Browse Source

ZOOKEEPER-293. zoo_set needs to be abi compatible (3.1 changed the signature), fix this by adding zoo_set2 (pat via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@741294 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 16 years ago
parent
commit
4447e6dfa7

+ 6 - 0
CHANGES.txt

@@ -106,6 +106,12 @@ and runping via mahadev)
   ZOOKEEPER-291. regression for legacy code using KeeperException.Code 
   constants (due to 246). (pat via mahadev)
 
+  ZOOKEEPER-255. zoo_set() api does not return stat datastructure.
+  (avery ching via mahadev)
+
+  ZOOKEEPER-293. zoo_set needs to be abi compatible (3.1 changed the
+signature), fix this by adding zoo_set2 (pat via mahadev)
+
 IMPROVEMENTS:
    
   ZOOKEEPER-64. Log system env information when initializing server and

+ 2 - 2
src/c/Makefile.am

@@ -7,7 +7,7 @@ CXXFLAGS = -Wall -g
 
 LIB_LDFLAGS = -no-undefined -version-info 2
 
-pkginclude_HEADERS = include/zookeeper.h include/recordio.h generated/zookeeper.jute.h
+pkginclude_HEADERS = include/zookeeper.h include/zookeeper_version.h include/recordio.h generated/zookeeper.jute.h
 EXTRA_DIST=LICENSE
 
 HASHTABLE_SRC = src/hashtable/hashtable_itr.h src/hashtable/hashtable_itr.c \
@@ -16,7 +16,7 @@ HASHTABLE_SRC = src/hashtable/hashtable_itr.h src/hashtable/hashtable_itr.c \
 noinst_LTLIBRARIES = libhashtable.la
 libhashtable_la_SOURCES = $(HASHTABLE_SRC)
 
-COMMON_SRC = src/zookeeper.c include/zookeeper.h \
+COMMON_SRC = src/zookeeper.c include/zookeeper.h include/zookeeper_version.h \
     src/recordio.c include/recordio.h include/proto.h \
     src/zk_adaptor.h generated/zookeeper.jute.c \
     src/zk_log.h src/zk_log.c src/zk_hashtable.h src/zk_hashtable.c

+ 30 - 2
src/c/include/zookeeper.h

@@ -21,6 +21,8 @@
 
 #include <sys/time.h>
 #include <stdio.h>
+
+#include "zookeeper_version.h"
 #include "recordio.h"
 #include "zookeeper.jute.h"
 
@@ -1089,7 +1091,8 @@ ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
         char *buffer, int* buffer_len, struct Stat *stat);
 
 /**
- * \brief sets the data associated with a node.
+ * \brief sets the data associated with a node. See zoo_set2 function if
+ * you require access to the stat information associated with the znode.
  * 
  * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  * \param path the name of the node. Expressed as a file name with slashes 
@@ -1099,7 +1102,6 @@ ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
  * \param version the expected version of the node. The function will fail if 
  * the actual version of the node does not match the expected version. If -1 is 
  * used the version check will not take place. 
- * \param stat if not NULL, will hold the value of stat for the path on return.
  * \return the return code for the function call.
  * ZOK operation completed succesfully
  * ZNONODE the node does not exist.
@@ -1110,6 +1112,32 @@ ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
  * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  */
 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
+                   int buflen, int version);
+
+/**
+ * \brief sets the data associated with a node. This function is the same
+ * as zoo_set except that it also provides access to stat information
+ * associated with the znode.
+ * 
+ * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
+ * \param path the name of the node. Expressed as a file name with slashes 
+ * separating ancestors of the node.
+ * \param buffer the buffer holding data to be written to the node.
+ * \param buflen the number of bytes from buffer to write.
+ * \param version the expected version of the node. The function will fail if 
+ * the actual version of the node does not match the expected version. If -1 is 
+ * used the version check will not take place. 
+ * \param stat if not NULL, will hold the value of stat for the path on return.
+ * \return the return code for the function call.
+ * ZOK operation completed succesfully
+ * ZNONODE the node does not exist.
+ * ZNOAUTH the client does not have permission.
+ * ZBADVERSION expected version does not match actual version.
+ * ZBADARGUMENTS - invalid input parameters
+ * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
+ * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
+ */
+ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
                    int buflen, int version, struct Stat *stat);
 
 /**

+ 33 - 0
src/c/include/zookeeper_version.h

@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ZOOKEEPER_VERSION_H_
+#define ZOOKEEPER_VERSION_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZOO_MAJOR_VERSION 3
+#define ZOO_MINOR_VERSION 2
+#define ZOO_PATCH_VERSION 0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZOOKEEPER_VERSION_H_ */

+ 6 - 1
src/c/src/cli.c

@@ -277,7 +277,7 @@ void processline(char *line) {
                     strdup(line));
         } else {
             struct Stat stat;
-            rc = zoo_set(zh, line, ptr, strlen(ptr), -1, &stat);
+            rc = zoo_set2(zh, line, ptr, strlen(ptr), -1, &stat);
         }
         if (rc) {
             fprintf(stderr, "Error %d for %s\n", rc, line);
@@ -400,6 +400,11 @@ int main(int argc, char **argv) {
         fprintf(stderr,
                 "USAGE %s zookeeper_host_list [clientid_file|cmd:(ls|create|od|...)]\n", 
                 argv[0]);
+        fprintf(stderr,
+                "Version: ZooKeeper cli (c client) version %d.%d.%d\n", 
+                ZOO_MAJOR_VERSION,
+                ZOO_MINOR_VERSION,
+                ZOO_PATCH_VERSION);
         return 2;
     }
     if (argc > 2) {

+ 6 - 0
src/c/src/zookeeper.c

@@ -2491,6 +2491,12 @@ int zoo_wget(zhandle_t *zh, const char *path,
 }
 
 int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen,
+        int version)
+{
+  return zoo_set2(zh, path, buffer, buflen, version, 0);
+}
+
+int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, int buflen,
         int version, struct Stat *stat)
 {
     struct sync_completion *sc = alloc_sync_completion();

+ 4 - 4
src/c/tests/TestClient.cc

@@ -443,15 +443,15 @@ public:
 
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
 
-        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, 0);
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         struct Stat stat1, stat2;
-        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, &stat1);
+        rc = zoo_set2(zk, "/watchtest/child", "1", 1, -1, &stat1);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT(stat1.version >= 0);
-        rc = zoo_set(zk, "/watchtest/child", "1", 1, stat1.version, &stat2);
+        rc = zoo_set2(zk, "/watchtest/child", "1", 1, stat1.version, &stat2);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
-        rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version, 0);
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child2", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);

+ 1 - 2
src/contrib/zkfuse/src/zkadapter.cc

@@ -867,8 +867,7 @@ ZooKeeperAdapter::setNodeData(const string &path,
                       path.c_str(),
                       value.c_str(),
                       value.length(),
-                      version,
-                      0);
+                      version);
     } while (rc != ZOK && rh.handleRC(rc));
     if (rc != ZOK) {
         LOG_ERROR( LOG, "Error %d for %s", rc, path.c_str() );