Search in sources :

Example 1 with RingState

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState in project SilverKing by Morgan-Stanley.

the class NodeRingMaster2 method setConvergenceState.

public void setConvergenceState(MessageGroup message, MessageGroupConnection connection) {
    RingState state;
    ProtoOpResponseMessageGroup response;
    OpResult result;
    ConvergencePoint curCP;
    ConvergencePoint targetCP;
    state = ProtoSetConvergenceStateMessageGroup.getRingState(message);
    curCP = ProtoSetConvergenceStateMessageGroup.getCurCP(message);
    targetCP = ProtoSetConvergenceStateMessageGroup.getTargetCP(message);
    Log.warningf("setConvergenceState %s %s %s", state, curCP, targetCP);
    if (!curMapState.getConvergencePoint().equals(curCP)) {
        Log.warningf("!curMapState.getConvergencePoint().equals(curCP)");
    // This is valid if the node was not in the last ring
    // in which case, nobody should be trying to read from this replica
    // result = OpResult.ERROR;
    }
    // } else {
    if (targetMapState == null || (!targetMapState.getConvergencePoint().equals(targetCP) && state != RingState.ABANDONED)) {
        if (state == RingState.INITIAL) {
            try {
                setTargetMapState(newMapState(targetCP));
                result = OpResult.SUCCEEDED;
            } catch (Exception e) {
                Log.logErrorWarning(e);
                result = OpResult.ERROR;
            }
        } else {
            Log.warningf("targetMapState error. state %s", state);
            if (targetMapState == null) {
                Log.warningf("targetMapState == null");
            } else {
                Log.warningf("!targetMapState.getConvergencePoint().equals(targetCP) %s", !targetMapState.getConvergencePoint().equals(targetCP));
            }
            result = OpResult.ERROR;
        }
    } else {
        result = targetMapState.setState(state);
        if (state == RingState.CLOSED && result == OpResult.SUCCEEDED) {
            setCurMapState(targetMapState);
            setTargetMapState(null);
        } else if (state == RingState.ABANDONED) {
            setTargetMapState(null);
        }
    }
    // }
    Log.warningf("setConvergenceState result %s", result);
    response = new ProtoOpResponseMessageGroup(message.getUUID(), 0, result, myOriginatorID.getBytes(), message.getDeadlineRelativeMillis());
    try {
        connection.sendAsynchronous(response.toMessageGroup(), SystemTimeUtil.systemTimeSource.absTimeMillis() + message.getDeadlineRelativeMillis());
    } catch (IOException ioe) {
        Log.logErrorWarning(ioe);
    }
}
Also used : ProtoOpResponseMessageGroup(com.ms.silverking.cloud.dht.net.ProtoOpResponseMessageGroup) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) OpResult(com.ms.silverking.cloud.dht.common.OpResult) IOException(java.io.IOException) RingState(com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 2 with RingState

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState in project SilverKing by Morgan-Stanley.

the class PeerStateWatcher method childrenChanged.

@Override
public void childrenChanged(String basePath, Map<String, byte[]> childStates) {
    if (active) {
        RingState _targetState;
        if (RingMapState.verbosePeerStateCheck) {
            Log.warning("PeerStateWatcher.childrenChanged: ", basePath);
        }
        _targetState = targetState;
        if (_targetState != null && stateMet(_targetState, childStates)) {
            if (RingMapState.verbosePeerStateCheck) {
                Log.warning("PeerStateWatcher calling peerStateMet: ", basePath);
            }
            if (statesMet.add(targetState)) {
                peerStateListener.peerStateMet(dhtConfig, ringVersionPair, _targetState);
            }
        }
    }
}
Also used : RingState(com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState)

Example 3 with RingState

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState in project SilverKing by Morgan-Stanley.

the class PeerStateWatcher method stateMet.

private boolean stateMet(RingState targetState, Map<String, byte[]> childStates) {
    if (active) {
        nodesMissingInZK.clear();
        if (RingMapState.debug) {
            Log.warning("in PeerStateWatcher.stateMet ", targetState);
        }
        if (childStates.size() >= peers.size()) {
            Set<IPAndPort> nodesToCheck;
            if (RingMapState.debug) {
                Log.warning("childStates.size() >= peers.size()");
            }
            if (targetState.requiresPassiveParticipation()) {
                // FUTURE - this won't have any effect until passive nodes are adding themselves
                nodesToCheck = new HashSet<>(peers);
                for (String nodeDef : childStates.keySet()) {
                    nodesToCheck.add(new IPAndPort(nodeDef));
                }
            } else {
                nodesToCheck = peers;
            }
            for (IPAndPort node : nodesToCheck) {
                byte[] nodeStateRaw;
                RingState nodeState;
                nodeStateRaw = childStates.get(node.toString());
                nodeState = RingState.valueOf(nodeStateRaw);
                if (!targetState.metBy(nodeState)) {
                    // if (debug) {
                    Log.warning(String.format("targetState not found for: %s nodeState %s targetState %s %s", node.toString(), nodeState, targetState, targetState.metBy(nodeState)));
                    if (nodeState == null) {
                        considerForTimeout(node);
                    }
                    // }
                    return false;
                }
            }
            if (RingMapState.debug) {
                Log.warning("stateMet");
            }
            return true;
        } else {
            if (RingMapState.debug) {
                Log.warning("childStates.size() < peers.size()");
                for (IPAndPort peer : peers) {
                    if (!childStates.containsKey(peer.toString())) {
                        Log.warning("Couldn't find state for: " + peer);
                        considerForTimeout(peer);
                    } else {
                    // peerHealthMonitor.removeSuspect(peer.toString());
                    }
                }
            }
            return false;
        }
    } else {
        return false;
    }
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) RingState(com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState)

Aggregations

RingState (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState)3 OpResult (com.ms.silverking.cloud.dht.common.OpResult)1 ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)1 ProtoOpResponseMessageGroup (com.ms.silverking.cloud.dht.net.ProtoOpResponseMessageGroup)1 IPAndPort (com.ms.silverking.net.IPAndPort)1 IOException (java.io.IOException)1 KeeperException (org.apache.zookeeper.KeeperException)1