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();
}
}
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());
}
}
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);
}
}
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));
}
Aggregations