Search in sources :

Example 6 with ConvergencePoint

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

the class DHTRingMaster method setTarget.

public void setTarget(Pair<UUIDBase, Quadruple<String, Long, Long, Long>> idAndRing) {
    UUIDBase uuid;
    Quadruple<String, Long, Long, Long> ring;
    uuid = idAndRing.getV1();
    ring = idAndRing.getV2();
    Log.warningAsyncf("DHTRingMaster.setTarget %s %s", uuid, ring.getV1());
    convergenceLock.lock();
    try {
        if (!isValidTarget(ring)) {
            // FUTURE - could improve this sanity check to look at zk info
            Log.warningAsync("Ignoring invalid target ring: ", ring);
        } else {
            if (currentRing == null) {
                try {
                    currentRing = ring.getTripleAt1();
                    dhtRingCurTargetZK.setCurRingAndVersionPair(ring.getV1(), ring.getPairAt2());
                } catch (KeeperException ke) {
                    Log.logErrorWarning(ke);
                }
            } else {
                if (enableLogging) {
                    Log.warningAsync("New ring: ", ring);
                }
                try {
                    CentralConvergenceController.RequestedSyncMode syncMode;
                    // Stop old convergence
                    if (targetConvergenceController != null) {
                        if (enableLogging) {
                            Log.warningAsync("Abandoning old convergence: ", targetRing);
                        }
                        targetConvergenceController.abandon();
                    }
                    // Start new convergence
                    dhtRingCurTargetZK.setTargetRingAndVersionPair(ring.getV1(), ring.getPairAt2());
                    targetRing = ring.getTripleAt1();
                    targetCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(ring.getTripleAt1()), ring.getV4());
                    if (enableLogging) {
                        Log.warningAsync("New targetRing: ", targetRing);
                    }
                    if (mode == Mode.ManualNoSync) {
                        syncMode = CentralConvergenceController.RequestedSyncMode.SetStateOnly;
                    } else {
                        syncMode = CentralConvergenceController.RequestedSyncMode.SyncAndSetStateUnlessSubset;
                    }
                    try {
                        targetConvergenceController = new CentralConvergenceController(uuid, dhtMetaReader, currentCP, targetCP, readExclusions(ring), mgBase, syncUnchangedOwners, syncMode);
                        convergenceControllers.put(targetConvergenceController.getUUID(), targetConvergenceController);
                    } catch (IOException ioe) {
                        Log.logErrorWarning(ioe, "Unable to start convergence");
                        return;
                    }
                    try {
                        convergenceLock.unlock();
                        try {
                            if (enableLogging) {
                                Log.warningAsync("Calling converge(): ", targetRing);
                            }
                            ((CentralConvergenceController) targetConvergenceController).converge(CentralConvergenceController.SyncTargets.Primary);
                        } finally {
                            convergenceLock.lock();
                        }
                        // Convergence was successful
                        // Set the cur -> target, target -> null?
                        currentRing = targetRing;
                        currentCP = targetCP;
                        dhtRingCurTargetZK.setCurRingAndVersionPair(currentRing.getHead(), currentRing.getTail());
                        targetRing = null;
                        targetCP = null;
                        targetConvergenceController = null;
                        if (enableLogging) {
                            Log.warningAsync("Convergence complete: ", targetRing);
                        }
                    } catch (ConvergenceException ce) {
                        // Convergence failed
                        if (!ce.getAbandoned()) {
                            // Failed due to an exception
                            Log.logErrorWarning(ce, "Convergence failed due to exception");
                        } else {
                            // Failed due to a new target causing the old convergence to be abandoned
                            // In this case, the new convergence will take over the cur and target pointers
                            Log.warningAsync("Previous convergence abandoned");
                        }
                    }
                } catch (KeeperException ke) {
                    // Retries are internal to DHTringCurTargetZK. If we got here, those
                    // retries failed.
                    // FUTURE - relay to alerting
                    Log.logErrorWarning(ke, "Unexpected exception during peerStateMet handling");
                }
            }
        }
    } finally {
        convergenceLock.unlock();
    }
}
Also used : ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) UUIDBase(com.ms.silverking.id.UUIDBase) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with ConvergencePoint

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

