HADOOP-14543. ZKFC should use getAversion() while setting the zkacl. Contributed by Brahma Reddy Battula.

This commit is contained in:
Arpit Agarwal 2017-06-23 16:50:47 -07:00
parent c6bd73c6c5
commit 0111711d8b
2 changed files with 29 additions and 1 deletions

View File

@ -1080,7 +1080,7 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
List<ACL> 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;
}

View File

@ -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.<ZKAuthInfo>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();
}
}