Search in sources :

Example 1 with BadVersionException

use of org.apache.zookeeper_voltpatches.KeeperException.BadVersionException in project voltdb by VoltDB.

the class TestZK method testDataWatches.

@Test
public void testDataWatches() throws Exception {
    ZooKeeper zk = getClient(0);
    ZooKeeper zk2 = getClient(1);
    final Semaphore sem = new Semaphore(0);
    zk2.create("/foo", new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.getData("/foo", new Watcher() {

        @Override
        public void process(WatchedEvent event) {
            if (event.getType() == EventType.NodeDataChanged) {
                sem.release();
                System.out.println(event);
            }
        }
    }, 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);
}
Also used : WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) Watcher(org.apache.zookeeper_voltpatches.Watcher) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 2 with BadVersionException

use of org.apache.zookeeper_voltpatches.KeeperException.BadVersionException in project voltdb by VoltDB.

the class Pause method run.

/**
     * Enter admin mode
     * @param ctx       Internal parameter. Not user-accessible.
     * @return          Standard STATUS table.
     */
public VoltTable[] run(SystemProcedureExecutionContext ctx) {
    if (ctx.isLowestSiteId()) {
        VoltDBInterface voltdb = VoltDB.instance();
        OperationMode opMode = voltdb.getMode();
        if (LOG.isDebugEnabled()) {
            LOG.debug("voltdb opmode is " + opMode);
        }
        ZooKeeper zk = voltdb.getHostMessenger().getZK();
        try {
            Stat stat;
            OperationMode zkMode = null;
            Code code;
            do {
                stat = new Stat();
                code = Code.BADVERSION;
                try {
                    byte[] data = zk.getData(VoltZK.operationMode, false, stat);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("zkMode is " + (zkMode == null ? "(null)" : OperationMode.valueOf(data)));
                    }
                    zkMode = data == null ? opMode : OperationMode.valueOf(data);
                    if (zkMode == PAUSED) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("read node at version " + stat.getVersion() + ", txn " + ll(stat.getMzxid()));
                        }
                        break;
                    }
                    stat = zk.setData(VoltZK.operationMode, PAUSED.getBytes(), stat.getVersion());
                    code = Code.OK;
                    zkMode = PAUSED;
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("!WROTE! node at version " + stat.getVersion() + ", txn " + ll(stat.getMzxid()));
                    }
                    break;
                } catch (BadVersionException ex) {
                    code = ex.code();
                }
            } while (zkMode != PAUSED && code == Code.BADVERSION);
            m_stat = stat;
            voltdb.getHostMessenger().pause();
            voltdb.setMode(PAUSED);
            // for snmp
            SnmpTrapSender snmp = voltdb.getSnmpTrapSender();
            if (snmp != null) {
                snmp.pause("Cluster paused.");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    // Force a tick so that stats will be updated.
    // Primarily added to get latest table stats for DR pause and empty db check.
    ctx.getSiteProcedureConnection().tick();
    VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
    t.addRow(VoltSystemProcedure.STATUS_OK);
    return (new VoltTable[] { t });
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) SnmpTrapSender(org.voltdb.snmp.SnmpTrapSender) OperationMode(org.voltdb.OperationMode) Code(org.apache.zookeeper_voltpatches.KeeperException.Code) VoltTable(org.voltdb.VoltTable) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)

Example 3 with BadVersionException

use of org.apache.zookeeper_voltpatches.KeeperException.BadVersionException in project voltdb by VoltDB.

the class Resume method run.

/**
     * Exit admin mode
     * @param ctx       Internal parameter. Not user-accessible.
     * @return          Standard STATUS table.
     */
public VoltTable[] run(SystemProcedureExecutionContext ctx) {
    // Choose the lowest site ID on this host to actually flip the bit
    VoltDBInterface voltdb = VoltDB.instance();
    OperationMode opMode = voltdb.getMode();
    if (ctx.isLowestSiteId()) {
        ZooKeeper zk = voltdb.getHostMessenger().getZK();
        try {
            Stat stat;
            OperationMode zkMode = null;
            Code code;
            do {
                stat = new Stat();
                code = Code.BADVERSION;
                try {
                    byte[] data = zk.getData(VoltZK.operationMode, false, stat);
                    zkMode = data == null ? opMode : OperationMode.valueOf(data);
                    if (zkMode == RUNNING) {
                        break;
                    }
                    stat = zk.setData(VoltZK.operationMode, RUNNING.getBytes(), stat.getVersion());
                    code = Code.OK;
                    zkMode = RUNNING;
                    break;
                } catch (BadVersionException ex) {
                    code = ex.code();
                }
            } while (zkMode != RUNNING && code == Code.BADVERSION);
            voltdb.getHostMessenger().unpause();
            voltdb.setMode(RUNNING);
            // for snmp
            SnmpTrapSender snmp = voltdb.getSnmpTrapSender();
            if (snmp != null) {
                snmp.resume("Cluster resumed.");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
    t.addRow(VoltSystemProcedure.STATUS_OK);
    return new VoltTable[] { t };
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) SnmpTrapSender(org.voltdb.snmp.SnmpTrapSender) OperationMode(org.voltdb.OperationMode) Code(org.apache.zookeeper_voltpatches.KeeperException.Code) VoltTable(org.voltdb.VoltTable) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)

Example 4 with BadVersionException

use of org.apache.zookeeper_voltpatches.KeeperException.BadVersionException in project voltdb by VoltDB.

the class TestZK method getThread.

private Thread getThread(final ZooKeeper zk, final int count) {
    return new Thread() {

        @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;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
}
Also used : Stat(org.apache.zookeeper_voltpatches.data.Stat) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) ByteBuffer(java.nio.ByteBuffer) NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)

Aggregations

BadVersionException (org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)4 Stat (org.apache.zookeeper_voltpatches.data.Stat)4 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)3 Code (org.apache.zookeeper_voltpatches.KeeperException.Code)2 OperationMode (org.voltdb.OperationMode)2 VoltDBInterface (org.voltdb.VoltDBInterface)2 VoltTable (org.voltdb.VoltTable)2 SnmpTrapSender (org.voltdb.snmp.SnmpTrapSender)2 ByteBuffer (java.nio.ByteBuffer)1 Semaphore (java.util.concurrent.Semaphore)1 NoNodeException (org.apache.zookeeper_voltpatches.KeeperException.NoNodeException)1 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)1 Watcher (org.apache.zookeeper_voltpatches.Watcher)1 Test (org.junit.Test)1