pmem / pmemkv

Key/Value Datastore for Persistent Memory
https://pmem.io
Other
398 stars 120 forks source link

compare-and-swap API extension #566

Open googlespot opened 4 years ago

googlespot commented 4 years ago

Concurrent scenarios are difficult to use because there is no compact-and-swap interface.

szyrom commented 4 years ago

Can describe use-case and what compact-and-swap api should do?

googlespot commented 4 years ago

virtual status replace(string_view key, string_view expect_value, string_view value) = 0;

szyrom commented 4 years ago

we already have similar idea for API extension: https://github.com/pmem/pmemkv/issues/387 but it will work only for values that do not require reallocation - will it work for your use-case?

pbalcer commented 4 years ago

compare and swap is different than update. Update is not conditional, whereas CAS is. This makes it a bit more difficult to implement atomically.

igchor commented 4 years ago

@pbalcer yes, but the isue linked by szyrom discusses several possible approaches (the last example in the first comment is what would allow CAS). However, it would be quite complicated to implement that and came up with a reasonable API so for now we only plan to do a regular, not conditional update.