I am trying to understand how to use versionstamps and if they can be useful in my layer.
I am trying to build something like datomic, that is a versioned database. I am relying on optimistic locking that is, I read and write the latest version of the data before storing the diff between the new data and the previously stored data with the transaction. In this context, it seems to me that using a timestamp generated in Python should be enough to have the correct ordering of transactions when it matters. That is, when two transactions read and write different parts of the database it doesn’t really matter which one comes first, I think.
A simpler question, might be, in which case versionstamp are useful? What are the usecases for versionstamps?
Also, I tried to experiment with
fdb.tuple.pack_with_versionstamp, here is an example run:
import fdb fdb.api_version(510) db = fdb.open() txn = db.create_transaction() v1 = fdb.tuple.pack_with_versionstamp((b'\x00', fdb.tuple.Versionstamp(),)); txn.set_versionstamped_key(v1, b'\x42'); v2 = fdb.tuple.pack_with_versionstamp((b'\x00', fdb.tuple.Versionstamp(),)); txn.set_versionstamped_value(b'\x42', v2) txn.commit()
And I get a very strange result:
>>> db.get_range_startswith(b'\x42') [b'B': b'\x00\x00\x00#l\xc5\x04d\x00\x00\xff\xff\xff\xff\xff\x00\x00\x05\x00']
>>> db.get_range_startswith(b'\x01') [b'\x01\x00\xff\x003\x00\x00\x00#l\xc5\x04d\x00\x00\x00\x00': b'B']
Where the first byte of the key is indeed
\x01 which is the code for bytes values followed by
Also both timestamp are cleary not the same. What is the reason for that?