Search in sources :

Example 1 with ServiceLock

use of org.apache.accumulo.fate.zookeeper.ServiceLock in project accumulo by apache.

the class ServiceLockIT method testDeleteWaiting.

@Test(timeout = 15000)
public void testDeleteWaiting() throws Exception {
    var parent = ServiceLock.path("/zltestDeleteWaiting-" + this.hashCode() + "-l" + pdCount.incrementAndGet());
    ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, "secret");
    zk.mkdirs(parent.toString());
    ServiceLock zl = getZooLock(parent, UUID.randomUUID());
    assertFalse(zl.isLocked());
    TestALW lw = new TestALW();
    zl.lock(lw, "test1".getBytes(UTF_8));
    lw.waitForChanges(1);
    assertTrue(lw.locked);
    assertTrue(zl.isLocked());
    assertNull(lw.exception);
    assertNull(lw.reason);
    ServiceLock zl2 = getZooLock(parent, UUID.randomUUID());
    TestALW lw2 = new TestALW();
    zl2.lock(lw2, "test2".getBytes(UTF_8));
    assertFalse(lw2.locked);
    assertFalse(zl2.isLocked());
    ServiceLock zl3 = getZooLock(parent, UUID.randomUUID());
    TestALW lw3 = new TestALW();
    zl3.lock(lw3, "test3".getBytes(UTF_8));
    List<String> children = ServiceLock.validateAndSort(parent, zk.getChildren(parent.toString()));
    zk.delete(parent + "/" + children.get(1));
    lw2.waitForChanges(1);
    assertFalse(lw2.locked);
    assertNotNull(lw2.exception);
    assertNull(lw2.reason);
    zk.delete(parent + "/" + children.get(0));
    lw.waitForChanges(2);
    assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
    assertNull(lw.exception);
    lw3.waitForChanges(1);
    assertTrue(lw3.locked);
    assertTrue(zl3.isLocked());
    assertNull(lw3.exception);
    assertNull(lw3.reason);
    zl3.unlock();
}
Also used : ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Test(org.junit.Test)

Example 2 with ServiceLock

use of org.apache.accumulo.fate.zookeeper.ServiceLock in project accumulo by apache.

the class ServiceLockIT method testDeleteParent.

@Test(timeout = 10000)
public void testDeleteParent() throws Exception {
    var parent = ServiceLock.path("/zltestDeleteParent-" + this.hashCode() + "-l" + pdCount.incrementAndGet());
    ServiceLock zl = getZooLock(parent, UUID.randomUUID());
    assertFalse(zl.isLocked());
    ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, "secret");
    // intentionally created parent after lock
    zk.mkdirs(parent.toString());
    zk.delete(parent.toString());
    zk.mkdirs(parent.toString());
    TestALW lw = new TestALW();
    zl.lock(lw, "test1".getBytes(UTF_8));
    lw.waitForChanges(1);
    assertTrue(lw.locked);
    assertTrue(zl.isLocked());
    assertNull(lw.exception);
    assertNull(lw.reason);
    zl.unlock();
}
Also used : ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Test(org.junit.Test)

Example 3 with ServiceLock

use of org.apache.accumulo.fate.zookeeper.ServiceLock in project accumulo by apache.

the class ServiceLockIT method testChangeData.

