I think I found out a way to do this, if I open the database as a managed DB, I can specify the version timestamp for each key and then my values will be added correctly.
The only issue now is that with this approach, seems like NumVersionsToKeep is ignored, since I always get all versions for that key during iteration instead of only the max number by above option.
Hey @sezaru, apologies for the delay in the reply.
Badger keeps the transactions in-memory before they’re committed.
In normal mode, if you write the same key twice, we will overwrite the first value (which is fine because you want to update the value).
You’re correct that you will need managed mode. The setEntryAt will commit entry at a specific timestamp. However, please be aware that managed mode is used when the application can deal with transaction conflicts and provide correct timestamps (dgraph used managed mode and deals with this).
If you commit things at an incorrect timestamp, you might not be able to read it correctly.
The NumVersionsToKeep flag is not used in the iterators. The NumVersionsToKeep flag is used by compaction to determine if the value should be kept or removed. So if the data you inserted is compacted (which happens when you have enough data), we will remove more than 2 versions of the key.
Iterators do not respect the NumVersionsToKeep flag.