Skip to content
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

feat(config): add txn_context_enabled to allow to enable the transaction feature #2506

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ json-max-nesting-depth 1024
# Default: json
json-storage-format json

# Whether to enable transactional mode engine::Context.
PokIsemaine marked this conversation as resolved.
Show resolved Hide resolved
#
# If enabled, is_txn_mode in engine::Context will be set properly,
# which is expected to improve the consistency of commands.
# If disabled, is_txn_mode in engine::Context will be set to false,
# making engine::Context equivalent to engine::Storage.
#
# NOTE: This is an experimental feature. If you find errors, performance degradation,
# excessive memory usage, excessive disk I/O, etc. after enabling it, please try disabling it.
# At the same time, we welcome feedback on related issues to help iterative improvements.
#
# Default: no
txn-context-enabled no
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add some go cases for "yes" mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we need to test, but "some" may actually be almost all.
Is it possible to add a "yes" mode process to the GitHub Actions?

Copy link
Member

@PragmaTwice PragmaTwice Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just change the go cases to make some test functions like TestXX work on both mode, e.g.

TestXXAllMode() {
  TestXX(yes)
  TestXX(no)
}

Currently it is not required to include all test cases. Just some basic tests to ensure it can works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, how about adding these tests in another PR? I need to go out recently, so I may not be able to update immediately. You can merge this PR first, and then I will create an issue to track it and solve it when I have free time.


################################## TLS ###################################

# By default, TLS/SSL is disabled, i.e. `tls-port` is set to 0.
Expand Down
1 change: 1 addition & 0 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Config::Config() {
{"json-max-nesting-depth", false, new IntField(&json_max_nesting_depth, 1024, 0, INT_MAX)},
{"json-storage-format", false,
new EnumField<JsonStorageFormat>(&json_storage_format, json_storage_formats, JsonStorageFormat::JSON)},
{"txn-context-enabled", true, new YesNoField(&txn_context_enabled, false)},

/* rocksdb options */
{"rocksdb.compression", false,
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ struct Config {
int json_max_nesting_depth = 1024;
JsonStorageFormat json_storage_format = JsonStorageFormat::JSON;

// transactional mode engine::Context
PokIsemaine marked this conversation as resolved.
Show resolved Hide resolved
bool txn_context_enabled = false;

struct RocksDB {
int block_size;
bool cache_index_and_filter_blocks;
Expand Down
7 changes: 6 additions & 1 deletion src/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ struct Context {
std::unique_ptr<rocksdb::WriteBatchWithIndex> batch = nullptr;

/// is_txn_mode is used to determine whether the current Context is in transactional mode,
/// if it is not transactional mode, then Context is equivalent to a Storage
/// if it is not transactional mode, then Context is equivalent to a Storage.
/// If the configuration of txn-context-enabled is no, it is false.
bool is_txn_mode = true;

/// NoTransactionContext returns a Context with a is_txn_mode of false
Expand All @@ -409,6 +410,10 @@ struct Context {
/// TODO: Change it to defer getting the context, and the snapshot is pinned after the first read operation
explicit Context(engine::Storage *storage) : storage(storage) {
auto guard = storage->ReadLockGuard();
if (!storage->GetConfig()->txn_context_enabled) {
is_txn_mode = false;
return;
}
snapshot = storage->GetDB()->GetSnapshot(); // NOLINT
}
~Context() {
Expand Down