You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had searched in the issues and found no similar issues.
Motivation
As mentioned in #487, the current transaction is NOT an atomic operation, some operations may be committed to DB but some are not if they crashed in the middle way of executing the command EXEC.
To fix this issue, we need to gather all write operations into one RocksDB's WriteBatch, then commit it at once.
Solution
We can add a new function to create a shared WriteBatch for the Multi-Exec command like the below:
Status Storage::Begin() {
is_txn_mode = true;
txn_write_batch = make_shared<*rocksdb::WriteBatch>();
}
rocksdb::WriteBatch *Storage::GetWriteBatch() {
if (is_txn_mode) {
return txn_write_batch.get();
}
return make_shared<*rocksdb::WriteBatch>();
}
Status Storage::Commit() {
is_txn_mode = false;
// write txn WriteBatch to RocksDB
txn_write_batch.reset();
}
For the Command Exec, we need to explicitly call the Begin() and Commit() to enter and leave the transaction mode. So that Kvrocks will create a new WriteBatch for each writes operation if it's NOT in transaction mode, and use the shared WriteBatch to collect all write operations if it's in the transaction mode.
Are you willing to submit a PR?
I'm willing to submit a PR!
The text was updated successfully, but these errors were encountered:
Search before asking
Motivation
As mentioned in #487, the current transaction is NOT an atomic operation, some operations may be committed to DB but some are not if they crashed in the middle way of executing the command EXEC.
To fix this issue, we need to gather all write operations into one RocksDB's WriteBatch, then commit it at once.
Solution
We can add a new function to create a shared WriteBatch for the Multi-Exec command like the below:
For the Command Exec, we need to explicitly call the Begin() and Commit() to enter and leave the transaction mode. So that Kvrocks will create a new WriteBatch for each writes operation if it's NOT in transaction mode, and use the shared WriteBatch to collect all write operations if it's in the transaction mode.
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: