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

`WriteBatch` is not thread safe

Open BusyJay opened this issue 8 years ago • 4 comments
trafficstars

From what I can see, WriteBatch is not thread safe. We should change the put method to take a mut ref instead.

https://github.com/facebook/rocksdb/blob/e03377c7fd86f117c6c64d35955140dab400eb3c/db/write_batch.cc#L525-L547

BusyJay avatar Nov 07 '17 12:11 BusyJay

I think the user will rarely use a WriteBatch cross multi-threads, maybe make it with no send, no sync?

siddontang avatar Nov 07 '17 12:11 siddontang

It may be a workaround, but certainly not a good design and feels weird.

BusyJay avatar Nov 07 '17 12:11 BusyJay

I think it's pretty common to have multiple writes distributed across threads, that should include WriteBatch, no?

alanhoff avatar Nov 22 '17 13:11 alanhoff

... it's pretty common to have multiple writes distributed across threads ...

That's exact the reason why DB::write is synchronized.

... that should include WriteBatch ...

No. Generally, WriteBatch is created and flushed in the same thread.

BusyJay avatar Nov 22 '17 14:11 BusyJay