Search in sources :

Example 1 with StartAction

use of org.voltdb.StartAction in project voltdb by VoltDB.

the class ZKTestBase method setUpZK.

protected void setUpZK(int sites) throws Exception {
    m_siteIdToZKPort = new TreeMap<Integer, Integer>();
    m_clients = new ArrayList<ZooKeeper>();
    m_messengers = new ArrayList<HostMessenger>();
    String[] coordinators = IntStream.range(0, sites).mapToObj(i -> ":" + (i + Constants.DEFAULT_INTERNAL_PORT)).toArray(s -> new String[s]);
    for (int ii = 0; ii < sites; ii++) {
        HostMessenger.Config config = new HostMessenger.Config();
        config.internalPort += ii;
        config.acceptor = MeshProber.builder().coordinators(coordinators).startAction(StartAction.PROBE).hostCount(sites).build();
        int externalPort = m_ports.next();
        config.zkInterface = "127.0.0.1:" + externalPort;
        m_siteIdToZKPort.put(ii, externalPort);
        config.networkThreads = 1;
        HostMessenger hm = new HostMessenger(config, null);
        hm.start();
        m_messengers.add(hm);
    }
    for (HostMessenger hm : m_messengers) {
        MeshProber.prober(hm).waitForDetermination();
    }
}
Also used : IntStream(java.util.stream.IntStream) WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) MeshProber(org.voltdb.probe.MeshProber) Semaphore(java.util.concurrent.Semaphore) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Sets(com.google_voltpatches.common.collect.Sets) KeeperState(org.apache.zookeeper_voltpatches.Watcher.Event.KeeperState) ArrayList(java.util.ArrayList) Watcher(org.apache.zookeeper_voltpatches.Watcher) HostMessenger(org.voltcore.messaging.HostMessenger) HostAndPort(com.google_voltpatches.common.net.HostAndPort) TreeMap(java.util.TreeMap) Map(java.util.Map) Constants(org.voltcore.common.Constants) StartAction(org.voltdb.StartAction) PortGenerator(org.voltcore.utils.PortGenerator) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) HostMessenger(org.voltcore.messaging.HostMessenger)

Example 2 with StartAction

use of org.voltdb.StartAction 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 3 with StartAction

use of org.voltdb.StartAction in project voltdb by VoltDB.

the class CommandLine method startCommand.

public CommandLine startCommand(String command) {
    StartAction action = StartAction.monickerFor(command);
    if (action == null) {
        // command wasn't a valid enum type, throw an exception.
        String msg = "Unknown action: " + command + ". ";
        hostLog.warn(msg);
        throw new IllegalArgumentException(msg);
    }
    m_startAction = action;
    return this;
}
Also used : StartAction(org.voltdb.StartAction)

Example 4 with StartAction

use of org.voltdb.StartAction in project voltdb by VoltDB.

the class TestStateMachine method setUp.

@Before
public void setUp() throws Exception {
    setUpZK(NUM_AGREEMENT_SITES);
    coordinators = IntStream.range(0, NUM_AGREEMENT_SITES).mapToObj(i -> ":" + (i + Constants.DEFAULT_INTERNAL_PORT)).toArray(s -> new String[s]);
    criteria = MeshProber.builder().coordinators(coordinators).startAction(StartAction.PROBE).hostCount(NUM_AGREEMENT_SITES).build();
    ZooKeeper zk = m_messengers.get(0).getZK();
    ZKUtil.addIfMissing(zk, "/test", CreateMode.PERSISTENT, null);
    ZKUtil.addIfMissing(zk, "/test/db", CreateMode.PERSISTENT, null);
    ZKUtil.addIfMissing(zk, stateMachineManagerRoot, CreateMode.PERSISTENT, null);
    for (int ii = 0; ii < NUM_AGREEMENT_SITES; ii++) {
        addStateMachinesFor(ii);
    }
}
Also used : IntStream(java.util.stream.IntStream) MeshProber(org.voltdb.probe.MeshProber) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) ByteBuffer(java.nio.ByteBuffer) Charsets(com.google_voltpatches.common.base.Charsets) List(java.util.List) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) HostMessenger(org.voltcore.messaging.HostMessenger) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) After(org.junit.After) CreateMode(org.apache.zookeeper_voltpatches.CreateMode) Constants(org.voltcore.common.Constants) Assert.fail(org.junit.Assert.fail) StartAction(org.voltdb.StartAction) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) VoltLogger(org.voltcore.logging.VoltLogger) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Before(org.junit.Before)

Example 5 with StartAction

use of org.voltdb.StartAction in project voltdb by VoltDB.

the class MeshProber method determineStartActionIfNecessary.

/**
     * Check to see if we have enough {@link HostCriteria} gathered to make a
     * start action {@link Determination}
     */
private void determineStartActionIfNecessary(Map<Integer, HostCriteria> hostCriteria) {
    // already made a determination
    if (m_probedDetermination.isDone()) {
        return;
    }
    final int ksafety = getkFactor() + 1;
    // node has no recoverable artifacts (Command Logs, Snapshots)
    int bare = 0;
    int unmeshed = 0;
    int operational = 0;
    int haveTerminus = 0;
    int hostCount = getHostCount();
    int missingHostCount = getmissingHostCount();
    // both paused and safemode need to be specified on only one node to
    // make them a cluster attribute. These are overridden if there are
    // any nodes in operational state
    boolean paused = isPaused();
    boolean safemode = isSafeMode();
    final NavigableSet<String> terminusNonces = new TreeSet<>();
    for (HostCriteria c : hostCriteria.values()) {
        if (c.getNodeState().operational()) {
            operational += 1;
            // prefer host count from operational nodes
            if (operational == 1) {
                paused = c.isPaused();
                hostCount = c.getHostCount();
            }
        }
        unmeshed += c.getNodeState().unmeshed() ? 1 : 0;
        bare += c.isBare() ? 1 : 0;
        if (c.isPaused() && operational == 0) {
            paused = c.isPaused();
        }
        safemode = safemode || c.isSafeMode();
        if (c.getTerminusNonce() != null) {
            terminusNonces.add(c.getTerminusNonce());
            ++haveTerminus;
        }
    }
    int expectedHostCount = hostCount - missingHostCount;
    // not enough host criteria to make a determination
    if (hostCriteria.size() < expectedHostCount && operational == 0) {
        m_networkLog.debug("have yet to receive all the required host criteria");
        return;
    }
    // handle add (i.e. join) cases too
    if (hostCount < getHostCount() && hostCriteria.size() <= expectedHostCount) {
        m_networkLog.debug("have yet to receive all the required host criteria");
        return;
    }
    m_networkLog.debug("Received all the required host criteria");
    // kfactor + 1
    safemode = safemode && operational == 0 && bare < ksafety;
    if (m_networkLog.isDebugEnabled()) {
        m_networkLog.debug("We have " + operational + " operational nodes, " + bare + " bare nodes, and " + unmeshed + " unmeshed nodes");
        m_networkLog.debug("Propagated cluster attribute are paused: " + paused + ", and safemode: " + safemode);
    }
    if (terminusNonces.size() > 1) {
        org.voltdb.VoltDB.crashLocalVoltDB("Detected multiple startup snapshots, cannot " + "proceed with cluster startup. Snapshot IDs " + terminusNonces);
    }
    String terminusNonce = terminusNonces.pollFirst();
    if (operational == 0 && haveTerminus <= (hostCount - ksafety)) {
        terminusNonce = null;
    }
    if (getStartAction() != StartAction.PROBE) {
        m_probedDetermination.set(new Determination(getStartAction(), getHostCount(), paused, terminusNonce));
        return;
    }
    StartAction determination = isBare() ? StartAction.CREATE : StartAction.RECOVER;
    if (operational > 0 && operational < hostCount) {
        // rejoin
        determination = StartAction.LIVE_REJOIN;
    } else if (operational > 0 && operational == hostCount) {
        // join
        if (isAddAllowed()) {
            // kfactor + 1
            hostCount = hostCount + ksafety;
            determination = StartAction.JOIN;
        } else {
            org.voltdb.VoltDB.crashLocalVoltDB("Node is not allowed to rejoin an already complete cluster");
            return;
        }
    } else if (operational == 0 && bare == unmeshed) {
        determination = StartAction.CREATE;
    } else if (operational == 0 && bare < ksafety) /* kfactor + 1 */
    {
        determination = safemode ? StartAction.SAFE_RECOVER : StartAction.RECOVER;
    } else if (operational == 0 && bare >= ksafety) /* kfactor + 1 */
    {
        org.voltdb.VoltDB.crashLocalVoltDB("Cluster has incomplete command logs: " + bare + " nodes have no command logs, while " + (unmeshed - bare) + " nodes have them");
        return;
    }
    final Determination dtrm = new Determination(determination, hostCount, paused, terminusNonce);
    if (m_networkLog.isDebugEnabled()) {
        m_networkLog.debug("made the following " + dtrm);
    }
    m_probedDetermination.set(dtrm);
}
Also used : StartAction(org.voltdb.StartAction) TreeSet(java.util.TreeSet)

Aggregations

StartAction (org.voltdb.StartAction)5 Map (java.util.Map)3 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)3 Constants (org.voltcore.common.Constants)3 HostMessenger (org.voltcore.messaging.HostMessenger)3 HostAndPort (com.google_voltpatches.common.net.HostAndPort)2 List (java.util.List)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 IntStream (java.util.stream.IntStream)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 Charsets (com.google_voltpatches.common.base.Charsets)1 Joiner (com.google_voltpatches.common.base.Joiner)1 Preconditions.checkArgument (com.google_voltpatches.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google_voltpatches.common.base.Preconditions.checkNotNull)1 Predicate (com.google_voltpatches.common.base.Predicate)1 Predicates.equalTo (com.google_voltpatches.common.base.Predicates.equalTo)1 Predicates.not (com.google_voltpatches.common.base.Predicates.not)1 Splitter (com.google_voltpatches.common.base.Splitter)1 Supplier (com.google_voltpatches.common.base.Supplier)1