You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2019/03/19 00:12:34 UTC

[zookeeper] branch branch-3.5 updated: ZOOKEEPER-2168: Add C APIs for new createContainer Methods

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

andor pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.5 by this push:
     new 7b36fd5  ZOOKEEPER-2168: Add C APIs for new createContainer Methods
7b36fd5 is described below

commit 7b36fd550c0e5c85388918d1467a87f0b129ada6
Author: Balazs Meszaros <me...@apache.org>
AuthorDate: Mon Mar 18 17:12:03 2019 -0700

    ZOOKEEPER-2168: Add C APIs for new createContainer Methods
    
    I rebased and addressed the comments of https://github.com/apache/zookeeper/pull/33 by Randgalt
    
    Author: randgalt <jo...@jordanzimmerman.com>
    Author: Balazs Meszaros <ba...@cloudera.com>
    
    Reviewers: andor@apache.org
    
    Closes #838 from meszibalu/my/container and squashes the following commits:
    
    c6c9dc0a6 [Balazs Meszaros] ZOOKEEPER-2168 - added test case for containers
    ed4b842e6 [Balazs Meszaros] ZOOKEEPER-2168 - rebase and review comment fixes
    f0f144129 [randgalt] ZOOKEEPER-2168 - fixed typo
    4cea8d412 [randgalt] ZOOKEEPER-2168 - first pass at C changes for containers
    
    (cherry picked from commit 9fba2f6c93a78928df4841a66185f51e242653aa)
    Signed-off-by: Andor Molnar <an...@apache.org>
