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

granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 9232452  KUDU-2612: disable TxnSystemClient initialization by default
9232452 is described below

commit 923245291fade95febc36265cfba8cc92ee457d5
Author: Andrew Wong <[email protected]>
AuthorDate: Mon May 24 17:43:20 2021 -0700

    KUDU-2612: disable TxnSystemClient initialization by default
    
    Currently the TxnSystemClient gets initialized on tablet servers by
    default, retrying every second until successful, and logging an error
    every minute if unable to. Since transactions support is currently
    experimental and disabled by default, so too should this initialization
    be. This patch hides the initialization with the existing
    --disable_txn_system_client_init flag (previously used for tests),
    adjusted to --enable_txn_system_client_init to match most of our
    feature-gating flags.
    
    Change-Id: I7c020a66db484f88ae1cb7c15d860d503a3f8a3b
    Reviewed-on: http://gerrit.cloudera.org:8080/17499
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <[email protected]>
    Reviewed-by: Grant Henke <[email protected]>
---
 .../apache/kudu/client/TestKuduTransaction.java    | 84 ++++++++++++++++++++--
 src/kudu/client/client-test.cc                     |  5 +-
 .../client-negotiation-failover-itest.cc           |  1 +
 .../integration-tests/location_assignment-itest.cc |  2 +-
 src/kudu/integration-tests/security-itest.cc       |  1 +
 .../integration-tests/ts_tablet_manager-itest.cc   |  6 ++
 src/kudu/integration-tests/txn_commit-itest.cc     |  2 +
 .../integration-tests/txn_status_manager-itest.cc  |  2 +
 .../integration-tests/txn_status_table-itest.cc    |  4 ++
 src/kudu/integration-tests/txn_write_ops-itest.cc  | 26 ++++---
 src/kudu/tools/kudu-txn-cli-test.cc                |  3 +-
 src/kudu/transactions/txn_status_manager-test.cc   |  2 +
 src/kudu/transactions/txn_system_client.cc         | 30 ++++----
 src/kudu/tserver/tablet_service.cc                 |  8 +++
 14 files changed, 144 insertions(+), 32 deletions(-)

