Search in sources :

Example 21 with KeeperException

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

the class ExportGeneration method createAndRegisterAckMailboxes.

private void createAndRegisterAckMailboxes(final Set<Integer> localPartitions, HostMessenger messenger) {
    m_mailboxesZKPath = VoltZK.exportGenerations + "/" + m_timestamp + "/" + "mailboxes";
    m_mbox = new LocalMailbox(messenger) {

        @Override
        public void deliver(VoltMessage message) {
            if (message instanceof BinaryPayloadMessage) {
                BinaryPayloadMessage bpm = (BinaryPayloadMessage) message;
                ByteBuffer buf = ByteBuffer.wrap(bpm.m_payload);
                final int partition = buf.getInt();
                final int length = buf.getInt();
                byte[] stringBytes = new byte[length];
                buf.get(stringBytes);
                String signature = new String(stringBytes, Constants.UTF8ENCODING);
                final long ackUSO = buf.getLong();
                final boolean runEveryWhere = (buf.getShort() == (short) 1);
                final Map<String, ExportDataSource> partitionSources = m_dataSourcesByPartition.get(partition);
                if (partitionSources == null) {
                    exportLog.error("Received an export ack for partition " + partition + " which does not exist on this node, partitions = " + m_dataSourcesByPartition);
                    return;
                }
                final ExportDataSource eds = partitionSources.get(signature);
                if (eds == null) {
                    exportLog.warn("Received an export ack for partition " + partition + " source signature " + signature + " which does not exist on this node, sources = " + partitionSources);
                    return;
                }
                try {
                    eds.ack(ackUSO, runEveryWhere);
                } catch (RejectedExecutionException ignoreIt) {
                // ignore it: as it is already shutdown
                }
            } else {
                exportLog.error("Receive unexpected message " + message + " in export subsystem");
            }
        }
    };
    messenger.createMailbox(null, m_mbox);
    for (Integer partition : localPartitions) {
        final String partitionDN = m_mailboxesZKPath + "/" + partition;
        ZKUtil.asyncMkdirs(messenger.getZK(), partitionDN);
        ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
        messenger.getZK().create(partitionDN + "/" + m_mbox.getHSId(), null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, cb, null);
    }
    ListenableFuture<?> fut = m_childUpdatingThread.submit(new Runnable() {

        @Override
        public void run() {
            List<Pair<Integer, ZKUtil.ChildrenCallback>> callbacks = new ArrayList<Pair<Integer, ZKUtil.ChildrenCallback>>();
            for (Integer partition : localPartitions) {
                ZKUtil.ChildrenCallback callback = new ZKUtil.ChildrenCallback();
                messenger.getZK().getChildren(m_mailboxesZKPath + "/" + partition, constructMailboxChildWatcher(messenger), callback, null);
                callbacks.add(Pair.of(partition, callback));
            }
            for (Pair<Integer, ZKUtil.ChildrenCallback> p : callbacks) {
                final Integer partition = p.getFirst();
                List<String> children = null;
                try {
                    children = p.getSecond().getChildren();
                } catch (InterruptedException e) {
                    Throwables.propagate(e);
                } catch (KeeperException e) {
                    Throwables.propagate(e);
                }
                ImmutableList.Builder<Long> mailboxes = ImmutableList.builder();
                for (String child : children) {
                    if (child.equals(Long.toString(m_mbox.getHSId())))
                        continue;
                    mailboxes.add(Long.valueOf(child));
                }
                ImmutableList<Long> mailboxHsids = mailboxes.build();
                for (ExportDataSource eds : m_dataSourcesByPartition.get(partition).values()) {
                    eds.updateAckMailboxes(Pair.of(m_mbox, mailboxHsids));
                }
            }
        }
    });
    try {
        fut.get();
    } catch (Throwable t) {
        Throwables.propagate(t);
    }
}
Also used : ImmutableList(com.google_voltpatches.common.collect.ImmutableList) BinaryPayloadMessage(org.voltcore.messaging.BinaryPayloadMessage) ZKUtil(org.voltcore.zk.ZKUtil) VoltMessage(org.voltcore.messaging.VoltMessage) LocalMailbox(org.voltdb.messaging.LocalMailbox) ImmutableList(com.google_voltpatches.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.voltcore.utils.Pair) ByteBuffer(java.nio.ByteBuffer) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) CatalogMap(org.voltdb.catalog.CatalogMap) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 22 with KeeperException

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

the class RealVoltDB method validateStartAction.

