Package org.apache.zookeeper_voltpatches.data

Examples of org.apache.zookeeper_voltpatches.data.Stat


        ZooKeeper zk = VoltDB.instance().getHostMessenger().getZK();
        final String snapshotPath = VoltZK.completed_snapshots + "/" + txnId;

        boolean success = false;
        while (!success) {
            Stat stat = new Stat();
            byte data[] = null;
            try {
                data = zk.getData(snapshotPath, false, stat);
            } catch (KeeperException e) {
                if (e.code() == KeeperException.Code.NONODE) {
                    // If snapshot creation failed for some reason, the node won't exist. ignore
                    return;
                }
                VoltDB.crashLocalVoltDB("Failed to get snapshot completion node", true, e);
            } catch (InterruptedException e) {
                VoltDB.crashLocalVoltDB("Interrupted getting snapshot completion node", true, e);
            }
            if (data == null) {
                VoltDB.crashLocalVoltDB("Data should not be null if the node exists", false, null);
            }

            try {
                JSONObject jsonObj = new JSONObject(new String(data, Charsets.UTF_8));
                if (jsonObj.getLong("txnId") != txnId) {
                    VoltDB.crashLocalVoltDB("TxnId should match", false, null);
                }

                int hostCount = jsonObj.getInt("hostCount");
                // +1 because hostCount was initialized to -1
                jsonObj.put("hostCount", hostCount + participantCount + 1);
                zk.setData(snapshotPath, jsonObj.toString(4).getBytes(Charsets.UTF_8),
                        stat.getVersion());
            } catch (KeeperException.BadVersionException e) {
                continue;
            } catch (Exception e) {
                VoltDB.crashLocalVoltDB("This ZK call should never fail", true, e);
            }
View Full Code Here


    public void testBasic() throws Exception {
        ZooKeeper zk = getClient(0);
        zk.create("/foo", new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        ZooKeeper zk2 = getClient(1);
        Stat stat = new Stat();
        assertEquals( 1, zk2.getData("/foo", false, stat).length);
        zk2.setData("/foo", new byte[4], stat.getVersion());

        assertEquals( 4, zk.getData("/foo", false, stat).length);
        zk.delete("/foo", -1);

        zk2.create("/bar", new byte[6], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
View Full Code Here

            }
        }, null);

        zk2.setData("/foo", new byte[2], -1);

        Stat stat = new Stat();
        zk.getData("/foo", false, stat);

        boolean threwException = false;
        try {
            zk2.setData("/foo", new byte[3], stat.getVersion());
            zk.setData("/foo", new byte[3], stat.getVersion());
        } catch (BadVersionException e) {
            threwException = true;
            e.printStackTrace();
        }
        assertTrue(threwException);
View Full Code Here

            @Override
            public void run() {
                try {
                    for (int ii = 0; ii < count; ii++) {
                        while (true) {
                            Stat stat = new Stat();
                            ByteBuffer buf = ByteBuffer.wrap(zk.getData("/foo", false, stat));
                            int value = buf.getInt();
                            value++;
                            buf.clear();
                            buf.putInt(value);
                            try {
                                zk.setData("/foo", buf.array(), stat.getVersion());
                            } catch (BadVersionException e) {
                                continue;
                            }
                            //System.out.println("CASed " + value);
                            break;
View Full Code Here

        while (!success) {
            if (System.currentTimeMillis() > endTime) {
                VoltDB.crashLocalVoltDB("Timed out logging snapshot completion to ZK");
            }

            Stat stat = new Stat();
            byte data[] = null;
            try {
                data = zk.getData(snapshotPath, false, stat);
            } catch (NoNodeException e) {
                // The MPI creates the snapshot completion node asynchronously,
                // if the node doesn't exist yet, retry
                continue;
            } catch (Exception e) {
                VoltDB.crashLocalVoltDB("This ZK get should never fail", true, e);
            }
            if (data == null) {
                VoltDB.crashLocalVoltDB("Data should not be null if the node exists", false, null);
            }

            try {
                JSONObject jsonObj = new JSONObject(new String(data, "UTF-8"));
                if (jsonObj.getLong("txnId") != txnId) {
                    VoltDB.crashLocalVoltDB("TxnId should match", false, null);
                }
                int remainingHosts = jsonObj.getInt("hostCount") - 1;
                jsonObj.put("hostCount", remainingHosts);
                jsonObj.put("didSucceed", snapshotSuccess);
                if (!snapshotSuccess) {
                    jsonObj.put("isTruncation", false);
                }
                mergeExportSequenceNumbers(jsonObj, exportSequenceNumbers);
                zk.setData(snapshotPath, jsonObj.toString(4).getBytes("UTF-8"), stat.getVersion());
            } catch (KeeperException.BadVersionException e) {
                continue;
            } catch (Exception e) {
                VoltDB.crashLocalVoltDB("This ZK call should never fail", true, e);
            }
View Full Code Here

        }
    };

    private List<String> watch() throws InterruptedException, KeeperException
    {
        Stat stat = new Stat();
        List<String> zkchildren = m_zk.getChildren(m_dir, m_watcher, stat);
        // Sort on the ephemeral sequential part, the prefix is not padded, so string sort doesn't work
        Collections.sort(zkchildren, new Comparator<String>() {
            @Override
            public int compare(String left, String right)
View Full Code Here

        countDown(false);
    }

    public void countDown(boolean expectNonZeroCount) throws InterruptedException, KeeperException {
        while (true) {
            Stat stat = new Stat();
            ByteBuffer buf = ByteBuffer.wrap(m_zk.getData(m_path, false, stat));
            int count = buf.getInt();
            if (count == 0) {
                countedDown = true;
                if (expectNonZeroCount) {
                    throw new RuntimeException("Count should be > 0");
                }
                return;
            }

            count--;

            //Save a few milliseconds
            if (count == 0) countedDown = true;

            buf.clear();
            buf.putInt(count);
            try {
                m_zk.setData(m_path, buf.array(), stat.getVersion());
            } catch (KeeperException.BadVersionException e) {
                continue;
            }
            return;
        }
View Full Code Here

                VoltDB.crashLocalVoltDB(clusterConfig.getErrorMsg(), false, null);
            }
            topo = registerClusterConfig(clusterConfig);
        }
        else {
            Stat stat = new Stat();
            try {
                topo =
                    new JSONObject(new String(m_messenger.getZK().getData(VoltZK.topology, false, stat), "UTF-8"));
            }
            catch (Exception e) {
View Full Code Here

     */
    private void leaderElection() {
        loggingLog.info("Starting leader election for snapshot truncation daemon");
        try {
            while (true) {
                Stat stat = m_zk.exists(VoltZK.snapshot_truncation_master, new Watcher() {
                    @Override
                    public void process(WatchedEvent event) {
                        switch(event.getType()) {
                        case NodeDeleted:
                            loggingLog.info("Detected the snapshot truncation leader's ephemeral node deletion");
View Full Code Here

            final String requestId,
            final long clientHandle,
            final Connection c,
            final boolean notifyChanges) throws Exception {
        final String responseNode = VoltZK.user_snapshot_response + requestId;
        Stat exists = m_zk.exists(responseNode, new Watcher() {
            @Override
            public void process(final WatchedEvent event) {
                if (event.getState() == KeeperState.Disconnected) return;
                switch (event.getType()) {
                case NodeCreated:
View Full Code Here

TOP

Related Classes of org.apache.zookeeper_voltpatches.data.Stat

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.