Search in sources :

Example 6 with KeeperException

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

the class LeaderCache method processChildEvent.

/**
     * Update a modified child and republish a new snapshot. This may indicate
     * a deleted child or a child with modified data.
     */
private void processChildEvent(WatchedEvent event) throws Exception {
    HashMap<Integer, Long> cacheCopy = new HashMap<Integer, Long>(m_publicCache);
    ByteArrayCallback cb = new ByteArrayCallback();
    m_zk.getData(event.getPath(), m_childWatch, cb, null);
    try {
        // cb.getData() and cb.getPath() throw KeeperException
        byte[] payload = cb.getData();
        long HSId = Long.valueOf(new String(payload, "UTF-8"));
        cacheCopy.put(getPartitionIdFromZKPath(cb.getPath()), HSId);
    } catch (KeeperException.NoNodeException e) {
        // rtb: I think result's path is the same as cb.getPath()?
        cacheCopy.remove(getPartitionIdFromZKPath(event.getPath()));
    }
    m_publicCache = ImmutableMap.copyOf(cacheCopy);
    if (m_cb != null) {
        m_cb.run(m_publicCache);
    }
}
Also used : ByteArrayCallback(org.voltcore.zk.ZKUtil.ByteArrayCallback) HashMap(java.util.HashMap) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 7 with KeeperException

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

the class ClusterSettingsRef method store.

public int store(ZooKeeper zk) {
    Stat stat = null;
    int[] stamp = new int[] { 0 };
    ClusterSettings settings = get(stamp);
    try {
        // at this stage zookeeper is one version behind
        stat = zk.setData(VoltZK.cluster_settings, settings.asBytes(), stamp[0] - 1);
    } catch (KeeperException | InterruptedException e) {
        throw new SettingsException("Failed to store to ZooKeeper", e);
    }
    return stat.getVersion();
}
Also used : Stat(org.apache.zookeeper_voltpatches.data.Stat) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 8 with KeeperException

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

the class TopologyZKUtils method updateTopologyToZK.

