tisonkun commented on PR #2062:
URL: https://github.com/apache/zookeeper/pull/2062#issuecomment-1720932722

   Here is a patch:
   
   ```diff
   diff --git 
a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java 
b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
   index 727d97daa..a2be07deb 100644
   --- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
   +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java
   @@ -856,13 +856,13 @@ class SendThread extends ZooKeeperThread {
            private volatile ZooKeeperSaslClient zooKeeperSaslClient;
    
            private String stripChroot(String serverPath) {
   -            if (serverPath.startsWith(chrootPath)) {
   +            if (serverPath.startsWith(ZooDefs.ZOOKEEPER_NODE_SUBTREE)) {
   +                return serverPath;
   +            } else if (serverPath.startsWith(chrootPath)) {
                    if (serverPath.length() == chrootPath.length()) {
                        return "/";
                    }
                    return serverPath.substring(chrootPath.length());
   -            } else if 
(serverPath.startsWith(ZooDefs.ZOOKEEPER_NODE_SUBTREE)) {
   -                return serverPath;
                }
                LOG.warn("Got server path {} which is not descendant of chroot 
path {}.", serverPath, chrootPath);
                return serverPath;
   diff --git 
a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ChrootTest.java 
b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ChrootTest.java
   index fca48c751..54f0f6560 100644
   --- 
a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ChrootTest.java
   +++ 
b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ChrootTest.java
   @@ -82,6 +82,25 @@ public void testChrootWithZooKeeperPathWatcher() throws 
Exception {
            assertEquals(ZooDefs.CONFIG_NODE, event.getPath());
        }
    
   +    @Test
   +    public void testChrootWithZooKeeperPathWatcherAndOverlapChrootPath() 
throws Exception {
   +        ZooKeeper zk1 = createClient(hostPort + "/zoo");
   +        BlockingQueue<WatchedEvent> events = new LinkedBlockingQueue<>();
   +        byte[] config = zk1.getConfig(events::add, null);
   +
   +        ZooKeeper zk2 = createClient();
   +        zk2.addAuthInfo("digest", "super:test".getBytes());
   +        zk2.setData(ZooDefs.CONFIG_NODE, config, -1);
   +
   +        waitFor("config watcher receive no event", () -> !events.isEmpty(), 
10);
   +
   +        WatchedEvent event = events.poll();
   +        assertNotNull(event);
   +        assertEquals(Watcher.Event.KeeperState.SyncConnected, 
event.getState());
   +        assertEquals(Watcher.Event.EventType.NodeDataChanged, 
event.getType());
   +        assertEquals(ZooDefs.CONFIG_NODE, event.getPath());
   +    }
   +
        @Test
        public void testChrootSynchronous() throws IOException, 
InterruptedException, KeeperException {
            ZooKeeper zk1 = createClient();
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to