use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class SingleRing method releaseToNode.
/**
* Mutates this ring to move the specified region from the oldOwner to the newOwner.
* The specified region must be a subregion of an existing region owned by the oldOwner.
*/
@Override
public void releaseToNode(RingRegion region, Node oldOwner, Node newOwner) {
RingEntry oldEntry;
RingRegion otherRegion;
RingRegion oldRegion;
ensureMutable();
Log.fine("region: " + region);
oldEntry = removeOwner(region.getEnd());
oldRegion = oldEntry.getRegion();
Log.fine("oldRegion: " + oldRegion);
if (region.getSize() > oldRegion.getSize()) {
throw new RuntimeException("region.getSize() > oldRegion.getSize() " + oldRegion + " " + region);
}
if (oldRegion.getEnd() == region.getEnd()) {
if (oldRegion.getStart() == region.getStart()) {
// complete replacement
Log.fine("complete replacement");
addEntry(oldEntry.replacePrimaryOwner(oldOwner, newOwner));
} else {
// region is the end of the old region
Log.fine("region is the end of the old region");
addEntry(new RingEntry(oldEntry.getOwnersSetWithReplacement(oldOwner, newOwner, OwnerQueryMode.Primary), region, oldEntry.getMinPrimaryUnderFailure()));
otherRegion = new RingRegion(oldRegion.getStart(), LongRingspace.prevPoint(region.getStart()));
addEntry(new RingEntry(oldEntry.getPrimaryOwnersList(), otherRegion, oldEntry.getMinPrimaryUnderFailure()));
}
} else {
if (oldRegion.getStart() == region.getStart()) {
// region is the start of the old region
Log.fine("region is the start of the old region");
otherRegion = new RingRegion(LongRingspace.nextPoint(region.getEnd()), oldRegion.getEnd());
addEntry(new RingEntry(oldEntry.getPrimaryOwnersList(), otherRegion, oldEntry.getMinPrimaryUnderFailure()));
addEntry(new RingEntry(oldEntry.getOwnersSetWithReplacement(oldOwner, newOwner, OwnerQueryMode.Primary), region, oldEntry.getMinPrimaryUnderFailure()));
} else {
throw new RuntimeException("invalid regions: " + oldRegion + "\t" + region);
}
}
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class DHTRingMaster method requestChecksumTree.
public void requestChecksumTree(Triple<Long, Long, Long> nsAndRegion, ConvergencePoint curCP, ConvergencePoint targetCP, IPAndPort owner) {
MessageGroup mg;
UUIDBase uuid;
uuid = UUIDBase.random();
mg = new ProtoChecksumTreeRequestMessageGroup(uuid, nsAndRegion.getV1(), targetCP, curCP, mgBase.getMyID(), new RingRegion(nsAndRegion.getV2(), nsAndRegion.getV3()), mgBase._getIPAndPort(), false).toMessageGroup();
mgBase.send(mg, owner);
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class CentralConvergenceController method syncRegion.
// ////////////////////////////////////////////////////////////////
private void syncRegion(long ns, RingEntry targetEntry, SyncTargets syncTargets, Action upstreamDependency, List<ReplicaSyncRequest> srList) throws ConvergenceException {
List<RingEntry> sourceEntries;
// Log.warningAsyncf("syncRegion %x %s", ns, targetEntry);
sourceEntries = curMap.getEntries(targetEntry.getRegion());
if (!sourceEntries.isEmpty()) {
// Log.warningAsyncf("%x target %s\towners %s\n", ns, targetEntry.getRegion(), CollectionUtil.toString(sourceEntries));
for (RingEntry sourceEntry : sourceEntries) {
List<IPAndPort> sourceOwners;
List<IPAndPort> nonExcludedSourceOwners;
sourceOwners = new ArrayList<>(sourceEntry.getOwnersIPList(OwnerQueryMode.Primary));
Log.info("Filtering exclusion set: ", exclusionSet);
nonExcludedSourceOwners = exclusionSet.filterByIP(sourceOwners);
if (nonExcludedSourceOwners.size() != sourceOwners.size()) {
Log.warningAsync("Raw sourceOwners: ", sourceOwners);
Log.warningAsync("Filtered nonExcludedSourceOwners: ", nonExcludedSourceOwners);
}
if (nonExcludedSourceOwners.size() == 0) {
Log.warningAsyncf("%x All nonLocalOwners excluded. Ignoring exclusions for this entry.", ns);
} else {
sourceOwners = nonExcludedSourceOwners;
}
IntersectionResult iResult;
// We don't want to request the entire source region.
// We're only interested in the portion(s) of the source region that cover(s) the target region.
// Log.warningAsyncf("Intersection %s %s", sourceEntry.getRegion(), targetEntry.getRegion());
iResult = RingRegion.intersect(sourceEntry.getRegion(), targetEntry.getRegion());
for (RingRegion commonSubRegion : iResult.getOverlapping()) {
List<IPAndPort> targetOwners;
List<IPAndPort> nonExcludedTargetOwners;
targetOwners = new ArrayList<>(targetEntry.getOwnersIPList(syncTargets.getOwnerQueryMode()));
nonExcludedTargetOwners = exclusionSet.filterByIP(targetOwners);
for (IPAndPort newOwner : nonExcludedTargetOwners) {
if (sourceOwners.contains(newOwner) && !syncUnchangedOwners) {
Log.warningAsyncf("Skipping unchanged owner: %s", newOwner);
} else {
Action prev;
prev = upstreamDependency;
for (IPAndPort sourceOwner : nonExcludedSourceOwners) {
prev = syncReplica(ns, commonSubRegion, newOwner.port(dhtConfig.getPort()), sourceOwner.port(dhtConfig.getPort()), prev, srList);
}
}
}
}
}
} else {
// This should actually never occur as the getEntries() call above
// has no notion of local/non-local. It just returns the owners, and there
// should always be owners.
Log.warningAsyncf("Primary convergence %x. No previous non-local owners for entry: ", ns, targetEntry);
throw new ConvergenceException("Unexpected no previous non-local owners for entry");
}
// Log.warningAsyncf("Done syncRegion %x %s", ns, targetEntry);
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class ConvergenceController2 method requestRemoteChecksumTreesForPrimary.
/*
private void requestRemoteChecksumTreesForPrimary(ConvergencePoint targetCP, ConvergencePoint curCP, RingEntry targetEntry) {
Set<IPAndPort> sourceOwners;
sourceOwners = ringMaster.getReplicas(targetEntry.getRegion(), OwnerQueryMode.Primary);
//sourceOwners = ImmutableUtil.remove(sourceMap.getOwners(targetEntry.getRegion(), OwnerQueryMode.Primary),
// mgBase._getIPAndPort());
if (!sourceOwners.isEmpty()) {
if (true) {
System.out.printf("target %s\towners %s\n", targetEntry.getRegion(), CollectionUtil.toString(sourceOwners));
}
requestRemoteChecksumTree(targetCP, curCP, targetEntry, sourceOwners);
} else {
Log.warning("Primary convergence. No previous non-local owners for entry: ", targetEntry);
}
}
*/
private void requestRemoteChecksumTreesForPrimary(RingEntry targetEntry) {
List<RingEntry> sourceEntries;
sourceEntries = getEntries(targetEntry.getRegion());
if (!sourceEntries.isEmpty()) {
Log.warningf("%x target %s\towners %s\n", ns, targetEntry.getRegion(), CollectionUtil.toString(sourceEntries));
for (RingEntry sourceEntry : sourceEntries) {
List<IPAndPort> nonLocalOwners;
List<IPAndPort> _nonLocalOwners;
// ExclusionSet curExclusionSet;
nonLocalOwners = new ArrayList<>(sourceEntry.getOwnersIPList(OwnerQueryMode.Primary));
nonLocalOwners.remove(mgBase._getIPAndPort());
// curExclusionSet = ringMaster.getCurrentExclusionSet();
// Log.warning("Filtering exclusion set: ", curExclusionSet);
// nonLocalOwners = curExclusionSet.filterByIP(nonLocalOwners);
Log.info("Filtering exclusion set: ", exclusionSet);
_nonLocalOwners = exclusionSet.filterByIP(nonLocalOwners);
if (_nonLocalOwners.size() != nonLocalOwners.size()) {
Log.warning("Raw nonLocalOwners: ", nonLocalOwners);
Log.warning("Filtered nonLocalOwners: ", _nonLocalOwners);
}
if (_nonLocalOwners.size() == 0) {
Log.warningf("%x All nonLocalOwners excluded. Ignoring exclusions for this entry.", ns);
} else {
nonLocalOwners = _nonLocalOwners;
}
IntersectionResult iResult;
// We don't want to request the entire source region.
// We're only interested in the portion(s) of the source region that cover(s) the target region.
iResult = RingRegion.intersect(sourceEntry.getRegion(), targetEntry.getRegion());
for (RingRegion commonSubRegion : iResult.getOverlapping()) {
requestRemoteChecksumTree(targetCP, curCP, commonSubRegion, nonLocalOwners);
}
}
} else {
// FIXME - this should actually never occur as the getEntries() call above
// has no notion of local/non-local. It just returns the owners, and there
// should always be owners.
Log.warningf("Primary convergence %x. No previous non-local owners for entry: ", ns, targetEntry);
}
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class RegionTreeBuilder method createLeaves.
private static LeafChecksumNode[] createLeaves(RingRegion region, int numLeaves) {
LeafChecksumNode[] leaves;
long leafRegionSize;
long lastEnd;
leaves = new LeafChecksumNode[numLeaves];
leafRegionSize = region.getSize() / numLeaves;
lastEnd = LongRingspace.prevPoint(region.getStart());
for (int i = 0; i < numLeaves; i++) {
RingRegion leafRegion;
long start;
long end;
start = LongRingspace.nextPoint(lastEnd);
if (i < numLeaves - 1) {
end = LongRingspace.add(start, leafRegionSize - 1);
} else {
end = region.getEnd();
}
leafRegion = new RingRegion(start, end);
leaves[i] = new LeafChecksumNode(leafRegion);
lastEnd = end;
}
return leaves;
}
Aggregations