the class MessageModule method handleChecksumTreeRequest.

private void handleChecksumTreeRequest(MessageGroup message, MessageGroupConnection connection) {
    ConvergencePoint targetCP;
    ConvergencePoint sourceCP;
    RingRegion region;
    boolean localFlag;
    if (Log.levelMet(Level.FINE)) {
        Log.warning("handleChecksumTreeRequest");
        message.displayForDebug();
    }
    targetCP = ProtoChecksumTreeRequestMessageGroup.getTargetConvergencePoint(message);
    sourceCP = ProtoChecksumTreeRequestMessageGroup.getSourceConvergencePoint(message);
    region = ProtoChecksumTreeRequestMessageGroup.getRegion(message);
    localFlag = ProtoChecksumTreeRequestMessageGroup.getLocalFlag(message);
    // targetCP, sourceCP, connection, message.getOriginator(), region);
    if (!localFlag) {
        storage.asyncInvocation("getChecksumTreeForRemote", message.getContext(), message.getUUID(), targetCP, sourceCP, connection, message.getOriginator(), region);
    } else {
        IPAndPort replica;
        replica = ProtoChecksumTreeRequestMessageGroup.getReplica(message);
        storage.asyncInvocation("getChecksumTreeForLocal", message.getContext(), message.getUUID(), targetCP, sourceCP, connection, message.getOriginator(), region, replica, message.getDeadlineRelativeMillis());
    }
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) RingRegion(com.ms.silverking.cloud.ring.RingRegion) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)

Example 8 with ConvergencePoint

use of com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint 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 9 with ConvergencePoint

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

the class NodeRingMaster2 method initializeMap.

public void initializeMap(DHTConfiguration dhtConfig) throws IOException, KeeperException {
    Triple<String, Long, Long> curRingAndVersionPair;
    ConvergencePoint currentCP;
    long creationTime;
    int attemptIndex;
    String ringName;
    Pair<Long, Long> configAndInstance;
    curRingAndVersionPair = new DHTRingCurTargetZK(dhtMetaReader.getMetaClient(), dhtMetaReader.getDHTConfig()).getCurRingAndVersionPair();
    ringName = curRingAndVersionPair.getHead();
    configAndInstance = curRingAndVersionPair.getTail();
    creationTime = Long.MIN_VALUE;
    attemptIndex = 0;
    do {
        String instanceBase;
        instanceBase = MetaPaths.getRingConfigInstancePath(ringName, configAndInstance.getV1());
        try {
            creationTime = dhtMetaReader.getMetaClient().getZooKeeper().getCreationTime(ZooKeeperExtended.padVersionPath(instanceBase, configAndInstance.getV2()));
        } catch (KeeperException e) {
            Log.logErrorWarning(e);
        }
        if (creationTime < 0) {
            ThreadUtil.sleep(zkReadRetryIntervalMillis);
        }
        ++attemptIndex;
    } while (creationTime < 0 && attemptIndex < zkReadAttempts);
    if (creationTime < 0) {
        throw new RuntimeException("Unable to initialize map: " + curRingAndVersionPair);
    }
    currentCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(curRingAndVersionPair), creationTime);
    setCurMapState(newMapState(currentCP));
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) ConvergencePoint(com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ConvergencePoint (com.ms.silverking.cloud.dht.daemon.storage.convergence.ConvergencePoint)9 IOException (java.io.IOException)4 KeeperException (org.apache.zookeeper.KeeperException)4 ChecksumNode (com.ms.silverking.cloud.dht.daemon.storage.convergence.ChecksumNode)3 RingRegion (com.ms.silverking.cloud.ring.RingRegion)2 UUIDBase (com.ms.silverking.id.UUIDBase)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 OpResult (com.ms.silverking.cloud.dht.common.OpResult)1 RingID (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingID)1 RingIDAndVersionPair (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingIDAndVersionPair)1 RingState (com.ms.silverking.cloud.dht.daemon.storage.convergence.RingState)1 SKGridConfiguration (com.ms.silverking.cloud.dht.gridconfig.SKGridConfiguration)1 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)1 ProtoOpResponseMessageGroup (com.ms.silverking.cloud.dht.net.ProtoOpResponseMessageGroup)1