Browse Source

ZOOKEEPER-2611: zoo_remove_watchers - can remove the wrong watch
(Eyal Leshmem via rgs)

Raul Gutierrez Segales 8 years ago
parent
commit
f78061aafb
3 changed files with 26 additions and 3 deletions
  1. 3 0
      CHANGES.txt
  2. 1 1
      src/c/src/zk_hashtable.c
  3. 22 2
      src/c/tests/TestClient.cc

+ 3 - 0
CHANGES.txt

@@ -394,6 +394,9 @@ BUGFIXES:
   ZOOKEEPER-2579: ZooKeeper server should verify that dataDir and
   snapDir are writeable before starting (Abraham Fine via phunt)
 
+  ZOOKEEPER-2611: zoo_remove_watchers - can remove the wrong watch
+  (Eyal Leshmem via rgs)
+
 IMPROVEMENTS:
   ZOOKEEPER-2024 Major throughput improvement with mixed workloads (Kfir Lev-Ari via shralex)
 

+ 1 - 1
src/c/src/zk_hashtable.c

@@ -371,7 +371,7 @@ static void removeWatcherFromList(watcher_object_list_t *wl, watcher_fn watcher,
     while (e){
         if (e->next &&
             e->next->watcher == watcher &&
-            e->context == watcherCtx) {
+            e->next->context == watcherCtx) {
             watcher_object_t *this = e->next;
             e->next = e->next->next;
             free(this);

+ 22 - 2
src/c/tests/TestClient.cc

@@ -1331,6 +1331,10 @@ public:
                       &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
       CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
+      rc = zoo_create(zk, "/something2", "", 0,
+                      &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
+      CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+
       char buf[1024];
       int blen = sizeof(buf);
       rc = zoo_get(zk, "/something", 1, buf, &blen, NULL);
@@ -1381,13 +1385,29 @@ public:
       zk = createClient(&ctx);
 
       /* add a watch, stop the server, and remove it locally */
-      rc = zoo_wget(zk, "/something", watcher_remove_watchers, NULL,
+      void* ctx1=(void*)0x1;
+      void* ctx2=(void*)0x2;
+
+      rc = zoo_wget(zk, "/something", watcher_remove_watchers, ctx1,
                     buf, &blen, NULL);
       CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+
+      rc = zoo_wget(zk, "/something2", watcher_remove_watchers, ctx2,
+                         buf, &blen, NULL);
+      CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+
       stopServer();
       rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA,
-                               watcher_remove_watchers, NULL, 1);
+                               watcher_remove_watchers, ctx1, 1);
       CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+
+      rc = zoo_remove_watchers(zk, "/something", ZWATCHERTYPE_DATA,
+                                    watcher_remove_watchers, ctx1, 1);
+      CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc);
+
+      rc = zoo_remove_watchers(zk, "/something2", ZWATCHERTYPE_DATA,
+                                          watcher_remove_watchers, ctx2, 1);
+      CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
     }
 };