mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(kinesis): resolve LATEST shard iterator position at GetShardIterator time (#1901)
* fix(kinesis): resolve LATEST shard iterator position at GetShardIterator time A LATEST iterator recomputed its start position as the shard tip on every GetRecords call, so records written between obtaining the iterator and the first poll were skipped forever. Snapshot the tip once when the iterator is created (matching DynamoDbStreamService) and encode it in the iterator's index slot. GetShardIterator now also fails fast with ResourceNotFoundException for an unknown shard, as on AWS. Fixes #1900 * test(kinesis): add regression tests for tailing with a LATEST iterator Reproduce issue #1900: a record written after the iterator is obtained must be returned, both on the first GetRecords call and when polling via NextShardIterator. * test(kinesis): cover unknown shard validation for LATEST iterators GetShardIterator must return ResourceNotFoundException when the shard does not exist instead of deferring the failure to GetRecords. * docs(kinesis): document shard iterator semantics Describe the supported iterator types and the LATEST tip-snapshot behavior; remove a stray empty Examples heading. * fix(kinesis): validate shard existence for all iterator types in GetShardIterator AWS rejects an unknown shard at GetShardIterator time for every iterator type, not just LATEST. Apply the shard lookup unconditionally instead of deferring the failure to GetRecords. Addresses review feedback on #1901. * test(kinesis): cover unknown shard validation across all iterator types
This commit is contained in:
1 parent
c4f4181c3d
commit
3b760bd8e5
3 files changed
+73
-13
No files matched your search
@@ -108,6 +108,50 @@ class KinesisServiceTest {
|
||||
assertEquals(0L, ((Number) result.get("MillisBehindLatest")).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void latestIteratorReturnsRecordsWrittenAfterItWasObtained() {
|
||||
kinesisService.createStream("my-stream", 1, REGION);
|
||||
kinesisService.putRecord("my-stream", "before".getBytes(StandardCharsets.UTF_8), "pk", REGION);
|
||||
|
||||
String shardId = kinesisService.describeStream("my-stream", REGION).getShards().getFirst().getShardId();
|
||||
String iterator = kinesisService.getShardIterator("my-stream", shardId, "LATEST", null, REGION);
|
||||
|
||||
kinesisService.putRecord("my-stream", "after".getBytes(StandardCharsets.UTF_8), "pk", REGION);
|
||||
|
||||
Map<String, Object> result = kinesisService.getRecords(iterator, 10, REGION);
|
||||
var records = (List<?>) result.get("Records");
|
||||
assertEquals(1, records.size());
|
||||
assertEquals("after", new String(((KinesisRecord) records.getFirst()).getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void latestIteratorContinuationPicksUpSubsequentWrites() {
|
||||
kinesisService.createStream("my-stream", 1, REGION);
|
||||
String shardId = kinesisService.describeStream("my-stream", REGION).getShards().getFirst().getShardId();
|
||||
String iterator = kinesisService.getShardIterator("my-stream", shardId, "LATEST", null, REGION);
|
||||
|
||||
// First poll before any write: empty, but the continuation iterator must not skip ahead.
|
||||
Map<String, Object> first = kinesisService.getRecords(iterator, 10, REGION);
|
||||
assertTrue(((List<?>) first.get("Records")).isEmpty());
|
||||
|
||||
kinesisService.putRecord("my-stream", "tailed".getBytes(StandardCharsets.UTF_8), "pk", REGION);
|
||||
|
||||
Map<String, Object> second = kinesisService.getRecords((String) first.get("NextShardIterator"), 10, REGION);
|
||||
var records = (List<?>) second.get("Records");
|
||||
assertEquals(1, records.size());
|
||||
assertEquals("tailed", new String(((KinesisRecord) records.getFirst()).getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getShardIteratorUnknownShardThrowsForAllIteratorTypes() {
|
||||
kinesisService.createStream("my-stream", 1, REGION);
|
||||
for (String type : List.of("LATEST", "TRIM_HORIZON", "AT_SEQUENCE_NUMBER", "AFTER_SEQUENCE_NUMBER", "AT_TIMESTAMP")) {
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
kinesisService.getShardIterator("my-stream", "shardId-999999999999", type, "1", 0L, REGION));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode(), type);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void millisBehindLatestIsZeroOnEmptyShard() {
|
||||
kinesisService.createStream("empty", 1, REGION);
|
||||
|
||||
Reference in new issue
Block a user