Search in sources :

Example 16 with Stat

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());
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL)

Example 17 with Stat

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 18 with Stat

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);
}
Also used : Stat(org.apache.zookeeper.data.Stat) Test(org.junit.Test)

Example 19 with Stat

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());
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 20 with Stat

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);
}
Also used : Stat(org.apache.zookeeper.data.Stat) Test(org.junit.Test)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27