9

DynamoDB ローカルを使用して、nodejs (Javascript SDK) から統合テストを実行しています。getRecords を呼び出すと、「TrimmedDataAccessException」が発生します。AWS (ローカルではない) で DynamoDB に対して同じコードを実行すると、正常に動作します。手順は次のとおりです。

  • DynamoDB を実行する
  • createTable "イベントストア"
  • createTable "音楽"
  • describeTable "EventStore" (LatestStreamArn を取得します)
  • 「LatestStreamArn」として返される describeStream (ShardId を取得します)
  • getShardIterator with ShardIteratorType "LATEST"
  • 「ミュージック」テーブルにレコードを入れる
  • 「EventStore」テーブルにレコードを入れる
  • 「EventStore」ストリームからの getRecords

「put」コマンドの順序は重要です。最初に "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(イベントストア)

{
    "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"
}

put(テーブル名:音楽)

{
    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)"
}

put(テーブル名: イベントストア)

{
  "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 (イベントストア)

{ 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
}
4

1 に答える 1