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

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

commit 36c5a2e29e95e9133adbaf8e1b82d4bdc8d74435
Author: Alexey Serbin <[email protected]>
AuthorDate: Mon Feb 15 18:50:32 2021 -0800

    [test] enable hash partitioning for TestWorkload's table
    
    With this patch, it's now possible to have auto-created TestWorkload's
    table use hash partitioning.  The newly introduced functionality
    will be used in follow-up patches.
    
    Change-Id: Ie693431a64ba2c3eb1ed1021faf8da42af03db86
    Reviewed-on: http://gerrit.cloudera.org:8080/17067
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Alexey Serbin <[email protected]>
---
 src/kudu/integration-tests/test_workload.cc | 55 ++++++++++++++++++++---------
 src/kudu/integration-tests/test_workload.h  | 33 +++++++++++++----
 2 files changed, 65 insertions(+), 23 deletions(-)

diff --git a/src/kudu/integration-tests/test_workload.cc 
b/src/kudu/integration-tests/test_workload.cc
index 441e22b..5cc6bdd 100644
--- a/src/kudu/integration-tests/test_workload.cc
+++ b/src/kudu/integration-tests/test_workload.cc
@@ -58,8 +58,10 @@ namespace kudu {
 
 const char* const TestWorkload::kDefaultTableName = "test-workload";
 
-TestWorkload::TestWorkload(MiniCluster* cluster)
+TestWorkload::TestWorkload(MiniCluster* cluster,
+                           PartitioningType partitioning)
   : cluster_(cluster),
+    partitioning_(partitioning),
     rng_(SeedRandom()),
     num_write_threads_(4),
     num_read_threads_(0),
@@ -79,7 +81,7 @@ TestWorkload::TestWorkload(MiniCluster* cluster)
     selection_(client::KuduClient::CLOSEST_REPLICA),
     schema_(KuduSchema::FromSchema(GetSimpleTestSchema())),
     num_replicas_(3),
-    num_tablets_(1),
+    num_tablets_(partitioning_ == PartitioningType::RANGE ? 1 : 2),
     table_name_(kDefaultTableName),
     start_latch_(0),
     should_run_(false),
@@ -304,25 +306,44 @@ void TestWorkload::Setup() {
   CHECK_OK(s);
 
   if (!table_exists) {
-    // Create split rows.
-    vector<const KuduPartialRow*> splits;
-    for (int i = 1; i < num_tablets_; i++) {
-      KuduPartialRow* r = schema_.NewRow();
-      CHECK_OK(r->SetInt32("key", MathLimits<int32_t>::kMax / num_tablets_ * 
i));
-      splits.push_back(r);
-    }
-
     // Create the table.
-    unique_ptr<KuduTableCreator> table_creator(client_->NewTableCreator());
+    unique_ptr<KuduTableCreator> creator_ptr(client_->NewTableCreator());
+
+    // Just an eye candy to use dots (.) only, not dots and arrows (->) mix.
+    KuduTableCreator& table_creator = *creator_ptr;
+    table_creator
+        .table_name(table_name_)
+        .schema(&schema_)
+        .num_replicas(num_replicas_);
+
+    switch (partitioning_) {
+      case PartitioningType::HASH:
+        table_creator.add_hash_partitions({ "key" }, num_tablets_);
+        break;
+      case PartitioningType::RANGE:
+        {
+          // Create split rows.
+          vector<const KuduPartialRow*> splits;
+          for (int i = 1; i < num_tablets_; i++) {
+            KuduPartialRow* r = schema_.NewRow();
+            CHECK_OK(r->SetInt32("key",
+                                 MathLimits<int32_t>::kMax / num_tablets_ * 
i));
+            splits.push_back(r);
+          }
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-    Status s = table_creator->table_name(table_name_)
-        .schema(&schema_)
-        .num_replicas(num_replicas_)
-        .set_range_partition_columns({ "key" })
-        .split_rows(splits)
-        .Create();
+          table_creator
+              .set_range_partition_columns({ "key" })
+              .split_rows(splits);
 #pragma GCC diagnostic pop
+        }
+        break;
+      default:
+        LOG(FATAL) << "unexpected partitioning type for test table";
+        return; // unreachable
+    }
+
+    const auto s = table_creator.Create();
     if (!s.ok()) {
       if (!s.IsAlreadyPresent() && !s.IsServiceUnavailable()) {
         // TODO(KUDU-1537): Should be fixed with Exactly Once semantics.
diff --git a/src/kudu/integration-tests/test_workload.h 
b/src/kudu/integration-tests/test_workload.h
index 3f5ffb0..f93cb58 100644
--- a/src/kudu/integration-tests/test_workload.h
+++ b/src/kudu/integration-tests/test_workload.h
@@ -59,7 +59,22 @@ class TestWorkload {
  public:
   static const char* const kDefaultTableName;
 
-  explicit TestWorkload(cluster::MiniCluster* cluster);
+  // Kudu provides two types of partitioning for a table: range partitioning 
and
+  // hash partitioning. This enum contains corresponding elements to be used
+  // to define partitioning type for the test table. Multi-level partitioning
+  // for the test table automatically created by TestWorkload isn't supported
+  // yet: as a workaround, point TestWorkload to already existing table
+  // with desired partitioning type.
+  enum class PartitioningType {
+    RANGE,
+    HASH,
+  };
+
+  // Create an test workload object to run against the specified cluster
+  // using a test table of the specified partitioning type.
+  explicit TestWorkload(
+      cluster::MiniCluster* cluster,
+      PartitioningType partitioning = PartitioningType::RANGE);
   ~TestWorkload();
 
   // Sets whether the read thread should crash if scanning to the cluster fails
@@ -154,11 +169,16 @@ class TestWorkload {
     num_replicas_ = r;
   }
 
-  // Set the number of tablets for the table created by this workload.
-  // The split points are evenly distributed through positive int32s.
-  void set_num_tablets(int tablets) {
-    CHECK_GE(tablets, 1);
-    num_tablets_ = tablets;
+  // Set the number of tablets for the test table created by this workload.
+  // In case of range partitioning, the split points are evenly distributed
+  // through positive int32s.
+  void set_num_tablets(int num_tablets) {
+    if (partitioning_ == PartitioningType::RANGE) {
+      CHECK_GE(num_tablets, 1);
+    } else {
+      CHECK_GE(num_tablets, 2);
+    }
+    num_tablets_ = num_tablets;
   }
 
   void set_table_name(const std::string& table_name) {
@@ -262,6 +282,7 @@ class TestWorkload {
   size_t GetNumberOfErrors(client::KuduSession* session);
 
   cluster::MiniCluster* cluster_;
+  const PartitioningType partitioning_;
   client::KuduClientBuilder client_builder_;
   client::sp::shared_ptr<client::KuduClient> client_;
   ThreadSafeRandom rng_;

Reply via email to