kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/3] kudu git commit: KUDU-1593 - [python] Allow to set the number of replicas per tablet at table creation time
Date Thu, 08 Sep 2016 16:30:40 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 46d9ed7aa -> d807034dd


KUDU-1593 - [python] Allow to set the number of replicas per tablet at table creation time

Currently the Kudu Python client does not allow for the number of replicas to be set at
table creation time because the num_replicas method of the KuduTableCreator is not
exposed to the Python class. This patch exposes that method as well as it exposes the
num_replicas method of the KuduTable class so that the number of replicas for a table
can be retrieved from the cluster.  This patch includes a test.

Change-Id: I9dcac887029ef22e850ea8be72e71b684e6bee05
Reviewed-on: http://gerrit.cloudera.org:8080/4315
Reviewed-by: David Ribeiro Alves <dralves@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/211a5e4a
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/211a5e4a
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/211a5e4a

Branch: refs/heads/master
Commit: 211a5e4a3f3ea44ed297337a26e657866c5830df
Parents: 46d9ed7
Author: Jordan Birdsell <jordantbirdsell@gmail.com>
Authored: Tue Sep 6 09:13:51 2016 -0400
Committer: Todd Lipcon <todd@apache.org>
Committed: Thu Sep 8 02:13:02 2016 +0000

----------------------------------------------------------------------
 python/kudu/client.pyx           |  8 +++++++-
 python/kudu/libkudu_client.pxd   |  1 +
 python/kudu/tests/test_client.py | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/211a5e4a/python/kudu/client.pyx
----------------------------------------------------------------------
diff --git a/python/kudu/client.pyx b/python/kudu/client.pyx
index de816c4..8aefc1c 100644
--- a/python/kudu/client.pyx
+++ b/python/kudu/client.pyx
@@ -226,7 +226,7 @@ cdef class Client:
         # Nothing yet to clean up here
         pass
 
-    def create_table(self, table_name, Schema schema, partitioning):
+    def create_table(self, table_name, Schema schema, partitioning, n_replicas=None):
         """
         Creates a new Kudu table from the passed Schema and options.
 
@@ -236,6 +236,8 @@ cdef class Client:
         schema : kudu.Schema
           Create using kudu.schema_builder
         partitioning : Partitioning object
+        n_replicas : int Number of replicas to set. This should be an odd number.
+          If not provided (or if <= 0), falls back to the server-side default.
         """
         cdef:
             KuduTableCreator* c
@@ -245,6 +247,8 @@ cdef class Client:
             c.table_name(tobytes(table_name))
             c.schema(schema.schema)
             self._apply_partitioning(c, partitioning)
+            if n_replicas:
+                c.num_replicas(n_replicas)
             s = c.Create()
             check_status(s)
         finally:
@@ -489,6 +493,7 @@ cdef class Table:
         object _name
         Schema schema
         Client parent
+        int num_replicas
 
     def __cinit__(self, name, Client client):
         self._name = name
@@ -502,6 +507,7 @@ cdef class Table:
         self.schema.schema = &self.ptr().schema()
         self.schema.own_schema = 0
         self.schema.parent = self
+        self.num_replicas = self.ptr().num_replicas()
 
     def __len__(self):
         # TODO: is this cheaply knowable?

http://git-wip-us.apache.org/repos/asf/kudu/blob/211a5e4a/python/kudu/libkudu_client.pxd
----------------------------------------------------------------------
diff --git a/python/kudu/libkudu_client.pxd b/python/kudu/libkudu_client.pxd
index 8fe4942..ecc70b4 100644
--- a/python/kudu/libkudu_client.pxd
+++ b/python/kudu/libkudu_client.pxd
@@ -522,6 +522,7 @@ cdef extern from "kudu/client/client.h" namespace "kudu::client" nogil:
 
         string& name()
         KuduSchema& schema()
+        int num_replicas()
 
         KuduInsert* NewInsert()
         KuduUpsert* NewUpsert()

http://git-wip-us.apache.org/repos/asf/kudu/blob/211a5e4a/python/kudu/tests/test_client.py
----------------------------------------------------------------------
diff --git a/python/kudu/tests/test_client.py b/python/kudu/tests/test_client.py
index 49f413a..dba95b3 100644
--- a/python/kudu/tests/test_client.py
+++ b/python/kudu/tests/test_client.py
@@ -94,6 +94,26 @@ class TestClient(KuduTestBase, unittest.TestCase):
         self.assertRaises(kudu.KuduNotFound, self.client.table,
                           '__donotexist__')
 
+    def test_create_table_with_different_replication_factors(self):
+        name = "different_replica_table"
+
+        # Test setting the number of replicas for 1, 3 and 5 provided that the
+        # number does not exceed the number of tservers
+        for n_replicas in [n for n in [1, 3, 5] if n <= self.NUM_TABLET_SERVERS]:
+            try:
+                self.client.create_table(
+                    name, self.schema,
+                    partitioning=Partitioning().add_hash_partitions(['key'], 2),
+                    n_replicas=n_replicas)
+
+                assert n_replicas == self.client.table(name).num_replicas
+
+            finally:
+                try:
+                    self.client.delete_table(name)
+                except:
+                    pass
+
     def test_create_partitioned_table(self):
         name = 'partitioned_table'
         try:


Mime
View raw message