Why does get versionstamp() return a future that resolves with 0 bytes?

I’m trying to add support for Versionstamps to the third party FDBSwift bindings, but I’m running into a bit of an issue: every few runs, calling fdb_future_get_value() on the future from fdb_transaction_get_versionstamp() will return 0 bytes (out_present is also 0). For all I know, I believe that my versionstamped key has been written to the database successfully and there are no other errors, so I’m open to any ideas anyone might have regarding why I’m seeing this behavior.

To be clear, this works fine nine times out of ten — it just fails to return a useful value every so often, so I’m concerned I’m doing something fundamentally wrong.

My PR, if it helps: https://github.com/kirilltitov/FDBSwift/pull/59

I think you want fdb_future_get_key: see https://apple.github.io/foundationdb/api-c.html#c.fdb_transaction_get_versionstamp

1 Like

Ah, I’m not sure how I even missed that! I wonder why fdb_future_get_value() even works sometimes?

I can confirm I’m no longer getting erratic behavior when using fdb_future_get_key()! Thank you @andrew.noyes, you have saved many of my future brain cells!

I presume it’s because, as it often happens with such sophisticated systems AND low-level interfaces, calling fdb_future_get_value instead of fdb_future_get_key in this case results in undefined behaviour, and adding checks would make all database operations slower.

In retrospect, that makes the most sense, since “present” was often a value other than just 1, so it likely took in some garbage…