Package org.apache.zookeeper_voltpatches

Examples of org.apache.zookeeper_voltpatches.ZooKeeper


    int readDeploymentAndCreateStarterCatalogContext() {
        /*
         * Debate with the cluster what the deployment file should be
         */
        try {
            ZooKeeper zk = m_messenger.getZK();
            byte deploymentBytes[] = null;

            try {
                deploymentBytes = org.voltcore.utils.CoreUtils.urlToBytes(m_config.m_pathToDeployment);
            } catch (Exception ex) {
View Full Code Here


        String[] lines = pp.toLogLines().split("\n");
        for (String line : lines) {
            hostLog.info(line.trim());
        }

        final ZooKeeper zk = m_messenger.getZK();
        ZKUtil.ByteArrayCallback operationModeFuture = new ZKUtil.ByteArrayCallback();
        /*
         * Publish our cluster metadata, and then retrieve the metadata
         * for the rest of the cluster
         */
        try {
            zk.create(
                    VoltZK.cluster_metadata + "/" + m_messenger.getHostId(),
                    getLocalMetadata().getBytes("UTF-8"),
                    Ids.OPEN_ACL_UNSAFE,
                    CreateMode.EPHEMERAL,
                    new ZKUtil.StringCallback(),
                    null);
            zk.getData(VoltZK.operationMode, false, operationModeFuture, null);
        } catch (Exception e) {
            VoltDB.crashLocalVoltDB("Error creating \"/cluster_metadata\" node in ZK", true, e);
        }

        Map<Integer, String> clusterMetadata = new HashMap<Integer, String>(0);
        /*
         * Spin and attempt to retrieve cluster metadata for all nodes in the cluster.
         */
        Set<Integer> metadataToRetrieve = new HashSet<Integer>(m_messenger.getLiveHostIds());
        metadataToRetrieve.remove(m_messenger.getHostId());
        while (!metadataToRetrieve.isEmpty()) {
            Map<Integer, ZKUtil.ByteArrayCallback> callbacks = new HashMap<Integer, ZKUtil.ByteArrayCallback>();
            for (Integer hostId : metadataToRetrieve) {
                ZKUtil.ByteArrayCallback cb = new ZKUtil.ByteArrayCallback();
                zk.getData(VoltZK.cluster_metadata + "/" + hostId, false, cb, null);
                callbacks.put(hostId, cb);
            }

            for (Map.Entry<Integer, ZKUtil.ByteArrayCallback> entry : callbacks.entrySet()) {
                try {
View Full Code Here

                    " megabytes transferred at a rate of " +
                    megabytesPerSecond + " megabytes/sec");
        }

        try {
            final ZooKeeper zk = m_messenger.getZK();
            boolean logRecoveryCompleted = false;
            if (getCommandLog().getClass().getName().equals("org.voltdb.CommandLogImpl")) {
                String requestNode = zk.create(VoltZK.request_truncation_snapshot_node, null,
                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
                if (m_rejoinTruncationReqId == null) {
                    m_rejoinTruncationReqId = requestNode;
                }
            } else {
View Full Code Here

            }
            else {
                // If we saw some other truncation request ID, then try the same one again.  As long as we
                // don't flip the m_rejoining state, all truncation snapshot completions will call back to here.
                try {
                    final ZooKeeper zk = m_messenger.getZK();
                    String requestNode = zk.create(VoltZK.request_truncation_snapshot_node, null,
                            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
                    if (m_rejoinTruncationReqId == null) {
                        m_rejoinTruncationReqId = requestNode;
                    }
                }
View Full Code Here

                latestChildren.set(children);
                sem.release();
            }
        };

        ZooKeeper zk = getClient(0);
        zk.create("/babysitterroot", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        final String node6 = zk.create("/babysitterroot/6_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
        zk.create("/babysitterroot/7_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
        zk.create("/babysitterroot/10_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
        Pair<BabySitter, List<String>> pair = BabySitter.blockingFactory(zk, "/babysitterroot", cb);
        BabySitter bs = pair.getFirst();

        sem.acquire();
        assertEquals(Lists.newArrayList(6l, 7l, 10l), VoltZK.childrenToReplicaHSIds(latestChildren.get()));

        zk.delete(node6, -1);

        sem.acquire();
        assertEquals(Lists.newArrayList(7l, 10l), VoltZK.childrenToReplicaHSIds(latestChildren.get()));

        bs.shutdown();
View Full Code Here

    }

    @Test
    public void testInitialCache() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache01", zk);

        MapCache dut = new  MapCache(zk, "/cache01");
        dut.start(true);
        Map<String, JSONObject> cache = dut.pointInTimeCache();

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals("aaval", cache.get("/cache01/aa").get("key"));
        assertEquals("bbval", cache.get("/cache01/bb").get("key"));
        assertEquals("ccval", cache.get("/cache01/cc").get("key"));

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testInitialCacheWithCallback() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache01", zk);

        TestCallback cb = new TestCallback();
        MapCache dut = new  MapCache(zk, "/cache01", cb);
        dut.start(true);

        assertEquals("3 items cached.", 3, cb.m_cache.size());
        assertEquals("aaval", cb.m_cache.get("/cache01/aa").get("key"));
        assertEquals("bbval", cb.m_cache.get("/cache01/bb").get("key"));
        assertEquals("ccval", cb.m_cache.get("/cache01/cc").get("key"));

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testModifyChild() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache03", zk);

        MapCache dut = new  MapCache(zk, "/cache03");
        dut.start(true);
        Map<String, JSONObject> cache = dut.pointInTimeCache();

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals("aaval", cache.get("/cache03/aa").get("key"));

        JSONObject aa = new JSONObject("{key:aaval2}");
        zk.setData("/cache03/aa", aa.toString().getBytes(), -1);
        while(true) {
            cache = dut.pointInTimeCache();
            if (cache.get("/cache03/aa").get("key").equals("aaval2")) {
                break;
            }
        }
        assertEquals("3 items cached.", 3, cache.size());
        assertEquals("aaval2", cache.get("/cache03/aa").get("key"));
        assertEquals("bbval", cache.get("/cache03/bb").get("key"));
        assertEquals("ccval", cache.get("/cache03/cc").get("key"));

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testModifyChildWithCallback() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache03", zk);

        TestCallback cb = new TestCallback();
        MapCache dut = new  MapCache(zk, "/cache03", cb);
        dut.start(true);
        Map<String, JSONObject> cache = cb.m_cache;

        assertEquals("3 items cached.", 3, cache.size());
        assertEquals("aaval", cache.get("/cache03/aa").get("key"));

        JSONObject aa = new JSONObject("{key:aaval2}");
        zk.setData("/cache03/aa", aa.toString().getBytes(), -1);
        while(true) {
            cache = cb.m_cache;
            if (cache.get("/cache03/aa").get("key").equals("aaval2")) {
                break;
            }
        }
        assertEquals("3 items cached.", 3, cache.size());
        assertEquals("aaval2", cache.get("/cache03/aa").get("key"));
        assertEquals("bbval", cache.get("/cache03/bb").get("key"));
        assertEquals("ccval", cache.get("/cache03/cc").get("key"));

        dut.shutdown();
        zk.close();
    }
View Full Code Here

    }

    @Test
    public void testDeleteChild() throws Exception
    {
        ZooKeeper zk = getClient(0);
        configure("/cache02", zk);

        MapCache dut = new MapCache(zk, "/cache02");
        dut.start(true);
        Map<String, JSONObject> cache = dut.pointInTimeCache();
        assertEquals("3 items cached.", 3, cache.size());

        zk.delete("/cache02/bb", -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("/cache02/bb"));
        assertEquals("aaval", cache.get("/cache02/aa").get("key"));
        assertEquals("ccval", cache.get("/cache02/cc").get("key"));

        dut.shutdown();
        zk.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper_voltpatches.ZooKeeper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.