public static void updateTopologyToZK(ZooKeeper zk, AbstractTopology topology) {
    Stat stat = new Stat();
    try {
        zk.getData(VoltZK.topology, false, stat);
        byte[] payload = topology.topologyToJSON().toString().getBytes(Charsets.UTF_8);
        zk.setData(VoltZK.topology, payload, stat.getVersion());
    } catch (KeeperException | InterruptedException | JSONException e) {
        VoltDB.crashLocalVoltDB("Unable to update topology to ZK, dying", true, e);
    }
}
Also used : Stat(org.apache.zookeeper_voltpatches.data.Stat) JSONException(org.json_voltpatches.JSONException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 9 with KeeperException

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

the class MeshProber method considerMeshPlea.

@Override
public JoinAcceptor.PleaDecision considerMeshPlea(ZooKeeper zk, int hostId, JSONObject jo) {
    checkArgument(zk != null, "zookeeper is null");
    checkArgument(jo != null, "json object is null");
    if (!HostCriteria.hasCriteria(jo)) {
        return new JoinAcceptor.PleaDecision(String.format("Joining node version %s is incompatible with this node verion %s", jo.optString(SocketJoiner.VERSION_STRING, "(unknown)"), m_versionChecker.getVersionString()), false, false);
    }
    HostCriteria hc = new HostCriteria(jo);
    Map<Integer, HostCriteria> hostCriteria = m_hostCriteria.get();
    // when the cluster is forming anew)
    if (!getNodeState().operational() && !hostCriteria.values().stream().anyMatch(c -> c.getNodeState().operational())) {
        List<String> incompatibilities = asHostCriteria().listIncompatibilities(hc);
        if (!incompatibilities.isEmpty()) {
            Joiner joiner = Joiner.on("\n    ").skipNulls();
            String error = "Incompatible joining criteria:\n    " + joiner.join(incompatibilities);
            return new JoinAcceptor.PleaDecision(error, false, false);
        }
        return new JoinAcceptor.PleaDecision(null, true, false);
    } else {
        StartAction operationalStartAction = hostCriteria.values().stream().filter(c -> c.getNodeState().operational()).map(c -> c.getStartAction()).findFirst().orElse(getStartAction());
        if (operationalStartAction == StartAction.PROBE && hc.getStartAction() != StartAction.PROBE) {
            String msg = "Invalid VoltDB command. Please use init and start to join this cluster";
            return new JoinAcceptor.PleaDecision(msg, false, false);
        }
    }
    // how many hosts are already in the mesh?
    Stat stat = new Stat();
    try {
        zk.getChildren(CoreZK.hosts, false, stat);
    } catch (InterruptedException e) {
        String msg = "Interrupted while considering mesh plea";
        m_networkLog.error(msg, e);
        return new JoinAcceptor.PleaDecision(msg, false, false);
    } catch (KeeperException e) {
        EnumSet<KeeperException.Code> closing = EnumSet.of(KeeperException.Code.SESSIONEXPIRED, KeeperException.Code.CONNECTIONLOSS);
        if (closing.contains(e.code())) {
            return new JoinAcceptor.PleaDecision("Shutting down", false, false);
        } else {
            String msg = "Failed to list hosts while considering a mesh plea";
            m_networkLog.error(msg, e);
            return new JoinAcceptor.PleaDecision(msg, false, false);
        }
    }
    // connecting to already wholly formed cluster
    if (stat.getNumChildren() >= getHostCount()) {
        return new JoinAcceptor.PleaDecision(hc.isAddAllowed() ? null : "Cluster is already complete", hc.isAddAllowed(), false);
    } else if (stat.getNumChildren() < getHostCount()) {
        // check for concurrent rejoins
        final int rejoiningHost = CoreZK.createRejoinNodeIndicator(zk, hostId);
        if (rejoiningHost == -1) {
            return new JoinAcceptor.PleaDecision(null, true, false);
        } else {
            String msg = "Only one host can rejoin at a time. Host " + rejoiningHost + " is still rejoining.";
            return new JoinAcceptor.PleaDecision(msg, false, true);
        }
    }
    return new JoinAcceptor.PleaDecision(null, true, false);
}
Also used : ImmutableSortedSet(com.google_voltpatches.common.collect.ImmutableSortedSet) Arrays(java.util.Arrays) Supplier(com.google_voltpatches.common.base.Supplier) Preconditions.checkArgument(com.google_voltpatches.common.base.Preconditions.checkArgument) CoreZK(org.voltcore.zk.CoreZK) NodeState(org.voltdb.common.NodeState) SettableFuture(com.google_voltpatches.common.util.concurrent.SettableFuture) VersionChecker(org.voltcore.utils.VersionChecker) Predicates.not(com.google_voltpatches.common.base.Predicates.not) JoinAcceptor(org.voltcore.messaging.JoinAcceptor) InetAddresses(com.google_voltpatches.common.net.InetAddresses) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeSet(java.util.TreeSet) InetAddress(java.net.InetAddress) Generated(javax.annotation.Generated) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) Predicate(com.google_voltpatches.common.base.Predicate) HostAndPort(com.google_voltpatches.common.net.HostAndPort) Map(java.util.Map) JSONObject(org.json_voltpatches.JSONObject) Predicates.equalTo(com.google_voltpatches.common.base.Predicates.equalTo) Constants(org.voltcore.common.Constants) Joiner(com.google_voltpatches.common.base.Joiner) JSONWriter(org.json_voltpatches.JSONWriter) StartAction(org.voltdb.StartAction) EnumSet(java.util.EnumSet) VoltLogger(org.voltcore.logging.VoltLogger) Maps(com.google_voltpatches.common.collect.Maps) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Set(java.util.Set) NavigableSet(java.util.NavigableSet) UUID(java.util.UUID) MiscUtils(org.voltdb.utils.MiscUtils) Suppliers(com.google_voltpatches.common.base.Suppliers) JSONException(org.json_voltpatches.JSONException) SocketJoiner(org.voltcore.messaging.SocketJoiner) Throwables(com.google_voltpatches.common.base.Throwables) ExecutionException(java.util.concurrent.ExecutionException) JSONStringer(org.json_voltpatches.JSONStringer) List(java.util.List) HostMessenger(org.voltcore.messaging.HostMessenger) Stat(org.apache.zookeeper_voltpatches.data.Stat) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) InternetDomainName(com.google_voltpatches.common.net.InternetDomainName) Preconditions.checkNotNull(com.google_voltpatches.common.base.Preconditions.checkNotNull) Digester(org.voltdb.utils.Digester) Optional(java.util.Optional) Splitter(com.google_voltpatches.common.base.Splitter) Joiner(com.google_voltpatches.common.base.Joiner) SocketJoiner(org.voltcore.messaging.SocketJoiner) JoinAcceptor(org.voltcore.messaging.JoinAcceptor) EnumSet(java.util.EnumSet) StartAction(org.voltdb.StartAction) Stat(org.apache.zookeeper_voltpatches.data.Stat) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 10 with KeeperException

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