diff --git 
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
 
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
index 2681483..f5430b4 100644
--- 
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
+++ 
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
@@ -90,6 +90,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testNewTransaction() throws Exception {
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
@@ -113,6 +116,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testStartManyTransactions() throws Exception {
     List<KuduTransaction> transactions = new ArrayList<>();
     for (int i = 0; i < 1000; ++i) {
@@ -132,6 +138,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testRollbackAnEmptyTransaction() throws Exception {
     KuduTransaction txn = client.newTransaction();
     txn.rollback();
@@ -162,7 +171,8 @@ public class TestKuduTransaction {
       "--txn_manager_enabled",
   })
   @TabletServerConfig(flags = {
-      "--txn_schedule_background_tasks=false"
+      "--txn_schedule_background_tasks=false",
+      "--enable_txn_system_client_init=true",
   })
   public void testCommitAnEmptyTransaction() throws Exception {
     KuduTransaction txn = client.newTransaction();
@@ -193,6 +203,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testCommitNonExistentTransaction() throws Exception {
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
@@ -233,6 +246,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testTxnSessionClose() throws Exception {
     final String TABLE_NAME = "txn_session_close";
     client.createTable(
@@ -289,6 +305,7 @@ public class TestKuduTransaction {
   @TabletServerConfig(flags = {
       "--txn_schedule_background_tasks=false",
       "--txn_status_manager_inject_latency_finalize_commit_ms=1000",
+      "--enable_txn_system_client_init=true",
   })
   public void testIsCommitComplete() throws Exception {
     KuduTransaction txn = client.newTransaction();
@@ -305,7 +322,8 @@ public class TestKuduTransaction {
       "--txn_manager_enabled",
   })
   @TabletServerConfig(flags = {
-      "--txn_schedule_background_tasks=false"
+      "--txn_schedule_background_tasks=false",
+      "--enable_txn_system_client_init=true",
   })
   public void testIsCommitCompleteSpecialCases() throws Exception {
     KuduTransaction txn = client.newTransaction();
@@ -364,6 +382,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testCommitAnEmptyTransactionWait() throws Exception {
     KuduTransaction txn = client.newTransaction();
     txn.commit();
@@ -377,6 +398,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testRollbackNonExistentTransaction() throws Exception {
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
@@ -403,6 +427,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testNewTransactionAsyncClient() throws Exception {
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
@@ -425,6 +452,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testNewTransactionalSession() throws Exception {
     final String TABLE_NAME = "new_transactional_session";
     client.createTable(
@@ -465,6 +495,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testNewAsyncTransactionalSession() throws Exception {
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
@@ -487,6 +520,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled=false",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testTxnOpsWithoutTxnManager() throws Exception {
     try (KuduTransaction txn = client.newTransaction()) {
       fail("starting a new transaction without TxnManager should have failed");
@@ -510,7 +546,8 @@ public class TestKuduTransaction {
       "--txn_manager_enabled",
   })
   @TabletServerConfig(flags = {
-      "--txn_schedule_background_tasks=false"
+      "--txn_schedule_background_tasks=false",
+      "--enable_txn_system_client_init=true",
   })
   public void testAutoclosableUsage() throws Exception {
     byte[] buf = null;
@@ -560,6 +597,9 @@ public class TestKuduTransaction {
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testSerializationOptions() throws Exception {
     final KuduTransaction txn = client.newTransaction();
 
@@ -626,6 +666,7 @@ public class TestKuduTransaction {
   @TabletServerConfig(flags = {
       "--txn_keepalive_interval_ms=200",
       "--txn_staleness_tracker_interval_ms=50",
+      "--enable_txn_system_client_init=true",
   })
   public void testKeepaliveBasic() throws Exception {
     try (KuduTransaction txn = client.newTransaction()) {
@@ -694,7 +735,8 @@ public class TestKuduTransaction {
   @TabletServerConfig(flags = {
       "--txn_keepalive_interval_ms=200",
       "--txn_schedule_background_tasks=false",
-      "--txn_staleness_tracker_interval_ms=50"
+      "--txn_staleness_tracker_interval_ms=50",
+      "--enable_txn_system_client_init=true",
   })
   public void testKeepaliveForDeserializedHandle() throws Exception {
     // Check the keepalive behavior when serializing/deserializing with default
@@ -792,6 +834,7 @@ public class TestKuduTransaction {
       // FINALIZE_IN_PROGRESS state and make KuduTransaction.isCommitComplete()
       // to return 'false' at least once before returning 'true'.
       "--txn_status_manager_inject_latency_finalize_commit_ms=250",
+      "--enable_txn_system_client_init=true",
   })
   public void testPropagateTxnCommitTimestamp() throws Exception {
     final String TABLE_NAME = "propagate_txn_commit_timestamp";
@@ -896,6 +939,9 @@ public class TestKuduTransaction {
       // leader failure detection and new leader election.
       "--raft_heartbeat_interval_ms=100",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testSwitchToOtherTxnManager() throws Exception {
     final String TABLE_NAME = "txn_manager_ops_fallback";
     client.createTable(
@@ -992,6 +1038,9 @@ public class TestKuduTransaction {
       // leader failure detection and new leader election.
       "--raft_heartbeat_interval_ms=100",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testSwitchToOtherTxnManagerInFlightCalls() throws Exception {
     final String TABLE_NAME = "txn_manager_ops_fallback_inflight";
     client.createTable(
@@ -1065,7 +1114,8 @@ public class TestKuduTransaction {
       // The txn keepalive interval should be long enough to accommodate Raft
       // leader failure detection and election.
       "--txn_keepalive_interval_ms=1000",
-      "--txn_staleness_tracker_interval_ms=250"
+      "--txn_staleness_tracker_interval_ms=250",
+      "--enable_txn_system_client_init=true",
   })
   public void testTxnKeepaliveSwitchesToOtherTxnManager() throws Exception {
     final String TABLE_NAME = "txn_manager_fallback";
@@ -1129,7 +1179,8 @@ public class TestKuduTransaction {
       // The txn keepalive interval should be long enough to accommodate Raft
       // leader failure detection and election.
       "--txn_keepalive_interval_ms=1000",
-      "--txn_staleness_tracker_interval_ms=250"
+      "--txn_staleness_tracker_interval_ms=250",
+      "--enable_txn_system_client_init=true",
   })
   public void testTxnKeepaliveRollingSwitchToOtherTxnManager() throws 
Exception {
     final String TABLE_NAME = "txn_manager_fallback_rolling";
@@ -1218,6 +1269,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testFlushSessionsOnCommit() throws Exception {
     final String TABLE_NAME = "flush_sessions_on_commit";
     client.createTable(
@@ -1329,6 +1383,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testRetryCommitAfterSessionFlushError() throws Exception {
     final String TABLE_NAME = "retry_commit_after_session_flush_error";
     client.createTable(
@@ -1389,6 +1446,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testStartCommitWithFlushedSessions() throws Exception {
     final String TABLE_NAME = "start_commit_with_flushed_sessions";
     client.createTable(
@@ -1429,6 +1489,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testStartCommitWithNonFlushedSessions() throws Exception {
     final String TABLE_NAME = "non_flushed_sessions_on_start_commit";
     client.createTable(
@@ -1484,6 +1547,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testNewSessionAfterCommit() throws Exception {
     final String TABLE_NAME = "new_session_after_commit";
     client.createTable(
@@ -1551,6 +1617,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testCreateSessionAfterStartCommit() throws Exception {
     KuduTransaction txn = client.newTransaction();
     txn.startCommit();
@@ -1574,6 +1643,9 @@ public class TestKuduTransaction {
       // TxnManager functionality is necessary for this scenario.
       "--txn_manager_enabled",
   })
+  @TabletServerConfig(flags = {
+      "--enable_txn_system_client_init=true",
+  })
   public void testSubmitWriteOpAfterCommit() throws Exception {
     final String TABLE_NAME = "submit_write_op_after_commit";
     client.createTable(
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index e5c073e..d0ee1c0 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -136,7 +136,7 @@ DECLARE_bool(allow_unsafe_replication_factor);
 DECLARE_bool(catalog_manager_support_live_row_count);
 DECLARE_bool(catalog_manager_support_on_disk_size);
 DECLARE_bool(client_use_unix_domain_sockets);
-DECLARE_bool(disable_txn_system_client_init);
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(fail_dns_resolution);
 DECLARE_bool(location_mapping_by_uuid);
 DECLARE_bool(log_inject_latency);
@@ -247,6 +247,7 @@ class ClientTest : public KuduTest {
 
     // Enable TxnManager in Kudu master.
     FLAGS_txn_manager_enabled = true;
+    FLAGS_enable_txn_system_client_init = true;
     // Basic txn-related scenarios in this test assume there is only one
     // replica of the transaction status table.
     FLAGS_txn_manager_status_table_num_replicas = 1;
@@ -8303,7 +8304,7 @@ class ClientWithLocationTest : public ClientTest {
 
     // Some of these tests assume no client activity, so disable the
     // transaction system client.
-    FLAGS_disable_txn_system_client_init = true;
+    FLAGS_enable_txn_system_client_init = false;
 
     // By default, master doesn't assing locations to connecting clients.
     FLAGS_master_client_location_assignment_enabled = true;
diff --git a/src/kudu/integration-tests/client-negotiation-failover-itest.cc 
b/src/kudu/integration-tests/client-negotiation-failover-itest.cc
index 134d2d2..30afd1c 100644
--- a/src/kudu/integration-tests/client-negotiation-failover-itest.cc
+++ b/src/kudu/integration-tests/client-negotiation-failover-itest.cc
@@ -81,6 +81,7 @@ class ClientFailoverOnNegotiationTimeoutITest : public 
KuduTest {
         "--leader_failure_exp_backoff_max_delta_ms=1000",
         // Decreasing TS->master heartbeat interval speeds up the test.
         "--heartbeat_interval_ms=25",
+        "--enable_txn_system_client_init=true",
     };
     cluster_opts_.extra_master_flags = {
         // Speed up Raft elections.
diff --git a/src/kudu/integration-tests/location_assignment-itest.cc 
b/src/kudu/integration-tests/location_assignment-itest.cc
index 8f7e211..1904746 100644
--- a/src/kudu/integration-tests/location_assignment-itest.cc
+++ b/src/kudu/integration-tests/location_assignment-itest.cc
@@ -158,7 +158,7 @@ class TsLocationAssignmentITest :
     const auto& param = GetParam();
     opts_.num_masters = std::get<0>(param);
     opts_.num_tablet_servers = std::get<1>(param);
-    opts_.extra_tserver_flags.emplace_back("--disable_txn_system_client_init");
+    
opts_.extra_tserver_flags.emplace_back("--enable_txn_system_client_init=false");
   }
 
   virtual ~TsLocationAssignmentITest() = default;
diff --git a/src/kudu/integration-tests/security-itest.cc 
b/src/kudu/integration-tests/security-itest.cc
index b6e93c1..2607886 100644
--- a/src/kudu/integration-tests/security-itest.cc
+++ b/src/kudu/integration-tests/security-itest.cc
@@ -284,6 +284,7 @@ TEST_F(SecurityITest, TestAuthorizationOnChecksum) {
 // the table.
 TEST_F(SecurityITest, SmokeTestAsAuthorizedUser) {
   cluster_opts_.extra_master_flags.emplace_back("--txn_manager_enabled=true");
+  
cluster_opts_.extra_tserver_flags.emplace_back("--enable_txn_system_client_init=true");
   ASSERT_OK(StartCluster());
 
   ASSERT_OK(cluster_->kdc()->Kinit("test-user"));
diff --git a/src/kudu/integration-tests/ts_tablet_manager-itest.cc 
b/src/kudu/integration-tests/ts_tablet_manager-itest.cc
index dfa7324..018f933 100644
--- a/src/kudu/integration-tests/ts_tablet_manager-itest.cc
+++ b/src/kudu/integration-tests/ts_tablet_manager-itest.cc
@@ -94,6 +94,7 @@ DECLARE_bool(allow_unsafe_replication_factor);
 DECLARE_bool(catalog_manager_evict_excess_replicas);
 DECLARE_bool(catalog_manager_wait_for_new_tablets_to_elect_leader);
 DECLARE_bool(enable_leader_failure_detection);
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(raft_prepare_replacement_before_eviction);
 DECLARE_double(leader_failure_max_missed_heartbeat_periods);
 DECLARE_int32(heartbeat_interval_ms);
@@ -1033,6 +1034,11 @@ class TxnStatusTabletManagementTest : public 
TsTabletManagerITest {
   const char* kTxnStatusTabletId = "11111111111111111111111111111111";
   const MonoDelta kTimeout = MonoDelta::FromSeconds(30);
 
+  void SetUp() override {
+    NO_FATALS(TsTabletManagerITest::SetUp());
+    FLAGS_enable_txn_system_client_init = true;
+  }
+
   // Creates a request to create a transaction status tablet with the given IDs
   // and Raft config.
   static CreateTabletRequestPB CreateTxnTabletReq(const string& tablet_id, 
const string& replica_id,
diff --git a/src/kudu/integration-tests/txn_commit-itest.cc 
b/src/kudu/integration-tests/txn_commit-itest.cc
index 5fba278..48b5781 100644
--- a/src/kudu/integration-tests/txn_commit-itest.cc
+++ b/src/kudu/integration-tests/txn_commit-itest.cc
@@ -68,6 +68,7 @@
 #include "kudu/util/test_util.h"
 
 DECLARE_bool(enable_txn_partition_lock);
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(txn_manager_enabled);
 DECLARE_bool(txn_manager_lazily_initialized);
 DECLARE_bool(txn_schedule_background_tasks);
@@ -121,6 +122,7 @@ class TxnCommitITest : public KuduTest {
   // Sets up a cluster with the given number of tservers, creating a
   // single-replica transaction status table and user-defined table.
   void SetUpClusterAndTable(int num_tservers, int num_replicas = 1) {
+    FLAGS_enable_txn_system_client_init = true;
     FLAGS_txn_manager_enabled = true;
     FLAGS_txn_manager_lazily_initialized = false;
     FLAGS_txn_manager_status_table_num_replicas = num_replicas;
diff --git a/src/kudu/integration-tests/txn_status_manager-itest.cc 
b/src/kudu/integration-tests/txn_status_manager-itest.cc
index 024942f..d0019e1 100644
--- a/src/kudu/integration-tests/txn_status_manager-itest.cc
+++ b/src/kudu/integration-tests/txn_status_manager-itest.cc
@@ -111,6 +111,8 @@ class TxnStatusManagerITest : public 
ExternalMiniClusterITestBase {
         "--raft_heartbeat_interval_ms=$0", kRaftHbIntervalMs));
     cluster_opts_.extra_tserver_flags.emplace_back(
         "--leader_failure_max_missed_heartbeat_periods=1.25");
+    cluster_opts_.extra_tserver_flags.emplace_back(
+        "--enable_txn_system_client_init=true");
 
     // Some of these tests rely on checking state assuming no background tasks.
     // For simplicity, disable the background commits.
diff --git a/src/kudu/integration-tests/txn_status_table-itest.cc 
b/src/kudu/integration-tests/txn_status_table-itest.cc
index 66b429d..c478cea 100644
--- a/src/kudu/integration-tests/txn_status_table-itest.cc
+++ b/src/kudu/integration-tests/txn_status_table-itest.cc
@@ -66,6 +66,7 @@
 #include "kudu/util/test_macros.h"
 #include "kudu/util/test_util.h"
 
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(raft_enable_pre_election);
 DECLARE_bool(txn_schedule_background_tasks);
 DECLARE_bool(txn_status_tablet_failover_inject_timeout_error);
@@ -119,6 +120,7 @@ class TxnStatusTableITest : public KuduTest {
     // Several of these tests rely on checking transaction state, which is
     // easier to work with without committing in the background.
     FLAGS_txn_schedule_background_tasks = false;
+    FLAGS_enable_txn_system_client_init = true;
     cluster_.reset(new InternalMiniCluster(env_, {}));
     ASSERT_OK(cluster_->Start());
 
@@ -858,6 +860,7 @@ class MultiServerTxnStatusTableITest : public 
TxnStatusTableITest {
  public:
   void SetUp() override {
     KuduTest::SetUp();
+    FLAGS_enable_txn_system_client_init = true;
     InternalMiniClusterOptions opts;
     opts.num_tablet_servers = 4;
     cluster_.reset(new InternalMiniCluster(env_, std::move(opts)));
@@ -1026,6 +1029,7 @@ class TxnStatusTableElectionStormITest : public 
TxnStatusTableITest {
  public:
   void SetUp() override {
     KuduTest::SetUp();
+    FLAGS_enable_txn_system_client_init = true;
 
     // Make leader elections more frequent to get through this test a bit more
     // quickly.
diff --git a/src/kudu/integration-tests/txn_write_ops-itest.cc 
b/src/kudu/integration-tests/txn_write_ops-itest.cc
index 319d216..d49064c 100644
--- a/src/kudu/integration-tests/txn_write_ops-itest.cc
+++ b/src/kudu/integration-tests/txn_write_ops-itest.cc
@@ -136,6 +136,7 @@ DEFINE_uint32(max_pending_txn_write_ops, 10,
               "setting for tserver's --tablet_max_pending_txn_write_ops flag");
 DEFINE_bool(txn_enabled, true, "whether to use transactional sessions");
 
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(tserver_txn_write_op_handling_enabled);
 DECLARE_bool(txn_manager_enabled);
 DECLARE_bool(txn_manager_lazily_initialized);
@@ -320,7 +321,8 @@ TEST_F(TxnWriteOpsITest, CommitTimestampPropagation) {
     // is created at start, not on first transaction-related operation.
     "--txn_manager_lazily_initialized=false",
   };
-  NO_FATALS(StartCluster({}, master_flags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         master_flags, kNumTabletServers));
   NO_FATALS(Prepare());
 
   // Start a transaction, write a bunch or rows into the test table, and then
@@ -420,7 +422,8 @@ TEST_F(TxnWriteOpsITest, DeadlockPrevention) {
     // is created at start, not on first transaction-related operation.
     "--txn_manager_lazily_initialized=false",
   };
-  NO_FATALS(StartCluster({}, master_flags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         master_flags, kNumTabletServers));
   NO_FATALS(Prepare());
   vector<thread> threads;
   threads.reserve(kNumTxns);
@@ -496,7 +499,8 @@ TEST_F(TxnWriteOpsITest, TestWriteToNewRangeOfTxnIds) {
     // Set a small range so we can write to a new range of transactions IDs.
     Substitute("--txn_manager_status_table_range_partition_span=$0", kNumTxns 
/ 3),
   };
-  NO_FATALS(StartCluster({}, kMasterFlags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         kMasterFlags, kNumTabletServers));
   NO_FATALS(Prepare());
   for (int i = 0; i < kNumTxns; i++) {
     shared_ptr<KuduTransaction> txn;
@@ -529,7 +533,8 @@ TEST_F(TxnWriteOpsITest, TxnMultipleSingleRowWritesCommit) {
     // is created at start, not on first transaction-related operation.
     "--txn_manager_lazily_initialized=false",
   };
-  NO_FATALS(StartCluster({}, master_flags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         master_flags, kNumTabletServers));
 
   NO_FATALS(Prepare());
   shared_ptr<KuduTransaction> txn;
@@ -565,7 +570,8 @@ TEST_F(TxnWriteOpsITest, FrequentElections) {
 
     // Disable the partition lock as there are concurrent transactions.
     // TODO(awong): update this when implementing finer grained locking.
-    "--enable_txn_partition_lock=false"
+    "--enable_txn_partition_lock=false",
+    "--enable_txn_system_client_init=true",
   };
   const vector<string> master_flags = {
     // Enable TxnManager in Kudu masters.
@@ -684,7 +690,8 @@ TEST_F(TxnWriteOpsITest, WriteOpPerf) {
 
     // Disable the partition lock as there are concurrent transactions.
     // TODO(awong): update this when implementing finer grained locking.
-    "--enable_txn_partition_lock=false"
+    "--enable_txn_partition_lock=false",
+    "--enable_txn_system_client_init=true",
   };
   const vector<string> master_flags = {
     // Enable TxnManager in Kudu masters.
@@ -842,7 +849,8 @@ TEST_F(TxnWriteOpsITest, WriteOpForNonExistentTxn) {
     // TODO(aserbin): remove this customization once the flag is 'on' by 
default
     "--txn_manager_enabled=true",
   };
-  NO_FATALS(StartCluster({}, master_flags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         master_flags, kNumTabletServers));
   NO_FATALS(Prepare());
 
   shared_ptr<KuduTransaction> txn;
@@ -892,7 +900,8 @@ TEST_F(TxnWriteOpsITest, TxnWriteAfterCommit) {
     // TODO(aserbin): remove this customization once the flag is 'on' by 
default
     "--txn_manager_enabled=true",
   };
-  NO_FATALS(StartCluster({}, master_flags, kNumTabletServers));
+  NO_FATALS(StartCluster({ "--enable_txn_system_client_init=true" },
+                         master_flags, kNumTabletServers));
   NO_FATALS(Prepare());
   int idx = 0;
   {
@@ -973,6 +982,7 @@ class TxnOpDispatcherITest : public KuduTest {
     FLAGS_txn_manager_enabled = true;
     FLAGS_txn_manager_lazily_initialized = false;
     FLAGS_txn_manager_status_table_num_replicas = num_replicas;
+    FLAGS_enable_txn_system_client_init = true;
 
     InternalMiniClusterOptions opts;
     opts.num_tablet_servers = num_tservers;
diff --git a/src/kudu/tools/kudu-txn-cli-test.cc 
b/src/kudu/tools/kudu-txn-cli-test.cc
index e4ea01f..7d8efc0 100644
--- a/src/kudu/tools/kudu-txn-cli-test.cc
+++ b/src/kudu/tools/kudu-txn-cli-test.cc
@@ -49,7 +49,8 @@ class KuduTxnsCliTest : public ExternalMiniClusterITestBase {
     NO_FATALS(ExternalMiniClusterITestBase::SetUp());
     // Some tests will depend on flushing MRSs quickly, so ensure flushes
     // happen quickly.
-    NO_FATALS(StartCluster({ "--flush_threshold_mb=1", 
"--flush_threshold_secs=1" },
+    NO_FATALS(StartCluster({ "--flush_threshold_mb=1", 
"--flush_threshold_secs=1",
+                             "--enable_txn_system_client_init" },
                             {"--txn_manager_enabled=true"}));
   }
 };
diff --git a/src/kudu/transactions/txn_status_manager-test.cc 
b/src/kudu/transactions/txn_status_manager-test.cc
index df3d10e..c888d0b 100644
--- a/src/kudu/transactions/txn_status_manager-test.cc
+++ b/src/kudu/transactions/txn_status_manager-test.cc
@@ -69,6 +69,7 @@ using std::unique_ptr;
 using std::unordered_set;
 using std::vector;
 
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(txn_schedule_background_tasks);
 DECLARE_uint32(txn_keepalive_interval_ms);
 DECLARE_uint32(txn_staleness_tracker_interval_ms);
@@ -93,6 +94,7 @@ class TxnStatusManagerTest : public TabletReplicaTestBase {
   void SetUp() override {
     // Using shorter intervals for transaction staleness tracking to speed up
     // test scenarios verifying related functionality.
+    FLAGS_enable_txn_system_client_init = true;
     FLAGS_txn_keepalive_interval_ms = 200;
     FLAGS_txn_staleness_tracker_interval_ms = 50;
     FLAGS_txn_schedule_background_tasks = false;
diff --git a/src/kudu/transactions/txn_system_client.cc 
b/src/kudu/transactions/txn_system_client.cc
index 28bf23d..35fe87d 100644
--- a/src/kudu/transactions/txn_system_client.cc
+++ b/src/kudu/transactions/txn_system_client.cc
@@ -55,11 +55,11 @@
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/threadpool.h"
 
-DEFINE_bool(disable_txn_system_client_init, false,
+DEFINE_bool(enable_txn_system_client_init, false,
             "Whether or not background TxnSystemClient initialization should "
-            "be disabled. This is useful for tests that do not expect any "
-            "client connections.");
-TAG_FLAG(disable_txn_system_client_init, unsafe);
+            "be enabled. Setting this to 'true' allows the server's "
+            "TxnSystemClient to participate in orchestrating transactions.");
+TAG_FLAG(enable_txn_system_client_init, experimental);
 
 DEFINE_int64(txn_system_client_op_timeout_ms, 10 * 1000,
              "Op timeout used by the TxnSystemClient when making 
transactions-related "
@@ -426,6 +426,13 @@ TxnSystemClientInitializer::~TxnSystemClientInitializer() {
 
 Status TxnSystemClientInitializer::Init(const shared_ptr<Messenger>& messenger,
                                         vector<HostPort> master_addrs) {
+  if (PREDICT_FALSE(!FLAGS_enable_txn_system_client_init)) {
+    // If we're set to not enable the system client, return early. Further
+    // attempts to access the client will fail since initialization never
+    // completes.
+    LOG(INFO) << "TxnSystemClient initialization is disabled...";
+    return Status::OK();
+  }
   RETURN_NOT_OK(ThreadPoolBuilder("txn-client-init")
       .set_max_threads(1)
       .Build(&txn_client_init_pool_));
@@ -433,14 +440,6 @@ Status TxnSystemClientInitializer::Init(const 
shared_ptr<Messenger>& messenger,
   return txn_client_init_pool_->Submit([this, messenger, master_addrs = 
std::move(master_addrs)] {
       unique_ptr<TxnSystemClient> txn_client;
       while (!shutting_down_) {
-        static const MonoDelta kRetryInterval = MonoDelta::FromSeconds(1);
-        if (PREDICT_FALSE(FLAGS_disable_txn_system_client_init)) {
-          KLOG_EVERY_N_SECS(WARNING, 60) <<
-              Substitute("initialization of TxnSystemClient disabled, will 
retry in $0",
-                         kRetryInterval.ToString());
-          SleepFor(kRetryInterval);
-          continue;
-        }
         // HACK: if the master addresses are all totally unreachable,
         // KuduClientBuilder::Build() will hang, attempting fruitlessly to
         // retry, in the below call to Create(). So first, make sure we can at
@@ -475,6 +474,7 @@ Status TxnSystemClientInitializer::Init(const 
shared_ptr<Messenger>& messenger,
           init_complete_ = true;
           return;
         }
+        static const MonoDelta kRetryInterval = MonoDelta::FromSeconds(1);
         KLOG_EVERY_N_SECS(WARNING, 60) <<
             Substitute("unable to initialize TxnSystemClient, will retry in 
$0: $1",
                        kRetryInterval.ToString(), s.ToString());
@@ -516,8 +516,10 @@ Status TxnSystemClientInitializer::WaitForClient(const 
MonoDelta& timeout,
 
 void TxnSystemClientInitializer::Shutdown() {
   shutting_down_ = true;
-  txn_client_init_pool_->Wait();
-  txn_client_init_pool_->Shutdown();
+  if (FLAGS_enable_txn_system_client_init) {
+    txn_client_init_pool_->Wait();
+    txn_client_init_pool_->Shutdown();
+  }
 }
 
 } // namespace transactions
diff --git a/src/kudu/tserver/tablet_service.cc 
b/src/kudu/tserver/tablet_service.cc
index eec5b3c..d2a1b94 100644
--- a/src/kudu/tserver/tablet_service.cc
+++ b/src/kudu/tserver/tablet_service.cc
@@ -178,6 +178,7 @@ DEFINE_bool(tserver_txn_write_op_handling_enabled, true,
             "in the context of multi-row transactions");
 TAG_FLAG(tserver_txn_write_op_handling_enabled, hidden);
 
+DECLARE_bool(enable_txn_system_client_init);
 DECLARE_bool(raft_prepare_replacement_before_eviction);
 DECLARE_int32(memory_limit_warn_threshold_percentage);
 DECLARE_int32(tablet_history_max_age_sec);
@@ -1668,6 +1669,13 @@ void TabletServiceImpl::Write(const WriteRequestPB* req,
     // Submit the write operation. The RPC will be responded asynchronously.
     s = replica->SubmitWrite(std::move(op_state));
   } else {
+    if (!FLAGS_enable_txn_system_client_init) {
+      return SetupErrorAndRespond(
+          resp->mutable_error(),
+          Status::NotSupported(Substitute("txns not supported on server $0",
+                                          replica->permanent_uuid())),
+          TabletServerErrorPB::UNKNOWN_ERROR, context);
+    }
     auto abort_func = [this, txn_id = req->txn_id(), &username] {
       return server_->tablet_manager()->ScheduleAbortTxn(txn_id, username);
     };

Reply via email to