private void validateStartAction() {
    ZooKeeper zk = m_messenger.getZK();
    boolean initCompleted = false;
    List<String> children = null;
    try {
        initCompleted = zk.exists(VoltZK.init_completed, false) != null;
        children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
    } catch (KeeperException e) {
        hostLog.error("Failed to validate the start actions", e);
        return;
    } catch (InterruptedException e) {
        VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
    }
    if (children != null && !children.isEmpty()) {
        for (String child : children) {
            byte[] data = null;
            try {
                data = zk.getData(VoltZK.start_action + "/" + child, false, null);
            } catch (KeeperException excp) {
                if (excp.code() == Code.NONODE) {
                    hostLog.debug("Failed to validate the start action as node " + VoltZK.start_action + "/" + child + " got disconnected", excp);
                } else {
                    hostLog.error("Failed to validate the start actions ", excp);
                }
                return;
            } catch (InterruptedException e) {
                VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
            }
            if (data == null) {
                VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
            }
            String startAction = new String(data);
            if ((startAction.equals(StartAction.JOIN.toString()) || startAction.equals(StartAction.REJOIN.toString()) || startAction.equals(StartAction.LIVE_REJOIN.toString())) && !initCompleted) {
                int nodeId = VoltZK.getHostIDFromChildName(child);
                if (nodeId == m_messenger.getHostId()) {
                    VoltDB.crashLocalVoltDB("This node was started with start action " + startAction + " during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
                } else {
                    hostLog.warn("Node " + nodeId + " tried to " + startAction + " cluster but it is not allowed during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
                }
            }
        }
    }
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 23 with KeeperException

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

the class SnapshotSaveAPI method logParticipatingHostCount.

/**
     * Once participating host count is set, SnapshotCompletionMonitor can check this ZK node to
     * determine whether the snapshot has finished or not.
     *
     * This should only be called when all participants have responded. It is possible that some
     * hosts finish taking snapshot before the coordinator logs the participating host count. In
     * this case, the host count would have been decremented multiple times already. To make sure
     * finished hosts are logged correctly, this method adds participating host count + 1 to the
     * current host count.
     *
     * @param txnId The snapshot txnId
     * @param participantCount The number of hosts participating in this snapshot
     */
public static void logParticipatingHostCount(long txnId, int participantCount) {
    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);
        }
        success = true;
    }
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) JSONObject(org.json_voltpatches.JSONObject) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) JSONException(org.json_voltpatches.JSONException)

Example 24 with KeeperException

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

the class SnapshotDaemon method init.

public void init(DaemonInitiator initiator, HostMessenger messenger, Runnable threadLocalInit, GlobalServiceElector gse) {
    m_initiator = initiator;
    m_zk = messenger.getZK();
    m_mb = new SiteMailbox(messenger, messenger.getHSIdForLocalSite(HostMessenger.SNAPSHOT_DAEMON_ID));
    messenger.createMailbox(m_mb.getHSId(), m_mb);
    try {
        m_zk.create(VoltZK.nodes_currently_snapshotting, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (Exception e) {
    }
    try {
        m_zk.create(VoltZK.completed_snapshots, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (Exception e) {
    }
    if (threadLocalInit != null) {
        m_es.execute(threadLocalInit);
    }
    /*
         *  Really shouldn't leak this from a constructor, and twice to boot
         *  If IV2 is enabled leader election for the snapshot daemon is always tied to
         *  leader election for the MP coordinator so that they can't be partitioned
         *  from each other.
         */
    if (gse == null) {
        m_es.execute(new Runnable() {

            @Override
            public void run() {
                leaderElection();
            }
        });
    } else {
        gse.registerService(new Promotable() {

            @Override
            public void acceptPromotion() throws InterruptedException, ExecutionException, KeeperException {
                m_es.submit(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            m_isAutoSnapshotLeader = true;
                            if (m_lastKnownSchedule != null) {
                                makeActivePrivate(m_lastKnownSchedule);
                            }
                            electedTruncationLeader();
                        } catch (Exception e) {
                            VoltDB.crashLocalVoltDB("Exception in snapshot daemon electing master via ZK", true, e);
                        }
                    }
                });
            }
        });
    }
}
Also used : SiteMailbox(org.voltcore.messaging.SiteMailbox) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) NodeExistsException(org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) ExecutionException(java.util.concurrent.ExecutionException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 25 with KeeperException

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

the class MockVoltDB method validateStartAction.

public void validateStartAction() {
    try {
        ZooKeeper zk = m_hostMessenger.getZK();
        boolean initCompleted = zk.exists(VoltZK.init_completed, false) != null;
        List<String> children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
        if (!children.isEmpty()) {
            for (String child : children) {
                byte[] data = zk.getData(VoltZK.start_action + "/" + child, false, null);
                if (data == null) {
                    VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
                }
                String startAction = new String(data);
                if ((startAction.equals(StartAction.JOIN.toString()) || startAction.equals(StartAction.REJOIN.toString()) || startAction.equals(StartAction.LIVE_REJOIN.toString())) && !initCompleted) {
                    int nodeId = VoltZK.getHostIDFromChildName(child);
                    if (nodeId == m_hostMessenger.getHostId()) {
                        VoltDB.crashLocalVoltDB("This node was started with start action " + startAction + " during cluster creation. All nodes should be started with matching " + "create or recover actions when bring up a cluster. Join and Rejoin " + "are for adding nodes to an already running cluster.");
                    } else {
                        logger.warn("Node " + nodeId + " tried to " + startAction + " cluster but it is not allowed during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
                    }
                }
            }
        }
    } catch (KeeperException e) {
        logger.error("Failed to validate the start actions:" + e.getMessage());
    } catch (InterruptedException e) {
        VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
    }
}
Also used : ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper_voltpatches.KeeperException)25 Stat (org.apache.zookeeper_voltpatches.data.Stat)12 JSONException (org.json_voltpatches.JSONException)9 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)6 JSONObject (org.json_voltpatches.JSONObject)5 ByteBuffer (java.nio.ByteBuffer)4 List (java.util.List)4 Map (java.util.Map)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CreateTxn (org.apache.zookeeper_voltpatches.txn.CreateTxn)2 DeleteTxn (org.apache.zookeeper_voltpatches.txn.DeleteTxn)2 ErrorTxn (org.apache.zookeeper_voltpatches.txn.ErrorTxn)2 SetACLTxn (org.apache.zookeeper_voltpatches.txn.SetACLTxn)2 SetDataTxn (org.apache.zookeeper_voltpatches.txn.SetDataTxn)2