use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ZKRMStateStore method logRootNodeAcls.
private void logRootNodeAcls(String prefix) throws Exception {
Stat getStat = new Stat();
List<ACL> getAcls = getACL(zkRootNodePath);
StringBuilder builder = new StringBuilder();
builder.append(prefix);
for (ACL acl : getAcls) {
builder.append(acl.toString());
}
builder.append(getStat.toString());
LOG.debug(builder.toString());
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ActiveStandbyElectorTestUtil method waitForActiveLockData.
public static void waitForActiveLockData(TestContext ctx, ZooKeeperServer zks, String parentDir, byte[] activeData) throws Exception {
long st = Time.now();
long lastPrint = st;
while (true) {
if (ctx != null) {
ctx.checkException();
}
try {
Stat stat = new Stat();
byte[] data = zks.getZKDatabase().getData(parentDir + "/" + ActiveStandbyElector.LOCK_FILENAME, stat, null);
if (activeData != null && Arrays.equals(activeData, data)) {
return;
}
if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
LOG.info("Cur data: " + StringUtils.byteToHexString(data));
lastPrint = Time.now();
}
} catch (NoNodeException nne) {
if (activeData == null) {
return;
}
if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
LOG.info("Cur data: no node");
lastPrint = Time.now();
}
}
Thread.sleep(50);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class TestActiveStandbyElector method testCreateNodeResultRetryBecomeStandby.
/**
* verify that retry of network errors verifies active by session id and
* becomes standby if they dont match. monitoring is started.
*/
@Test
public void testCreateNodeResultRetryBecomeStandby() {
elector.joinElection(data);
elector.processResult(Code.CONNECTIONLOSS.intValue(), ZK_LOCK_NAME, mockZK, ZK_LOCK_NAME);
elector.processResult(Code.NODEEXISTS.intValue(), ZK_LOCK_NAME, mockZK, ZK_LOCK_NAME);
verifyExistCall(1);
Stat stat = new Stat();
stat.setEphemeralOwner(0);
Mockito.when(mockZK.getSessionId()).thenReturn(1L);
elector.processResult(Code.OK.intValue(), ZK_LOCK_NAME, mockZK, stat);
Mockito.verify(mockApp, Mockito.times(1)).becomeStandby();
verifyExistCall(1);
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class TestActiveStandbyElector method testParentZNodeACLs.
/**
* Test that ACLs are set on parent zNode even if the node already exists.
*/
@Test
public void testParentZNodeACLs() throws Exception {
KeeperException ke = new KeeperException(Code.NODEEXISTS) {
@Override
public Code code() {
return super.code();
}
};
Mockito.when(mockZK.create(Mockito.anyString(), Mockito.eq(new byte[] {}), Mockito.anyListOf(ACL.class), Mockito.eq(CreateMode.PERSISTENT))).thenThrow(ke);
elector.ensureParentZNode();
StringBuilder prefix = new StringBuilder();
for (String part : ZK_PARENT_NAME.split("/")) {
if (part.isEmpty())
continue;
prefix.append("/").append(part);
if (!"/".equals(prefix.toString())) {
Mockito.verify(mockZK).getACL(Mockito.eq(prefix.toString()), Mockito.eq(new Stat()));
Mockito.verify(mockZK).setACL(Mockito.eq(prefix.toString()), Mockito.eq(Ids.OPEN_ACL_UNSAFE), Mockito.anyInt());
}
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class TestActiveStandbyElector method testCreateNodeResultBecomeActive.
/**
* verify that successful znode create result becomes active and monitoring is
* started
*/
@Test
public void testCreateNodeResultBecomeActive() throws Exception {
mockNoPriorActive();
elector.joinElection(data);
elector.processResult(Code.OK.intValue(), ZK_LOCK_NAME, mockZK, ZK_LOCK_NAME);
Mockito.verify(mockApp, Mockito.times(1)).becomeActive();
verifyExistCall(1);
// monitor callback verifies the leader is ephemeral owner of lock but does
// not call becomeActive since its already active
Stat stat = new Stat();
stat.setEphemeralOwner(1L);
Mockito.when(mockZK.getSessionId()).thenReturn(1L);
elector.processResult(Code.OK.intValue(), ZK_LOCK_NAME, mockZK, stat);
// should not call neutral mode/standby/active
Mockito.verify(mockApp, Mockito.times(0)).enterNeutralMode();
Mockito.verify(mockApp, Mockito.times(0)).becomeStandby();
Mockito.verify(mockApp, Mockito.times(1)).becomeActive();
// another joinElection not called.
Mockito.verify(mockZK, Mockito.times(1)).create(ZK_LOCK_NAME, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, elector, mockZK);
// no new monitor called
verifyExistCall(1);
}
Aggregations