我正在使用 DynamoDB local 从 nodejs (Javascript SDK) 运行集成测试。当我调用 getRecords 时,我收到“TrimmedDataAccessException”。如果我在 AWS(非本地)中对 DynamoDB 运行相同的代码,它工作正常。以下是步骤:
- 运行 DynamoDB
- 创建表“事件存储”
- 创建表“音乐”
- describeTable "EventStore" (获取 LatestStreamArn")
- describeStream 返回为“LatestStreamArn”(获取 ShardId)
- getShardIterator with ShardIteratorType "LATEST"
- 将记录放入“音乐”表
- 将记录放入“EventStore”表
- 从“EventStore”流中获取记录
“put”命令的顺序很重要。如果我首先放入“EventStore”,一切正常,但当我首先放入“音乐”时,它会失败。如果我更改订单,我的应用程序逻辑就会出错,所以只是更改订单对我来说是个问题。
运行 DynamoDB
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -dbPath /data
创建表
{
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"
}
}
创建表(响应)
{
"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"
}
描述表(事件存储)
{
"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"
}
}
描述蒸汽
{
"StreamArn": "arn:aws:dynamodb:ddblocal:000000000000:table/EventStore/stream/2016-07-14T15:36:42.895"
}
描述流响应
{
"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"
}
}
]
}
}
获取分片迭代器
{
"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)"
}
放(表名: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)"
}
获取记录(事件存储)
{ 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
}