use of com.ms.silverking.id.UUIDBase 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.id.UUIDBase in project SilverKing by Morgan-Stanley.
the class NamespaceRequest method sendNamespaceRequest.
private void sendNamespaceRequest(IPAndPort dest) {
ProtoNamespaceRequestMessageGroup protoMG;
if (debug) {
Log.warning("Requesting namespaces from: ", dest);
}
protoMG = new ProtoNamespaceRequestMessageGroup(new UUIDBase(), mgBase.getMyID());
nsRequests.put(protoMG.getUUID(), this);
mgBase.send(protoMG.toMessageGroup(), dest);
}
use of com.ms.silverking.id.UUIDBase in project SilverKing by Morgan-Stanley.
the class ReplicaSyncRequest method of.
public static ReplicaSyncRequest of(long ns, RingRegion region, IPAndPort newOwner, IPAndPort oldOwner, Action upstreamDependency) {
Action[] upstreamDependencies;
UUIDBase uuid;
if (upstreamDependency != null) {
upstreamDependencies = new Action[1];
upstreamDependencies[0] = upstreamDependency;
} else {
upstreamDependencies = new Action[0];
}
// random to allow for easy use in hashCode()
uuid = UUIDBase.random();
return new ReplicaSyncRequest(uuid, ns, region, newOwner, oldOwner, upstreamDependencies);
}
use of com.ms.silverking.id.UUIDBase in project SilverKing by Morgan-Stanley.
the class CentralConvergenceController method setNodesState.
public void setNodesState(RingState ringState) throws ConvergenceException {
Set<UUIDBase> msgUUIDs;
Set<UUIDBase> incompleteUUIDs;
Set<UUIDBase> failedUUIDs;
Pair<Set<UUIDBase>, Set<UUIDBase>> result;
Map<UUIDBase, IPAndPort> replicaMap;
Set<IPAndPort> targetReplicas;
Set<IPAndPort> passiveNodes;
Log.warningAsyncf("setNodesState %s %s", targetRing.getRingIDAndVersionPair(), ringState);
replicaMap = new HashMap<>();
msgUUIDs = new HashSet<>();
// Also, send to source? but don't wait? unless source is now passive?
// fix passive to include unused?
targetReplicas = getTargetReplicasWithPorts();
passiveNodes = getPassiveNodes();
for (IPAndPort replica : targetReplicas) {
UUIDBase uuid;
uuid = new UUIDBase(false);
opUUIDs.add(uuid);
uuid = sendSetState(uuid, replica, ringState);
msgUUIDs.add(uuid);
replicaMap.put(uuid, replica);
}
for (IPAndPort passiveNode : passiveNodes) {
UUIDBase uuid;
uuid = new UUIDBase(false);
opUUIDs.add(uuid);
uuid = sendSetState(uuid, passiveNode, ringState);
msgUUIDs.add(uuid);
replicaMap.put(uuid, passiveNode);
}
result = opCompletionTracker.waitForCompletion(msgUUIDs, setStateDeadlineRelativeMillis, TimeUnit.MILLISECONDS);
opUUIDs.removeAll(msgUUIDs);
incompleteUUIDs = result.getV1();
failedUUIDs = result.getV2();
displayErrors(replicaMap, incompleteUUIDs, "Incomplete");
displayErrors(replicaMap, failedUUIDs, "Failed");
if (incompleteUUIDs.size() != 0) {
throw new ConvergenceException("Incomplete ops: " + incompleteUUIDs.size());
}
if (failedUUIDs.size() != 0) {
throw new ConvergenceException("Failed ops: " + failedUUIDs.size());
}
this.ringState = ringState;
Log.warningAsyncf("setNodesState complete %s %s", targetRing.getRingIDAndVersionPair(), ringState);
}
use of com.ms.silverking.id.UUIDBase in project SilverKing by Morgan-Stanley.
the class CentralConvergenceController method displayErrors.
private void displayErrors(Map<UUIDBase, IPAndPort> replicaMap, Set<UUIDBase> failed, String label) {
for (UUIDBase uuid : failed) {
IPAndPort replica;
replica = replicaMap.get(uuid);
Log.warningAsyncf("%s: %s", label, replica);
}
}
Aggregations