Reuse evicted IDs

After evicting an entity, should it be possible to create a new entity with the exact same xt/id?

Asked another way: it’s possible to put an entity with an id that was previously evicted. Is it OK if I rely on this behavior?

Reason for asking: I’m thinking of replacing an evicted user-entity with an “anonymous” entity (user name and email removed, but company name still there) so when I look at the history of other entities, I can still see which company did what change.

Hey @xpekeler reusing evicted IDs is possible currently, however, it may be subject to race conditions if you ‘replace’ the evicted entity too quickly after the eviction, see: Race Condition for Eviction Tombstone · Issue #432 · xtdb/xtdb · GitHub

Also note that you can’t evict and re-put within the same transaction, see: xtdb/tx_test.clj at 7ec4828f48b3fb97ffd1baf4eda22857c9fcb48d · xtdb/xtdb · GitHub and evict then re-put to the same entity in the same transaction is broken · Issue #1337 · xtdb/xtdb · GitHub

Therefore as general advice right now, we would recommend to avoid resurrecting an evicted entity whilst those issues remain unresolved. That said, I’d be happy to try to help you reason about how to avoid the race condition :slight_smile:

Thanks. Waiting for the evict transaction wouldn’t be enough to avoid the race-condition? What else could I be waiting for between eviction and put? (We’re using Postgresql & RocksDB, if that makes a diffeerence)

Actually I think that would be enough, but the trouble is knowing when an eviction operation has been submitted in the first place - like maybe you would need some other store/queue/service to handle this in reliable/scalable way. Or maybe it’s straightforward and safe enough if you are always funnelling such eviction requests through a single submitting node :thinking:

Thanks. Upon further thought, since I don’t even know how to detect the race condition, nor have any idea about the potential consequences, I decided to use a different approach. Now, when an entity is evicted, a new replacement-entity is created that gets its own id but has a :replaces-id with the evicted entity’s id. At runtime, when an association can’t be resolved, the replacement-entity is looked up and used in place of the evicted entity. Not as fast & clean as the original approach, but I prefer having higher confidence about this :slight_smile:

1 Like