@Test(timeout = 10000)
public void testChangeData() throws Exception {
    var parent = ServiceLock.path("/zltestChangeData-" + this.hashCode() + "-l" + pdCount.incrementAndGet());
    ConnectedWatcher watcher = new ConnectedWatcher();
    try (ZooKeeper zk = new ZooKeeper(szk.getConn(), 30000, watcher)) {
        ZooUtil.digestAuth(zk, "secret");
        while (!watcher.isConnected()) {
            Thread.sleep(200);
        }
        zk.create(parent.toString(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        ServiceLock zl = getZooLock(parent, UUID.randomUUID());
        TestALW lw = new TestALW();
        zl.lock(lw, "test1".getBytes(UTF_8));
        assertEquals("test1", new String(zk.getData(zl.getLockPath(), null, null)));
        zl.replaceLockData("test2".getBytes(UTF_8));
        assertEquals("test2", new String(zk.getData(zl.getLockPath(), null, null)));
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) Test(org.junit.Test)

Example 4 with ServiceLock

use of org.apache.accumulo.fate.zookeeper.ServiceLock in project accumulo by apache.

the class ServiceLockIT method testUnexpectedEvent.

@Test(timeout = 10000)
public void testUnexpectedEvent() throws Exception {
    var parent = ServiceLock.path("/zltestUnexpectedEvent-" + this.hashCode() + "-l" + pdCount.incrementAndGet());
    ConnectedWatcher watcher = new ConnectedWatcher();
    try (ZooKeeper zk = new ZooKeeper(szk.getConn(), 30000, watcher)) {
        ZooUtil.digestAuth(zk, "secret");
        while (!watcher.isConnected()) {
            Thread.sleep(200);
        }
        zk.create(parent.toString(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        ServiceLock zl = getZooLock(parent, UUID.randomUUID());
        assertFalse(zl.isLocked());
        // would not expect data to be set on this node, but it should not cause problems.....
        zk.setData(parent.toString(), "foo".getBytes(UTF_8), -1);
        TestALW lw = new TestALW();
        zl.lock(lw, "test1".getBytes(UTF_8));
        lw.waitForChanges(1);
        assertTrue(lw.locked);
        assertTrue(zl.isLocked());
        assertNull(lw.exception);
        assertNull(lw.reason);
        // would not expect data to be set on this node either
        zk.setData(zl.getLockPath(), "bar".getBytes(UTF_8), -1);
        zk.delete(zl.getLockPath(), -1);
        lw.waitForChanges(2);
        assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
        assertNull(lw.exception);
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) Test(org.junit.Test)

Example 5 with ServiceLock

use of org.apache.accumulo.fate.zookeeper.ServiceLock in project accumulo by apache.

the class SplitRecoveryIT method run.

private void run(ServerContext c) throws Exception {
    var zPath = ServiceLock.path(c.getZooKeeperRoot() + "/testLock");
    ZooReaderWriter zoo = c.getZooReaderWriter();
    zoo.putPersistentData(zPath.toString(), new byte[0], NodeExistsPolicy.OVERWRITE);
    ServiceLock zl = new ServiceLock(zoo.getZooKeeper(), zPath, UUID.randomUUID());
    boolean gotLock = zl.tryLock(new LockWatcher() {

        @SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
        @Override
        public void lostLock(LockLossReason reason) {
            System.exit(-1);
        }

        @SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
        @Override
        public void unableToMonitorLockNode(Exception e) {
            System.exit(-1);
        }
    }, "foo".getBytes(UTF_8));
    if (!gotLock) {
        System.err.println("Failed to get lock " + zPath);
    }
    // run test for a table with one tablet
    runSplitRecoveryTest(c, 0, "sp", 0, zl, nke("foo0", null, null));
    runSplitRecoveryTest(c, 1, "sp", 0, zl, nke("foo1", null, null));
    // run test for tables with two tablets, run test on first and last tablet
    runSplitRecoveryTest(c, 0, "k", 0, zl, nke("foo2", "m", null), nke("foo2", null, "m"));
    runSplitRecoveryTest(c, 1, "k", 0, zl, nke("foo3", "m", null), nke("foo3", null, "m"));
    runSplitRecoveryTest(c, 0, "o", 1, zl, nke("foo4", "m", null), nke("foo4", null, "m"));
    runSplitRecoveryTest(c, 1, "o", 1, zl, nke("foo5", "m", null), nke("foo5", null, "m"));
    // run test for table w/ three tablets, run test on middle tablet
    runSplitRecoveryTest(c, 0, "o", 1, zl, nke("foo6", "m", null), nke("foo6", "r", "m"), nke("foo6", null, "r"));
    runSplitRecoveryTest(c, 1, "o", 1, zl, nke("foo7", "m", null), nke("foo7", "r", "m"), nke("foo7", null, "r"));
    // run test for table w/ three tablets, run test on first
    runSplitRecoveryTest(c, 0, "g", 0, zl, nke("foo8", "m", null), nke("foo8", "r", "m"), nke("foo8", null, "r"));
    runSplitRecoveryTest(c, 1, "g", 0, zl, nke("foo9", "m", null), nke("foo9", "r", "m"), nke("foo9", null, "r"));
    // run test for table w/ three tablets, run test on last tablet
    runSplitRecoveryTest(c, 0, "w", 2, zl, nke("fooa", "m", null), nke("fooa", "r", "m"), nke("fooa", null, "r"));
    runSplitRecoveryTest(c, 1, "w", 2, zl, nke("foob", "m", null), nke("foob", "r", "m"), nke("foob", null, "r"));
}
Also used : ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) LockWatcher(org.apache.accumulo.fate.zookeeper.ServiceLock.LockWatcher) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) LockLossReason(org.apache.accumulo.fate.zookeeper.ServiceLock.LockLossReason)

Aggregations

ServiceLock (org.apache.accumulo.fate.zookeeper.ServiceLock)16 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)8 Test (org.junit.Test)8 LockLossReason (org.apache.accumulo.fate.zookeeper.ServiceLock.LockLossReason)5 LockWatcher (org.apache.accumulo.fate.zookeeper.ServiceLock.LockWatcher)5 UUID (java.util.UUID)4 ServerServices (org.apache.accumulo.core.util.ServerServices)4 IOException (java.io.IOException)3 KeeperException (org.apache.zookeeper.KeeperException)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 UnknownHostException (java.net.UnknownHostException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 ServerContext (org.apache.accumulo.server.ServerContext)2 TException (org.apache.thrift.TException)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 FileNotFoundException (java.io.FileNotFoundException)1 Field (java.lang.reflect.Field)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1