This is an automated email from the ASF dual-hosted git repository.

maplefu pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 6c850044 feat(config): add `txn_context_enabled` to allow to enable 
the transaction feature (#2506)
6c850044 is described below

commit 6c85004431d065a6d9c0fd0932c087f9e2e290be
Author: SiLe Zhou <[email protected]>
AuthorDate: Sun Sep 1 01:07:42 2024 +0800

    feat(config): add `txn_context_enabled` to allow to enable the transaction 
feature (#2506)
    
    Co-authored-by: mwish <[email protected]>
---
 kvrocks.conf          | 14 ++++++++++++++
 src/config/config.cc  |  1 +
 src/config/config.h   |  3 +++
 src/storage/storage.h |  7 ++++++-
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/kvrocks.conf b/kvrocks.conf
index fda3da0c..b5ad860a 100644
--- a/kvrocks.conf
+++ b/kvrocks.conf
@@ -335,6 +335,20 @@ json-max-nesting-depth 1024
 # Default: json
 json-storage-format json
 
+# Whether to enable transactional mode engine::Context.
+#
+# 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
+
 ################################## TLS ###################################
 
 # By default, TLS/SSL is disabled, i.e. `tls-port` is set to 0.
diff --git a/src/config/config.cc b/src/config/config.cc
index 1fbfe928..de914014 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -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,
diff --git a/src/config/config.h b/src/config/config.h
index 798bbc97..c1cf5da9 100644
--- a/src/config/config.h
+++ b/src/config/config.h
@@ -168,6 +168,9 @@ struct Config {
   int json_max_nesting_depth = 1024;
   JsonStorageFormat json_storage_format = JsonStorageFormat::JSON;
 
+  // Enable transactional mode in engine::Context
+  bool txn_context_enabled = false;
+
   struct RocksDB {
     int block_size;
     bool cache_index_and_filter_blocks;
diff --git a/src/storage/storage.h b/src/storage/storage.h
index 9c63582d..dfc0fec9 100644
--- a/src/storage/storage.h
+++ b/src/storage/storage.h
@@ -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
@@ -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() {

Reply via email to