mirror of
https://github.com/floci-io/floci.git
synced 2026-12-05 19:18:01 -05:00
fix(kinesis): require StartingSequenceNumber for sequence-number shard iterators (#9464)
GetShardIterator with AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER and no StartingSequenceNumber returned an iterator at the oldest record. It now answers InvalidArgumentException with Kinesis's message, naming the requested type. Closes #9462
This commit is contained in:
1 parent
4792c97902
commit
80da424ac0
3 files changed
+57
-20
No files matched your search
@@ -1298,6 +1298,14 @@ public class KinesisService implements ResourceProvider {
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Shard not found", 400));
|
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Shard not found", 400));
|
||||||
if (!"LATEST".equals(type)) {
|
if (!"LATEST".equals(type)) {
|
||||||
|
boolean sequenceType = "AT_SEQUENCE_NUMBER".equals(type) || "AFTER_SEQUENCE_NUMBER".equals(type);
|
||||||
|
if (sequenceType && (sequenceNumber == null || sequenceNumber.isEmpty())) {
|
||||||
|
throw new AwsException("InvalidArgumentException",
|
||||||
|
"Must either specify (1) AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER and "
|
||||||
|
+ "StartingSequenceNumber or (2) TRIM_HORIZON or LATEST and no "
|
||||||
|
+ "StartingSequenceNumber. Request specified " + type
|
||||||
|
+ " and no StartingSequenceNumber.", 400);
|
||||||
|
}
|
||||||
return sequenceNumber != null ? sequenceNumber : "";
|
return sequenceNumber != null ? sequenceNumber : "";
|
||||||
}
|
}
|
||||||
List<KinesisRecord> records = shard.getRecords();
|
List<KinesisRecord> records = shard.getRecords();
|
||||||
|
|||||||
@@ -226,6 +226,25 @@ class KinesisJsonHandlerTest {
|
|||||||
.path("Tags").size());
|
.path("Tags").size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getShardIteratorSequenceTypesWithoutStartingSequenceNumberReturnInvalidArgument() {
|
||||||
|
createStream("test-stream");
|
||||||
|
String shardId = firstShardId("test-stream");
|
||||||
|
for (String type : new String[] {"AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER"}) {
|
||||||
|
ObjectNode iterReq = MAPPER.createObjectNode();
|
||||||
|
iterReq.put("StreamName", "test-stream");
|
||||||
|
iterReq.put("ShardId", shardId);
|
||||||
|
iterReq.put("ShardIteratorType", type);
|
||||||
|
AwsException ex = assertThrows(AwsException.class,
|
||||||
|
() -> handler.handle("GetShardIterator", iterReq, REGION));
|
||||||
|
assertEquals("InvalidArgumentException", ex.getErrorCode(), type);
|
||||||
|
assertEquals(400, ex.getHttpStatus(), type);
|
||||||
|
assertEquals("Must either specify (1) AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER and "
|
||||||
|
+ "StartingSequenceNumber or (2) TRIM_HORIZON or LATEST and no StartingSequenceNumber. "
|
||||||
|
+ "Request specified " + type + " and no StartingSequenceNumber.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resourceTagsRejectForeignAndMissingResources() {
|
void resourceTagsRejectForeignAndMissingResources() {
|
||||||
createStream("test-stream");
|
createStream("test-stream");
|
||||||
@@ -431,6 +450,13 @@ class KinesisJsonHandlerTest {
|
|||||||
return (ObjectNode) response.getEntity();
|
return (ObjectNode) response.getEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String firstShardId(String streamName) {
|
||||||
|
ObjectNode descReq = MAPPER.createObjectNode();
|
||||||
|
descReq.put("StreamName", streamName);
|
||||||
|
return responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
||||||
|
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = {"PutRecord", "PutRecords"})
|
@ValueSource(strings = {"PutRecord", "PutRecords"})
|
||||||
void writesReportTheOpenHashRangeAfterRepeatedSplits(String action) {
|
void writesReportTheOpenHashRangeAfterRepeatedSplits(String action) {
|
||||||
@@ -1238,10 +1264,7 @@ class KinesisJsonHandlerTest {
|
|||||||
assertEquals("InvalidArgumentException", ex.getErrorCode());
|
assertEquals("InvalidArgumentException", ex.getErrorCode());
|
||||||
|
|
||||||
// The valid first record must not have landed either
|
// The valid first record must not have landed either
|
||||||
ObjectNode descReq = MAPPER.createObjectNode();
|
String shardId = firstShardId("test-stream");
|
||||||
descReq.put("StreamName", "test-stream");
|
|
||||||
String shardId = responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
|
||||||
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
|
||||||
|
|
||||||
ObjectNode iterReq = MAPPER.createObjectNode();
|
ObjectNode iterReq = MAPPER.createObjectNode();
|
||||||
iterReq.put("StreamName", "test-stream");
|
iterReq.put("StreamName", "test-stream");
|
||||||
@@ -1489,10 +1512,7 @@ class KinesisJsonHandlerTest {
|
|||||||
putReq.put("PartitionKey", "pk1");
|
putReq.put("PartitionKey", "pk1");
|
||||||
handler.handle("PutRecord", putReq, REGION);
|
handler.handle("PutRecord", putReq, REGION);
|
||||||
|
|
||||||
ObjectNode descReq = MAPPER.createObjectNode();
|
String shardId = firstShardId("test-stream");
|
||||||
descReq.put("StreamName", "test-stream");
|
|
||||||
String shardId = responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
|
||||||
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
|
||||||
|
|
||||||
// A fixed, realistic (2020s-era) arrival timestamp - Instant.now() would also trigger
|
// A fixed, realistic (2020s-era) arrival timestamp - Instant.now() would also trigger
|
||||||
// the bug, but a fixed value makes the expected serialized decimal assertable exactly.
|
// the bug, but a fixed value makes the expected serialized decimal assertable exactly.
|
||||||
@@ -1531,10 +1551,7 @@ class KinesisJsonHandlerTest {
|
|||||||
putReq.put("PartitionKey", "pk1");
|
putReq.put("PartitionKey", "pk1");
|
||||||
handler.handle("PutRecord", putReq, REGION);
|
handler.handle("PutRecord", putReq, REGION);
|
||||||
|
|
||||||
ObjectNode descReq = MAPPER.createObjectNode();
|
String shardId = firstShardId("test-stream");
|
||||||
descReq.put("StreamName", "test-stream");
|
|
||||||
String shardId = responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
|
||||||
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
|
||||||
|
|
||||||
service.describeStream("test-stream", REGION).getShards().get(0).getRecords().get(0)
|
service.describeStream("test-stream", REGION).getShards().get(0).getRecords().get(0)
|
||||||
.setApproximateArrivalTimestamp(Instant.ofEpochMilli(1_786_959_659_000L));
|
.setApproximateArrivalTimestamp(Instant.ofEpochMilli(1_786_959_659_000L));
|
||||||
@@ -1570,10 +1587,7 @@ class KinesisJsonHandlerTest {
|
|||||||
putReq.put("PartitionKey", "pk1");
|
putReq.put("PartitionKey", "pk1");
|
||||||
handler.handle("PutRecord", putReq, REGION);
|
handler.handle("PutRecord", putReq, REGION);
|
||||||
|
|
||||||
ObjectNode descReq = MAPPER.createObjectNode();
|
String shardId = firstShardId("test-stream");
|
||||||
descReq.put("StreamName", "test-stream");
|
|
||||||
String shardId = responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
|
||||||
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
|
||||||
|
|
||||||
service.describeStream("test-stream", REGION).getShards().get(0).getRecords().get(0)
|
service.describeStream("test-stream", REGION).getShards().get(0).getRecords().get(0)
|
||||||
.setApproximateArrivalTimestamp(null);
|
.setApproximateArrivalTimestamp(null);
|
||||||
@@ -1596,10 +1610,7 @@ class KinesisJsonHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArrayNode readAllRecords(String streamName) {
|
private ArrayNode readAllRecords(String streamName) {
|
||||||
ObjectNode descReq = MAPPER.createObjectNode();
|
String shardId = firstShardId(streamName);
|
||||||
descReq.put("StreamName", streamName);
|
|
||||||
String shardId = responseEntity(handler.handle("DescribeStream", descReq, REGION))
|
|
||||||
.get("StreamDescription").get("Shards").get(0).get("ShardId").asText();
|
|
||||||
|
|
||||||
ObjectNode iterReq = MAPPER.createObjectNode();
|
ObjectNode iterReq = MAPPER.createObjectNode();
|
||||||
iterReq.put("StreamName", streamName);
|
iterReq.put("StreamName", streamName);
|
||||||
|
|||||||
@@ -341,6 +341,24 @@ class KinesisServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getShardIteratorSequenceTypesWithoutStartingSequenceNumberThrow() {
|
||||||
|
kinesisService.createStream("my-stream", 1, REGION);
|
||||||
|
String shardId = kinesisService.describeStream("my-stream", REGION).getShards().getFirst().getShardId();
|
||||||
|
kinesisService.putRecord("my-stream", "msg".getBytes(StandardCharsets.UTF_8), "pk", REGION);
|
||||||
|
for (String type : List.of("AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER")) {
|
||||||
|
for (String missing : new String[] {null, ""}) {
|
||||||
|
AwsException ex = assertThrows(AwsException.class, () ->
|
||||||
|
kinesisService.getShardIterator("my-stream", shardId, type, missing, REGION));
|
||||||
|
assertEquals("InvalidArgumentException", ex.getErrorCode(), type);
|
||||||
|
assertEquals(400, ex.getHttpStatus(), type);
|
||||||
|
assertEquals("Must either specify (1) AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER and "
|
||||||
|
+ "StartingSequenceNumber or (2) TRIM_HORIZON or LATEST and no StartingSequenceNumber. "
|
||||||
|
+ "Request specified " + type + " and no StartingSequenceNumber.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void millisBehindLatestIsZeroOnEmptyShard() {
|
void millisBehindLatestIsZeroOnEmptyShard() {
|
||||||
kinesisService.createStream("empty", 1, REGION);
|
kinesisService.createStream("empty", 1, REGION);
|
||||||
|
|||||||
Reference in new issue
Block a user