---
 zookeeper-client/zookeeper-client-c/include/proto.h     |  2 ++
 zookeeper-client/zookeeper-client-c/include/zookeeper.h |  1 +
 zookeeper-client/zookeeper-client-c/src/zookeeper.c     | 12 ++++++++----
 zookeeper-client/zookeeper-client-c/tests/TestClient.cc | 14 ++++++++++++++
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/zookeeper-client/zookeeper-client-c/include/proto.h b/zookeeper-client/zookeeper-client-c/include/proto.h
index 7c3fc16..f9489f0 100644
--- a/zookeeper-client/zookeeper-client-c/include/proto.h
+++ b/zookeeper-client/zookeeper-client-c/include/proto.h
@@ -40,6 +40,8 @@ extern "C" {
 #define ZOO_RECONFIG_OP 16
 #define ZOO_CHECK_WATCHES 17
 #define ZOO_REMOVE_WATCHES 18
+#define ZOO_CREATE_CONTAINER_OP 19
+#define ZOO_DELETE_CONTAINER_OP 20
 #define ZOO_CLOSE_OP -11
 #define ZOO_SETAUTH_OP 100
 #define ZOO_SETWATCHES_OP 101
diff --git a/zookeeper-client/zookeeper-client-c/include/zookeeper.h b/zookeeper-client/zookeeper-client-c/include/zookeeper.h
index cc19c90..95c7b3b 100644
--- a/zookeeper-client/zookeeper-client-c/include/zookeeper.h
+++ b/zookeeper-client/zookeeper-client-c/include/zookeeper.h
@@ -194,6 +194,7 @@ extern ZOOAPI const int ZOOKEEPER_READ;
 // @{
 extern ZOOAPI const int ZOO_EPHEMERAL;
 extern ZOOAPI const int ZOO_SEQUENCE;
+extern ZOOAPI const int ZOO_CONTAINER;
 // @}
 
 /**
diff --git a/zookeeper-client/zookeeper-client-c/src/zookeeper.c b/zookeeper-client/zookeeper-client-c/src/zookeeper.c
index fc04555..25baa9c 100644
--- a/zookeeper-client/zookeeper-client-c/src/zookeeper.c
+++ b/zookeeper-client/zookeeper-client-c/src/zookeeper.c
@@ -99,6 +99,7 @@ const int ZOOKEEPER_READ = 1 << 1;
 
 const int ZOO_EPHEMERAL = 1 << 0;
 const int ZOO_SEQUENCE = 1 << 1;
+const int ZOO_CONTAINER = 1 << 2;
 
 const int ZOO_EXPIRED_SESSION_STATE = EXPIRED_SESSION_STATE_DEF;
 const int ZOO_AUTH_FAILED_STATE = AUTH_FAILED_STATE_DEF;
@@ -108,6 +109,8 @@ const int ZOO_CONNECTED_STATE = CONNECTED_STATE_DEF;
 const int ZOO_READONLY_STATE = READONLY_STATE_DEF;
 const int ZOO_NOTCONNECTED_STATE = NOTCONNECTED_STATE_DEF;
 
+#define ZOOKEEPER_IS_CONTAINER(flags) (((flags) & ZOO_CONTAINER) == ZOO_CONTAINER)
+
 static __attribute__ ((unused)) const char* state2String(int state){
     switch(state){
     case 0:
@@ -3559,7 +3562,7 @@ int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
         string_completion_t completion, const void *data)
 {
     struct oarchive *oa;
-    struct RequestHeader h = {get_xid(), ZOO_CREATE_OP};
+    struct RequestHeader h = {get_xid(), ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE_OP};
     struct CreateRequest req;
 
     int rc = CreateRequest_init(zh, &req,
@@ -3591,7 +3594,7 @@ int zoo_acreate2(zhandle_t *zh, const char *path, const char *value,
         string_stat_completion_t completion, const void *data)
 {
     struct oarchive *oa;
-    struct RequestHeader h = { get_xid(), ZOO_CREATE2_OP };
+    struct RequestHeader h = { get_xid(), ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE2_OP };
     struct CreateRequest req;
 
     int rc = CreateRequest_init(zh, &req, path, value, valuelen, acl_entries, flags);
@@ -3956,6 +3959,7 @@ int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops,
         rc = rc < 0 ? rc : serialize_MultiHeader(oa, "multiheader", &mh);
 
         switch(op->type) {
+            case ZOO_CREATE_CONTAINER_OP:
             case ZOO_CREATE_OP: {
                 struct CreateRequest req;
 
@@ -4138,7 +4142,7 @@ void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value,
         char *path_buffer, int path_buffer_len)
 {
     assert(op);
-    op->type = ZOO_CREATE_OP;
+    op->type = ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE_OP;
     op->create_op.path = path;
     op->create_op.data = value;
     op->create_op.datalen = valuelen;
@@ -4153,7 +4157,7 @@ void zoo_create2_op_init(zoo_op_t *op, const char *path, const char *value,
         char *path_buffer, int path_buffer_len)
 {
     assert(op);
-    op->type = ZOO_CREATE2_OP;
+    op->type = ZOOKEEPER_IS_CONTAINER(flags) ? ZOO_CREATE_CONTAINER_OP : ZOO_CREATE2_OP;
     op->create_op.path = path;
     op->create_op.data = value;
     op->create_op.datalen = valuelen;
diff --git a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
index 89bf856..b6d8a64 100644
--- a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
+++ b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc
@@ -210,6 +210,7 @@ class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testIPV6);
 #endif
     CPPUNIT_TEST(testCreate);
+    CPPUNIT_TEST(testCreateContainer);
     CPPUNIT_TEST(testPath);
     CPPUNIT_TEST(testPathValidation);
     CPPUNIT_TEST(testPing);
@@ -698,6 +699,19 @@ public:
         CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b) != 1);
     }
 
+    void testCreateContainer() {
+        watchctx_t ctx;
+        int rc = 0;
+        zhandle_t *zk = createClient(&ctx);
+        CPPUNIT_ASSERT(zk);
+        char pathbuf[80];
+        struct Stat stat = {0};
+
+        rc = zoo_create2(zk, "/testContainer", "", 0, &ZOO_OPEN_ACL_UNSAFE,
+                         ZOO_CONTAINER, pathbuf, sizeof(pathbuf), &stat);
+        CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+    }
+
     void testGetChildren2() {
         int rc;
         watchctx_t ctx;