Browse Source

ZOOKEEPER-255. zoo_set() api does not return stat datastructure. (avery ching via mahadev)

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

+ 4 - 0
CHANGES.txt

@@ -2,6 +2,10 @@ Trunk
   
 Non-backward compatible changes:
 
+BUGFIXES:
+  ZOOKEEPER-255. zoo_set() api does not return stat datastructure. (avery
+ching via mahadev)
+
 Backward compatibile changes:
 
 BUGFIXES: 

+ 3 - 3
src/c/include/zookeeper.h

@@ -1084,6 +1084,7 @@ 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.
@@ -1093,9 +1094,8 @@ ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
  * 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_set(zhandle_t *zh, const char *path, const char *buffer, int buflen,
-                   int version);
-
+ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
+                   int buflen, int version, struct Stat *stat);
 
 /**
  * \brief lists the children of a node synchronously.

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

@@ -266,7 +266,8 @@ void processline(char *line) {
             rc = zoo_aset(zh, line, ptr, strlen(ptr), -1, my_stat_completion,
                     strdup(line));
         } else {
-            rc = zoo_set(zh, line, ptr, strlen(ptr), -1);
+            struct Stat stat;
+            rc = zoo_set(zh, line, ptr, strlen(ptr), -1, &stat);
         }
         if (rc) {
             fprintf(stderr, "Error %d for %s\n", rc, line);

+ 7 - 3
src/c/src/zookeeper.c

@@ -492,8 +492,9 @@ zhandle_t *zookeeper_init(const char *host, watcher_fn watcher,
               host,
               recv_timeout,
               watcher,
-              clientid->client_id,
-              (clientid->passwd == 0 ? "<null>" : "<hidden>"),
+              (clientid == 0 ? 0 : clientid->client_id),
+              ((clientid == 0) || (clientid->passwd == 0) ?
+               "<null>" : "<hidden>"),
               context,
               flags));
 
@@ -2426,7 +2427,7 @@ 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)
+        int version, struct Stat *stat)
 {
     struct sync_completion *sc = alloc_sync_completion();
     int rc;
@@ -2437,6 +2438,9 @@ int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen,
     if(rc==ZOK){
         wait_sync_completion(sc);
         rc = sc->rc;
+        if (rc == 0 && stat) {
+            *stat = sc->u.stat;
+        }
     }
     free_sync_completion(sc);
     return rc;

+ 10 - 1
src/c/tests/TestClient.cc

@@ -390,7 +390,16 @@ public:
         CPPUNIT_ASSERT_MESSAGE(testName, ctxLocal->waitForConnected(zk));
 
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
-        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1);
+
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, 0);
+        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        struct Stat stat1, stat2;
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, &stat1);
+        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT(stat1.version >= 0);
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, stat1.version, &stat2);
+        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version, 0);
         CPPUNIT_ASSERT_EQUAL(ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child2", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);

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

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