-
Notifications
You must be signed in to change notification settings - Fork 19
Description
I'm in a little bit of an XY problem situation. There's a known limitation in FDB client API, which is unlikely going to be resolved in the foreseeable future. So I need to work around that. If there's a [better] way to solve it, I'd be interested.
Setting version stamped entries makes those entries unreadable. But it is sometimes necessary to access those entries after they have been set. The only way to "access" them is to also store them in some other storage. (I guess I could also use transaction_bypass_unreadable but that seems too hacky to be useful.) Whatever that external storage would be (eg. WeakMap, magic property on some object), it has to be tied to a specific transaction run. When transaction is retried, that storage should reset.
The library doesn't provide a way for abstractions to detect that the transaction has been restarted and it should dispose the external state created by the previous run. Nor does it provide a way to identify the underlying transaction without using internal _tn or _ctx properties.
My proposal is to use Transaction#_ctx for this. It is already used for a very similar reason internally (providing a central state across multiple operations). A new TxnCtx should be created for each transaction run instead of resetting its properties. That object can be used as a key in the WeakMap or it could be manipulated directly.
There are 3 ways to go with it:
- Expose
Transaction#_ctxas is (eg.Transaction#context). - Expose
Transaction#_ctxand refactor it a bit for more generic use cases. - Create an entirely new property.
I would go with option (2). TxnCtx#nextCode could be turned into a generic counter, so that abstractions don't need to implement their own counter to serialize their operations. TxnCtx#toBake could be turned into an array of arbitrary callbacks to be run after a successful commit. Both of these features would be useful based on my experience.