massa
massa copied to clipboard
Ledger RocksDB batch write in single transaction
Describe the bug
WriteBatch
default behavior doesn't use single transaction. It provides atomicity by default when writing multiple keys.
To Reproduce Launch a batch writes with wrong operation.
Expected behavior
WriteBatch
should be replaced by WriteBatchWithTransaction::<true>::default()
.
Transactions provide a way to guarantee that a batch of writes will only be written if there are no conflicts.
Links
There is more details about RocksDB transactions here
IMHO transactions are safer than atomic write only. If we enable transactions, we have to choose between pessimistic vs optimistic one's.
There is more details about RocksDB transactions here
IMHO transactions are safer than atomic write only. If we enable transactions, we have to choose between pessimistic vs optimistic one's.
According to what I read there, atomic writes with WriteBatch provide better performance than transactions but less consistency guarantees in case of simultaneous write conflicts. In Massa, only one thread is writing to rocksdb. So if I'm not mistaken, our best course would be to stick to WriteBatch since we don't need the rollback guarantees of transactions ?
According to what I read there, atomic writes with WriteBatch provide better performance than transactions but less consistency guarantees in case of simultaneous write conflicts. In Massa, only one thread is writing to rocksdb. So if I'm not mistaken, our best course would be to stick to WriteBatch since we don't need the rollback guarantees of transactions ?
When we look at Rocks performance benchmarks it's higher than Massa throughput. So adding a transaction will not impact us*.
Have we a guaranty that we don't launch several WriteBatch's which could affect same keys ? if the WriteBatch fails to did it's atomic write ? it's a choice between performance vs consistency but the loose in performance is not that high IMHO.
I always did this in my applications to avoid weird issues.
We could enable this feature in the future if we detect consistency issues in the ledger.
This is done, right ? @Leo-Besancon
If I understood correctly, this would only be an issue if multiple thread try and write on the same keys.
In the current implementation, the massa-db only writes from self.current_batch, which is a Arc<Mutex<WriteBatch>>
, so it should be ok.