You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "git-hulk (via GitHub)" <gi...@apache.org> on 2023/02/27 10:59:20 UTC
[GitHub] [incubator-kvrocks] git-hulk opened a new issue, #1281: Atomic commit write batches in the command EXEC
git-hulk opened a new issue, #1281:
URL: https://github.com/apache/incubator-kvrocks/issues/1281
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/incubator-kvrocks/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:
```C++
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.
To be noticed: it only fixes this issue partially since it cannot read-it-own-writes in this transaction. To make the context clear, I will submit another issue to describe this solution.
### Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk closed issue #1281: Atomic commit write batches in the command EXEC
Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk closed issue #1281: Atomic commit write batches in the command EXEC
URL: https://github.com/apache/incubator-kvrocks/issues/1281
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] aleksraiden commented on issue #1281: Atomic commit write batches in the command EXEC
Posted by "aleksraiden (via GitHub)" <gi...@apache.org>.
aleksraiden commented on issue #1281:
URL: https://github.com/apache/incubator-kvrocks/issues/1281#issuecomment-1448748043
Very important to me, waiting for this in upstream. Lot of thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org