Skip to content

Commit 6c85004

Browse files
PokIsemainemapleFU
andauthored
feat(config): add txn_context_enabled to allow to enable the transaction feature (#2506)
Co-authored-by: mwish <maplewish117@gmail.com>
1 parent 6e7476f commit 6c85004

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

kvrocks.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,20 @@ json-max-nesting-depth 1024
335335
# Default: json
336336
json-storage-format json
337337

338+
# Whether to enable transactional mode engine::Context.
339+
#
340+
# If enabled, is_txn_mode in engine::Context will be set properly,
341+
# which is expected to improve the consistency of commands.
342+
# If disabled, is_txn_mode in engine::Context will be set to false,
343+
# making engine::Context equivalent to engine::Storage.
344+
#
345+
# NOTE: This is an experimental feature. If you find errors, performance degradation,
346+
# excessive memory usage, excessive disk I/O, etc. after enabling it, please try disabling it.
347+
# At the same time, we welcome feedback on related issues to help iterative improvements.
348+
#
349+
# Default: no
350+
txn-context-enabled no
351+
338352
################################## TLS ###################################
339353

340354
# By default, TLS/SSL is disabled, i.e. `tls-port` is set to 0.

src/config/config.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Config::Config() {
193193
{"json-max-nesting-depth", false, new IntField(&json_max_nesting_depth, 1024, 0, INT_MAX)},
194194
{"json-storage-format", false,
195195
new EnumField<JsonStorageFormat>(&json_storage_format, json_storage_formats, JsonStorageFormat::JSON)},
196+
{"txn-context-enabled", true, new YesNoField(&txn_context_enabled, false)},
196197

197198
/* rocksdb options */
198199
{"rocksdb.compression", false,

src/config/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ struct Config {
168168
int json_max_nesting_depth = 1024;
169169
JsonStorageFormat json_storage_format = JsonStorageFormat::JSON;
170170

171+
// Enable transactional mode in engine::Context
172+
bool txn_context_enabled = false;
173+
171174
struct RocksDB {
172175
int block_size;
173176
bool cache_index_and_filter_blocks;

src/storage/storage.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ struct Context {
388388
std::unique_ptr<rocksdb::WriteBatchWithIndex> batch = nullptr;
389389

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

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

0 commit comments

Comments
 (0)