the class DataTree method processTxn.

public ProcessTxnResult processTxn(TxnHeader header, Record txn) {
    ProcessTxnResult rc = new ProcessTxnResult();
    String debug = "";
    try {
        rc.clientId = header.getClientId();
        rc.cxid = header.getCxid();
        rc.zxid = header.getZxid();
        rc.type = header.getType();
        rc.err = 0;
        if (rc.zxid > lastProcessedZxid) {
            lastProcessedZxid = rc.zxid;
        }
        switch(header.getType()) {
            case OpCode.create:
                CreateTxn createTxn = (CreateTxn) txn;
                debug = "Create transaction for " + createTxn.getPath();
                createNode(createTxn.getPath(), createTxn.getData(), createTxn.getAcl(), createTxn.getEphemeral() ? header.getClientId() : 0, header.getZxid(), header.getTime());
                rc.path = createTxn.getPath();
                break;
            case OpCode.delete:
                DeleteTxn deleteTxn = (DeleteTxn) txn;
                debug = "Delete transaction for " + deleteTxn.getPath();
                deleteNode(deleteTxn.getPath(), header.getZxid());
                break;
            case OpCode.setData:
                SetDataTxn setDataTxn = (SetDataTxn) txn;
                debug = "Set data for  transaction for " + setDataTxn.getPath();
                rc.stat = setData(setDataTxn.getPath(), setDataTxn.getData(), setDataTxn.getVersion(), header.getZxid(), header.getTime());
                break;
            case OpCode.setACL:
                SetACLTxn setACLTxn = (SetACLTxn) txn;
                debug = "Set ACL for  transaction for " + setACLTxn.getPath();
                rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(), setACLTxn.getVersion());
                break;
            case OpCode.closeSession:
                killSession(header.getClientId(), header.getZxid());
                break;
            case OpCode.error:
                ErrorTxn errTxn = (ErrorTxn) txn;
                rc.err = errTxn.getErr();
                break;
        }
    } catch (KeeperException e) {
        // These are expected errors since we take a lazy snapshot
        if (initialized || (e.code() != Code.NONODE && e.code() != Code.NODEEXISTS)) {
            LOG.warn("Failed:" + debug, e);
        }
    }
    return rc;
}
Also used : CreateTxn(org.apache.zookeeper_voltpatches.txn.CreateTxn) ErrorTxn(org.apache.zookeeper_voltpatches.txn.ErrorTxn) SetACLTxn(org.apache.zookeeper_voltpatches.txn.SetACLTxn) SetDataTxn(org.apache.zookeeper_voltpatches.txn.SetDataTxn) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) DeleteTxn(org.apache.zookeeper_voltpatches.txn.DeleteTxn)

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