我正在使用DynamoDB Local来运行来自nodejs(Javascript SDK)的集成测试。当我调用getRecords时,我收到“TrimmedDataAccessException”。如果我在AWS(非本地)中针对DynamoDB运行相同的代码,则可以正常工作。步骤如下:
“put”命令的顺序很重要。如果我先将“EventStore”放入“EventStore”,则一切正常,但是当我先放入“Music”时,它将失败。如果更改顺序,我的应用程序逻辑将是错误的,因此仅更改顺序对我来说就是一个问题。
运行DynamoDB
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -dbPath /data
createTable
{
TableName: "EventStore",
KeySchema: [
{ AttributeName: "EntityId", KeyType: "HASH" },
{ AttributeName: "Version", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "EntityId", AttributeType: "S" },
{ AttributeName: "Version", AttributeType: "N" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
},
StreamSpecification: {
StreamEnabled: true,
StreamViewType: "NEW_IMAGE"
}
}
createTable(响应)
{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "EntityId",
"AttributeType": "S"
},
{
"AttributeName": "Version",
"AttributeType": "N"
}
],
"TableName": "EventStore",
"KeySchema": [
{
"AttributeName": "EntityId",
"KeyType": "HASH"
},
{
"AttributeName": "Version",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2016-07-14T15:36:42.895Z",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
"LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore",
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_IMAGE"
},
"LatestStreamLabel": "2016-07-14T15:36:42.895",
"LatestStreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895"
}
describeTable(EventStore)
{
"TableName": "EventStore"
}
describeTable(EventStore)响应
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "EntityId",
"AttributeType": "S"
},
{
"AttributeName": "Version",
"AttributeType": "N"
}
],
"TableName": "EventStore",
"KeySchema": [
{
"AttributeName": "EntityId",
"KeyType": "HASH"
},
{
"AttributeName": "Version",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2016-07-14T15:36:42.895Z",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
"LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 10,
"WriteCapacityUnits": 10
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore",
"StreamSpecification": {
"StreamEnabled": true,
"StreamViewType": "NEW_IMAGE"
},
"LatestStreamLabel": "2016-07-14T15:36:42.895",
"LatestStreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895"
}
}
描述 Steam
{
"StreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895"
}
describeStream响应
{
"StreamDescription": {
"StreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895",
"StreamLabel": "2016-07-14T15:36:42.895",
"StreamStatus": "ENABLED",
"StreamViewType": "NEW_IMAGE",
"CreationRequestDateTime": "2016-07-14T15:36:42.895Z",
"TableName": "EventStore",
"KeySchema": [
{
"AttributeName": "EntityId",
"KeyType": "HASH"
},
{
"AttributeName": "Version",
"KeyType": "RANGE"
}
],
"Shards": [
{
"ShardId": "shardId-00000001468510602897-249806fa",
"SequenceNumberRange": {
"StartingSequenceNumber": "000000000000000000052"
}
}
]
}
}
getShardIterator
{
"ShardId": "shardId-00000001468510602897-249806fa",
"ShardIteratorType": "LATEST",
"StreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895"
}
getShardIterator响应
{
"ShardIterator": "000|arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895|c2hhcmRJZC0wMDAwMDAwMTQ2ODUxMDYwMjg5Ny0yNDk4MDZmYXwwMDAwMDAwMDAwMDAwMDAwMDAwNTJ8MDAwMDAwMDAwMDAwMDAwMDAxNDY4NTEwNjc2NjEy"
}
(表名:音乐)
{
TableName: "Music",
Item: {
Id: "000-000-000-000-000",
Artist: "No One You Know",
SongTitle: "Call Me Today"
},
"ConditionExpression": "attribute_not_exists(Artist) and attribute_not_exists(SongTitle)"
}
放置(TableName:EventStore)
{
"TableName": "EventStore",
"Item": {
"EntityId": "000-000-000-000-000",
"Version": 1468510676704,
"Payload": [
{
"type": "Buffer",
"data": [
38,48,48,48,45,48,48,48,45,48,48,48,45,48,48,48,45,48,48,48,30,78,111,32,79,110,101,32,89,111,117,32,75,110,111,119,26,67,97,108,108,32,77,101,32,84,111,100,97,121
]
}
],
"Fingerprint": "8871e2afc3c31edfa9938e4cbb2b5",
"Timestamp": 1468510676704
},
"ConditionExpression": "attribute_not_exists(EntityId) and attribute_not_exists(Version)"
}
getRecords(EventStore)
{ ShardIterator: "000|arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895|c2hhcmRJZC0wMDAwMDAwMTQ2ODUxMDYwMjg5Ny0yNDk4MDZmYXwwMDAwMDAwMDAwMDAwMDAwMDAwNTJ8MDAwMDAwMDAwMDAwMDAwMDAxNDY4NTEwNjc2NjEy" }
getRecords(EventStore)响应
{
"message": "The operation attempted to read past the oldest stream record in a shard.",
"code": "TrimmedDataAccessException",
"time": "2016-07-14T15:37:56.740Z",
"requestId": "0e4d43ae-ac7d-419b-a1db-c8e2a955a877",
"statusCode": 400,
"retryable": false,
"retryDelay": 30.214022053405643
}
最佳答案
我发现,如果在调用getRecords之后,再次调用getShardIterator(具有相同的参数),则可以正常工作。
显然,本地实现中存在错误。
关于amazon-dynamodb-streams - DynamoDB本地: Streams. getRecords返回TrimmedDataAccessException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38378831/