我正在AWS上使用DynamoDB数据库。 我有一个已启用其流的表。据我了解,流应该捕获有关此表的任何活动。
但是,有时表的活动(通常是对某些记录的修改)不会记录在流中。 我知道新信息已写入表这一事实,因为我可以在表指标中看到此活动。
为什么会这样? 这并不罕见,它每天发生几次。 有什么办法可以刷新类似的内容吗? 我知道流中的分片中的数据会自行更新和刷新,但是还有什么办法吗?
我使用这种方法浏览流的分片:
private void processShards(AmazonDynamoDBStreamsClient sC, DescribeStreamResult dsr, String arn) {
String lastEvaluatedShardId = null;
final List<Shard> shards = dsr.getStreamDescription().getShards();
do {
// Process each shard on this page
for (Shard shard : shards) {
final String shardId = shard.getShardId();
if (!shardMap.containsKey(shardId)) {
shardMap.put(shardId, new String[2]);
shardMap.get(shardId)[0] = "";
shardMap.get(shardId)[1] = "open";
System.out.println("Shards map contains " + shardMap.size() + " shards.");
}
if (shardMap.get(shardId)[1].matches("open")) {
GetShardIteratorRequest getShardIteratorRequest = null;
if (shardMap.get(shardId)[0].matches("")) {
getShardIteratorRequest = new GetShardIteratorRequest()
.withStreamArn(arn)
.withShardId(shardId)
.withShardIteratorType(ShardIteratorType.TRIM_HORIZON);
} else {
getShardIteratorRequest = new GetShardIteratorRequest()
.withStreamArn(arn)
.withShardId(shardId)
.withShardIteratorType(ShardIteratorType.AFTER_SEQUENCE_NUMBER)
.withSequenceNumber(shardMap.get(shardId)[0]);
}
final GetShardIteratorResult sir = sC.getShardIterator(getShardIteratorRequest);
String currentShardIter = sir.getShardIterator();
while (currentShardIter != null) {
final GetRecordsResult getRecordsResult = sC.getRecords(new GetRecordsRequest()
.withShardIterator(currentShardIter));
final List<Record> records = getRecordsResult.getRecords();
if (!records.isEmpty()) {
for (Record record : records) {
final StreamRecord sr = record.getDynamodb();
// process record ..... do something
shardMap.get(shardId)[0] = sr.getSequenceNumber();
}
currentShardIter = getRecordsResult.getNextShardIterator();
} else {
break;
}
}
final String endSeq = shard.getSequenceNumberRange().getEndingSequenceNumber();
if (endSeq != null) {
shardMap.get(shardId)[1] = "closed";
}
} else {
// do nothing shard is closed
}
}
lastEvaluatedShardId = dsr.getStreamDescription().getLastEvaluatedShardId();
} while (lastEvaluatedShardId != null);
}
shardMap是-> HashMap <String, String[]> shardMap = new HashMap <String, String[]>();
在处理所有分片时,我可以看到那里有时不存在新信息。
可能是什么问题? 谢谢您的帮助。