From commits-return-7686-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Tue Mar 19 00:12:13 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 55F11180651 for ; Tue, 19 Mar 2019 01:12:12 +0100 (CET) Received: (qmail 24159 invoked by uid 500); 19 Mar 2019 00:12:11 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 24148 invoked by uid 99); 19 Mar 2019 00:12:11 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Mar 2019 00:12:11 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B468182F24; Tue, 19 Mar 2019 00:12:10 +0000 (UTC) Date: Tue, 19 Mar 2019 00:12:10 +0000 To: "commits@zookeeper.apache.org" Subject: [zookeeper] branch master updated: ZOOKEEPER-2168: Add C APIs for new createContainer Methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155295433061.13700.10912993745602713614@gitbox.apache.org> From: andor@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: zookeeper X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 19cb6fb8f7989121025f91889462386eb8918c56 X-Git-Newrev: 9fba2f6c93a78928df4841a66185f51e242653aa X-Git-Rev: 9fba2f6c93a78928df4841a66185f51e242653aa X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. andor pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zookeeper.git The following commit(s) were added to refs/heads/master by this push: new 9fba2f6 ZOOKEEPER-2168: Add C APIs for new createContainer Methods 9fba2f6 is described below commit 9fba2f6c93a78928df4841a66185f51e242653aa Author: Balazs Meszaros 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 Author: Balazs Meszaros 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 --- 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 2f435d4..8df1558 100644 --- a/zookeeper-client/zookeeper-client-c/include/zookeeper.h +++ b/zookeeper-client/zookeeper-client-c/include/zookeeper.h @@ -197,6 +197,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 239ffa2..a17b37d 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: @@ -3545,7 +3548,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, @@ -3577,7 +3580,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); @@ -3942,6 +3945,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; @@ -4124,7 +4128,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; @@ -4139,7 +4143,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 2006c45..a296dfc 100644 --- a/zookeeper-client/zookeeper-client-c/tests/TestClient.cc +++ b/zookeeper-client/zookeeper-client-c/tests/TestClient.cc @@ -211,6 +211,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); @@ -709,6 +710,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;