-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Transaction can't guarantee atomicity #487
Comments
Thanks for opening this issue @ShooterIT I suggest to use the API they are providing. |
Thanks @Eshcar Yes, i know RocksDB supports, but i worry transaction db would break kvrocks db usage, I will rethink it. |
@ShooterIT - can you demonstrate a problematic scenario that will break other kvrocks commands when using rocksdb txs? |
@Eshcar Sorry for the slow reply. Currently, kvrocks directly access |
Indeed, supporting tx atomicity will create changes to many kvrocks files, if not all. But it has the potential of improving the quality of the code. Here is my suggestion. At the core of it is the principle of encapsulation:
This is the list of methods that reference db_ or storage_ and need to be covered by the handler:
storage_:
Maybe there are some more methods that I missed. An example usage of the dbHandler would be:
So the code and flow for commands is similar to the current code, the only difference is how specific calls are handled at the db_ level based on the context (tx or simple). Do you see any inherent limitation in this suggestion? (except for the fact that it requires major refactoring of the code). |
Impressive idea, truly thanks @Eshcar Recently, I always thought that, it will be really cool to support ACID transaction for KV NoSql. Even I also want to support interactive transaction, and we can support more features transaction, such as optional sync, isolation level.
sync: we call fsync after transactions, i.e. truly guarantee data persistent in disk For code refactor of storage, i ever had a big idea, i think it is not good to directly access Your suggested method is much accessible i think, though it also breaks many places. Recently, i may don't have enough spare time to do this job, i think you can have a try if you want. |
Thanks @ShooterIT |
Hi, @Eshcar @ShooterIT I have an idea to workaround this bug. 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 |
it is limited, in transaction, there also are some reading operations, we also hope we can read committed writing operations, maybe you can implement searching WAL(rocksdb supports it) to support this feature, but we can't resolve conflicts when we commit transaction. so i prefer to just use rocksdb transaction to implement real transaction. |
Yes, RocksDB also supports the Refer: https://rocksdb.org/blog/2015/02/27/write-batch-with-index.html |
but if you don't commit write(pending in |
@ShooterIT Do you mean |
You said you don't want to use |
oh...I got your point now. What I mean is to implement the atomic write operations first, then involves read operations at the next stage. |
you shouldn't ask developers not have Read-Your-Own-Write operations in transactions,
|
@ShooterIT Yes, we cannot require users to avoid this, what I mean is to separate them into two PRs to make the code review simple. |
Describe the bug
The exclusive guard lock ensures you run the transaction in isolation, but it cannot guarantee the atomicity of the EXEC stage.
You would like to either have all commands applied to the db or none of them applied.
However, if some commands are executed and persisted to rocksdb and the process fails before the tx completes the db sees an intermediate state which is not desired.
Expected behavior
Guarantee the atomicity and consistency.
The text was updated successfully, but these errors were encountered: