ruakn
ruakn

Reputation: 326

DynamoDB:: Does lastevaluatekey change when a new item is added while table scan is in progress?

Scenario:

  1. DynamoDB table scan is in progress using filter expression based on time, using pagination, we receive lastevaluatedkey.
  2. Few items are added in the table. (They are added based on the hash function, so they are not added serially in the table which brings me to the point 3)
  3. Scan is continuously executing from lastevaluatedkey. The new items added, does this change the next lastevaulatedkey? while change in lastevaluatedkey, can we say that some old data is lost?

(PS: I'm okay if new data added is not returned, and not using "consistent read")

Upvotes: 1

Views: 1543

Answers (1)

hunterhacker
hunterhacker

Reputation: 7132

The LastEvaluatedKey is like a bookmark in the primary key keyspace, a reference to the hash key of the last item processed. When you then pass it as an ExclusiveStartKey the scan will find that bookmarked item position in the sequential set of hashes and start processing with the next item. It's basically just saying "start a new scan, and start with the keys after this hash value".

If you modify items in the table held prior to the key, they won't be in the scan, because you resumed the scan after them. If you modify items in the table held after the key, they will potentially be in the scan.

Think of it as if you're reading all the words in the dictionary. The LastEvaluatedKey is the last word you read. Maybe the OED is adding words before or after the word you read, and maybe you get new updated copies of the OED as you go. Your scan would still resume with the word after the word you last read. Even if the word you last read gets removed from the OED, that doesn't invalidate your scan and you can keep reading the dictionary from what would be the next word.

Upvotes: 2

Related Questions