kitsonk / kv-toolbox

Utilities for working with Deno KV 🦕🗝️
https://kview.deno.dev/kv-toolbox
MIT License
66 stars 5 forks source link

atomic blob commands #7

Closed inverted-capital closed 7 months ago

inverted-capital commented 7 months ago

Is there a way to do the blob set operation as part of an atomic operation ?

kitsonk commented 7 months ago

There is a problem in that the amount of operations in an atomic operations is limited, but a blob set operations breaks down the data into discreet chunks which can easily exceed the transaction limit of an atomic operations.

In implementation at the moment, a blob set actually sets that parts using batched atomic transactions. I suspect though what you are really asking for is to be able to have something like .setBlob() as part of an atomic transaction?

It is possible to add that method to the batch atomic API, but because blob currently depends on batch atomic it means that we would have to reorganise the code a bit so there isn't a cyclical dependency.

inverted-capital commented 7 months ago

Correct - setBlob() as part of an atomic transaction.

Ok thank you for your reply. The way I am doing it at the moment is setting the blob to a ulid key, then using an atomic transaction to update the key I want with the blob key, and rolling back if that fails.

Given how the set() function breaks up blobs into a set of keys, would it perhaps be simpler to implement a pointer key system as described rather than making the whole set() function be atomic ? Same result, but no code reorg and no hitting the atomic operation count limit 🤷

inverted-capital commented 7 months ago

Thank you kindly 🔥