Forráskód Böngészése

ZOOKEEPER-682. Event is not processed when the watcher is set to watch "/" if chrooted (Scott Wang via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@918810 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 15 éve
szülő
commit
691dfa44b4

+ 3 - 0
CHANGES.txt

@@ -237,6 +237,9 @@ BUGFIXES:
   ZOOKEEPER-683. LogFormatter fails to parse transactional log files (phunt
   via mahadev)
 
+  ZOOKEEPER-682. Event is not processed when the watcher is set to watch "/"
+  if chrooted (Scott Wang via mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

+ 4 - 1
src/java/main/org/apache/zookeeper/ClientCnxn.java

@@ -744,7 +744,10 @@ public class ClientCnxn {
                 // convert from a server path to a client path
                 if (chrootPath != null) {
                     String serverPath = event.getPath();
-                    event.setPath(serverPath.substring(chrootPath.length()));
+                    if(serverPath.compareTo(chrootPath)==0)
+                        event.setPath("/");
+                    else
+                        event.setPath(serverPath.substring(chrootPath.length()));
                 }
 
                 WatchedEvent we = new WatchedEvent(event);

+ 9 - 0
src/java/test/org/apache/zookeeper/test/ChrootTest.java

@@ -84,6 +84,12 @@ public class ChrootTest extends ClientBase {
 
             MyWatcher w3 = new MyWatcher("/ch2");
             assertNotNull(zk2.exists("/ch2", w3));
+            
+            // set watches on child
+            MyWatcher w4 = new MyWatcher("/ch1");
+            zk1.getChildren("/ch1",w4);
+            MyWatcher w5 = new MyWatcher("/");
+            zk2.getChildren("/",w5);
 
             // check set
             zk1.setData("/ch1", "1".getBytes(), -1);
@@ -110,6 +116,9 @@ public class ChrootTest extends ClientBase {
 
             // check delete
             zk2.delete("/ch2", -1);
+            assertTrue(w4.matches());
+            assertTrue(w5.matches());
+            
             zk1.delete("/ch1", -1);
             assertNull(zk1.exists("/ch1", false));
             assertNull(zk1.exists("/ch1/ch2", false));