fix(kinesis): return real ShardId in PutRecord and PutRecords responses (#518)

PutRecord and PutRecords were hardcoding "shardId-000000000000" in responses
regardless of which shard the record was routed to. Storage-side routing
(selectShard) was already picking the correct shard; only the handler response
was wrong.

Add PutRecordResult record and putRecordWithShardId method that exposes the
resolved shard to handlers. Keep the existing putRecord(...) String overload
for internal callers (KinesisStreamingForwarder, tests) to avoid churn.

Fixes cross-shard distribution assertions in downstream SDK tests.
This commit is contained in:
TiM authored and GitHub committed 2026-04-19 08:07:54 -05:00
1 parent 6e8127c0e8
commit b37f4c71e0
3 files changed
+137 -10

No files matched your search

@@ -347,11 +347,11 @@ public class KinesisJsonHandler {
byte[] data = Base64.getDecoder().decode(request.path("Data").asText());
String partitionKey = request.path("PartitionKey").asText();
String seq = service.putRecord(streamName, data, partitionKey, region);
KinesisService.PutRecordResult result = service.putRecordWithShardId(streamName, data, partitionKey, region);
ObjectNode response = objectMapper.createObjectNode();
response.put("SequenceNumber", seq);
response.put("ShardId", "shardId-000000000000"); // Simplified
response.put("SequenceNumber", result.sequenceNumber());
response.put("ShardId", result.shardId());
return Response.ok(response).build();
}
@@ -366,10 +366,10 @@ public class KinesisJsonHandler {
try {
byte[] data = Base64.getDecoder().decode(node.path("Data").asText());
String partitionKey = node.path("PartitionKey").asText();
String seq = service.putRecord(streamName, data, partitionKey, region);
KinesisService.PutRecordResult result = service.putRecordWithShardId(streamName, data, partitionKey, region);
results.addObject()
.put("SequenceNumber", seq)
.put("ShardId", "shardId-000000000000");
.put("SequenceNumber", result.sequenceNumber())
.put("ShardId", result.shardId());
} catch (Exception e) {
failed++;
results.addObject()
@@ -351,17 +351,23 @@ public class KinesisService {
return new java.math.BigInteger(val).subtract(java.math.BigInteger.ONE).toString();
}
public record PutRecordResult(String sequenceNumber, String shardId) {}
public String putRecord(String streamName, byte[] data, String partitionKey, String region) {
return putRecordWithShardId(streamName, data, partitionKey, region).sequenceNumber();
}
public PutRecordResult putRecordWithShardId(String streamName, byte[] data, String partitionKey, String region) {
KinesisStream stream = resolveStream(streamName, region);
KinesisShard shard = selectShard(stream, partitionKey);
String sequenceNumber = String.valueOf(sequenceGenerator.incrementAndGet());
KinesisRecord record = new KinesisRecord(data, partitionKey, sequenceNumber, Instant.now());
shard.getRecords().add(record);
store.put(regionKey(region, streamName), stream);
return sequenceNumber;
return new PutRecordResult(sequenceNumber, shard.getShardId());
}
public String getShardIterator(String streamName, String shardId, String type, String sequenceNumber, String region) {