diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java index cbd610c7fd5..1ce116e3955 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ActiveStandbyElector.java @@ -1080,7 +1080,7 @@ public class ActiveStandbyElector implements StatCallback, StringCallback { List acl = zkClient.getACL(path, stat); if (acl == null || !acl.containsAll(zkAcl) || !zkAcl.containsAll(acl)) { - zkClient.setACL(path, zkAcl, stat.getVersion()); + zkClient.setACL(path, zkAcl, stat.getAversion()); } return null; } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java index fb8c236c8fd..59c08868276 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestActiveStandbyElectorRealZK.java @@ -30,7 +30,9 @@ import org.apache.hadoop.ha.ActiveStandbyElector.ActiveStandbyElectorCallback; import org.apache.hadoop.ha.ActiveStandbyElector.State; import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.log4j.Level; +import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.server.ZooKeeperServer; import org.junit.Test; import org.mockito.AdditionalMatchers; @@ -256,4 +258,30 @@ public class TestActiveStandbyElectorRealZK extends ClientBaseWithFixes { Mockito.verify(cbs[1], Mockito.never()).becomeActive(); checkFatalsAndReset(); } + + /** + * Test to verify that proper ZooKeeper ACLs can be updated on + * ActiveStandbyElector's parent znode. + */ + @Test(timeout = 15000) + public void testSetZooKeeperACLsOnParentZnodeName() + throws Exception { + ActiveStandbyElectorCallback cb = + Mockito.mock(ActiveStandbyElectorCallback.class); + ActiveStandbyElector elector = + new ActiveStandbyElector(hostPort, 5000, PARENT_DIR, + Ids.READ_ACL_UNSAFE, Collections.emptyList(), cb, + CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT); + + // Simulate the case by pre-creating znode 'parentZnodeName'. Then updates + // znode's data so that data version will be increased to 1. Here znode's + // aversion is 0. + ZooKeeper otherClient = createClient(); + otherClient.create(PARENT_DIR, "sample1".getBytes(), Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + otherClient.setData(PARENT_DIR, "sample2".getBytes(), -1); + otherClient.close(); + + elector.ensureParentZNode(); + } }