Search in sources :

Example 61 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class TestLeaderCache method testDeleteChild.

@Test
public void testDeleteChild() throws Exception {
    ZooKeeper zk = getClient(0);
    configure("/cache02", zk);
    LeaderCache dut = new LeaderCache(zk, "/cache02");
    dut.start(true);
    Map<Integer, Long> cache = dut.pointInTimeCache();
    assertEquals("3 items cached.", 3, cache.size());
    zk.delete("/cache02/1", -1);
    while (true) {
        cache = dut.pointInTimeCache();
        if (cache.size() == 3) {
            Thread.sleep(1);
        } else {
            break;
        }
    }
    assertEquals("Item removed", 2, cache.size());
    assertEquals(null, cache.get(1));
    assertEquals(12345678, cache.get(0).longValue());
    assertEquals(11223344, cache.get(2).longValue());
    dut.shutdown();
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Test(org.junit.Test)

Example 62 with ZooKeeper

use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.

the class ElasticJoinProducer method fetchPerPartitionTxnId.

/*
     * Inherit the per partition txnid from the long since gone
     * partition that existed in the past
     */
private long[] fetchPerPartitionTxnId() {
    ZooKeeper zk = VoltDB.instance().getHostMessenger().getZK();
    byte[] partitionTxnIdsBytes = null;
    try {
        partitionTxnIdsBytes = zk.getData(VoltZK.perPartitionTxnIds, false, null);
    }//Can be no node if the cluster was never restored
     catch (KeeperException.NoNodeException e) {
        return null;
    } catch (Exception e) {
        VoltDB.crashLocalVoltDB("Error retrieving per partition txn ids", true, e);
    }
    ByteBuffer buf = ByteBuffer.wrap(partitionTxnIdsBytes);
    int count = buf.getInt();
    Long partitionTxnId = null;
    long[] partitionTxnIds = new long[count];
    for (int ii = 0; ii < count; ii++) {
        long txnId = buf.getLong();
        partitionTxnIds[ii] = txnId;
        int partitionId = TxnEgo.getPartitionId(txnId);
        if (partitionId == m_partitionId) {
            partitionTxnId = txnId;
            continue;
        }
    }
    if (partitionTxnId != null) {
        return partitionTxnIds;
    }
    return null;
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) ByteBuffer(java.nio.ByteBuffer) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Aggregations

ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)62 Test (org.junit.Test)38 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)14 JSONObject (org.json_voltpatches.JSONObject)14 Semaphore (java.util.concurrent.Semaphore)11 Stat (org.apache.zookeeper_voltpatches.data.Stat)10 ExecutionException (java.util.concurrent.ExecutionException)8 HostMessenger (org.voltcore.messaging.HostMessenger)8 IOException (java.io.IOException)7 JSONException (org.json_voltpatches.JSONException)7 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)5 Watcher (org.apache.zookeeper_voltpatches.Watcher)5 VoltTable (org.voltdb.VoltTable)5 SettingsException (org.voltdb.settings.SettingsException)5 List (java.util.List)4 Map (java.util.Map)4 HostAndPort (com.google_voltpatches.common.net.HostAndPort)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SocketException (java.net.SocketException)3 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)2