rust-rocksdb icon indicating copy to clipboard operation
rust-rocksdb copied to clipboard

Transaction's get_pinned's DbPinnableSlice borrows Transaction instead of TransactionDB

Open Ekleog opened this issue 10 months ago • 0 comments

Hey!

I'm trying to use rocksdb from an async context. In order to avoid memory copies, I'd like to use get_pinned.

However, there are .await points between my various get_pinned calls in a single transaction. This means that the Transaction ends up being borrowed from multiple threads, and thus requiring Sync, which it isn't. And so I cannot actually use get_pinned.

Reading the PinnableSlice rocksdb documentation, I'm not sure I totally understand the rational for it to borrow something, but to the best of my understanding it should at most need to borrow TransactionDB, and not the Transaction itself.

Do you think it would be possible to have the get_pinned_* actually return a DbPinnableSlice that borrows the TransactionDB? This'd require adding a borrow to the get_pinned_* methods so that the lifetime could be passed through, but I think it should be worth it — it'd unblock calling multiple get_pinned from async code.

(Once that's done I think I can just carry along &mut Transaction rather than &Transaction, and this should also relax the requirement for Sync itself, thus also avoiding mutexes altogether)

Ekleog avatar May 25 '25 23:05 Ekleog