use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class RingTree method merge.
private void merge(List<RingEntry> destList, List<RingEntry> _sourceList) {
List<RingEntry> sourceList;
Collections.sort(destList, RingEntryPositionComparator.instance);
if (_sourceList.size() == 0) {
throw new RuntimeException("Unexpected empty source list");
}
if (debug) {
System.out.println("merge: ************************");
System.out.println("\t\t" + RingEntry.toString(destList, "\n"));
System.out.println("...................................");
System.out.println("\t\t" + RingEntry.toString(_sourceList, "\n"));
System.out.println("===================================");
}
RingEntry.ensureEntryRegionsDisjoint(destList);
// RingEntry.ensureEntryRegionsDisjoint(_sourceList); // c/o since we support non-disjoint now
sourceList = new ArrayList<>(_sourceList);
while (sourceList.size() > 0) {
RingEntry oldSourceEntry;
RingRegion oldSourceRegion;
boolean destScanActive;
int searchResult;
int startIndex;
int endIndex;
int insertionIndex;
oldSourceEntry = sourceList.remove(0);
oldSourceRegion = oldSourceEntry.getRegion();
searchResult = Collections.binarySearch(destList, oldSourceEntry, RingEntryPositionComparator.instance);
if (searchResult < 0) {
// no exact match for this position was found
// we can look at the two entries next to us to figure out what's up
insertionIndex = -(searchResult + 1);
startIndex = insertionIndex - 1;
if (startIndex < 0) {
startIndex = 0;
endIndex = destList.size();
} else {
endIndex = startIndex + 1;
}
} else {
// we found an exact match for this position, there will be some sort of match below
// should have perfect match, no insertion
insertionIndex = Integer.MIN_VALUE;
startIndex = searchResult;
endIndex = searchResult;
}
// For simplicity, we perform a naive loop through all dests even though
// it would be possible to avoid this loop.
destScanActive = true;
for (int destIndex = startIndex; destScanActive && destIndex <= endIndex && destIndex < destList.size(); ) {
RingEntry oldDestEntry;
RingRegion oldDestRegion;
IntersectionResult iResult;
oldDestEntry = destList.get(destIndex);
oldDestRegion = oldDestEntry.getRegion();
iResult = RingRegion.intersect(oldDestRegion, oldSourceRegion);
// and avoid computing how many are added by each step
switch(iResult.getIntersectionType()) {
case disjoint:
destIndex++;
break;
case isomorphic:
destList.remove(destIndex);
destList.add(destIndex, oldDestEntry.addOwners(oldSourceEntry));
// go on to next source entry
destScanActive = false;
break;
case abPartial:
destList.remove(destIndex);
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping()));
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping()));
// go on to next source entry
destScanActive = false;
break;
case baPartial:
destList.remove(destIndex);
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping()));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping()));
// go on to next source entry
destScanActive = false;
break;
case // fall through
aSubsumesB:
destList.remove(destIndex);
if (iResult.getANonOverlapping().size() == 1) {
if (oldDestEntry.getRegion().getStart() == oldSourceEntry.getRegion().getStart()) {
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping()));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
} else if (oldDestEntry.getRegion().getEnd() == oldSourceEntry.getRegion().getEnd()) {
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping()));
} else {
throw new RuntimeException("panic");
}
} else if (iResult.getANonOverlapping().size() == 2) {
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping().get(1)));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping().get(0)));
} else {
throw new RuntimeException("panic");
}
// go on to next source entry
destScanActive = false;
break;
case // fall through
bSubsumesA:
destList.remove(destIndex);
if (iResult.getBNonOverlapping().size() == 1) {
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping()));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
} else if (iResult.getBNonOverlapping().size() == 2) {
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping().get(1)));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping()).addOwners(oldSourceEntry));
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping().get(0)));
} else {
throw new RuntimeException("panic");
}
// go on to next source entry
destScanActive = false;
break;
case wrappedPartial:
// below is from abPartial
destList.remove(destIndex);
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping().get(1)).addOwners(oldSourceEntry));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getANonOverlapping()));
destList.add(destIndex, oldDestEntry.replaceRegion(iResult.getOverlapping().get(0)).addOwners(oldSourceEntry));
sourceList.add(0, oldSourceEntry.replaceRegion(iResult.getBNonOverlapping()));
// go on to next source entry
destScanActive = false;
break;
case nonIdenticalAllRingspace:
// This case is prevented by the fact RingRegion normalizes all all-ringspace regions
throw new RuntimeException("panic");
default:
throw new RuntimeException("panic");
}
}
if (destScanActive) {
// if we didn't add it, then add here
destList.add(insertionIndex, oldSourceEntry);
// destList.add(oldSourceEntry);
// Collections.sort(destList, RingEntryPositionComparator.instance);
}
}
RingEntry.ensureEntryRegionsDisjoint(destList);
if (debug) {
System.out.println("merge complete: **************");
System.out.println("\t\t" + RingEntry.toString(destList));
System.out.println("======================================");
System.out.println();
}
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class SingleRingZK method writeEntry.
/*
public SingleRingZK(MetaClient mc, NodeClass nodeClass, long topologyVersion,
String configInstancePath, String parentID, String storagePolicyName)
throws KeeperException, IOException {
super(mc, getBase(configInstancePath, parentID, storagePolicyName));
this.nodeClass = nodeClass;
this.storagePolicyName = storagePolicyName;
topology = new TopologyZK(mc.createCloudMC()).readFromZK(topologyVersion);
}
public SingleRingZK(MetaClient mc, NodeClass nodeClass, long topologyVersion,
String configInstancePath, String mapName) throws KeeperException, IOException {
this(mc, nodeClass, topologyVersion, configInstancePath, mapName.split(mapNameDelimiter)[0], mapName.split(mapNameDelimiter)[1]);
}
*/
private void writeEntry(RingEntry ringEntry, String path) throws KeeperException {
RingRegion region;
region = ringEntry.getRegion();
zk.createString(path + "/" + region.toZKString(), ringEntry.getPrimaryOwnersZKString() + "::" + ringEntry.getSecondaryOwnersZKString());
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class TopologyRingCreator method reduceDataMovement.
// ///////////////////////////////////////////////////////////
public TopologyRing reduceDataMovement(TopologyRing oldRing, TopologyRing newRing, RingTreeRecipe recipe) {
SingleRing _old;
SingleRing _new;
SingleRing _ring;
_old = (SingleRing) oldRing.clone(Mutability.Mutable);
_new = (SingleRing) newRing.clone(Mutability.Mutable);
_ring = new SingleRing(_new.getNodeClass(), _new.getVersion(), _new.getStoragePolicyName());
while (_new.getMembers().iterator().hasNext()) {
RingEntry nEntry;
RingEntry oEntry;
IntersectionResult ir;
RingEntry shifted_nEntry;
nEntry = _new.getMembers().iterator().next();
oEntry = findBestRegionFor(_old, nEntry);
shifted_nEntry = nEntry.shiftTo(oEntry.getRegion().getStart());
ir = RingRegion.intersect(oEntry.getRegion(), shifted_nEntry.getRegion());
switch(ir.getIntersectionType()) {
case isomorphic:
_ring.addEntry(shifted_nEntry);
_old.removeEntry(oEntry);
_new.removeEntry(nEntry);
break;
case aSubsumesB:
// only one sub-case possible here
// r1 r2 (r1 ignored in this case)
// aaaaaa (oEntry)
// bbbb (shifted_nEntry)
{
RingEntry oEntry_2;
RingRegion r2;
r2 = new RingRegion(LongRingspace.nextPoint(shifted_nEntry.getRegion().getEnd()), oEntry.getRegion().getEnd());
oEntry_2 = oEntry.replaceRegion(r2);
_ring.addEntry(shifted_nEntry);
_old.removeEntry(oEntry);
_new.removeEntry(nEntry);
_old.addEntry(oEntry_2);
}
break;
case bSubsumesA:
// only one sub-case possible here
// aaaa (oEntry)
// bbbbbb (shifted_nEntry)
// r1 r2
{
RingEntry shifted_nEntry_1;
RingEntry shifted_nEntry_2;
RingRegion r1;
RingRegion r2;
r1 = oEntry.getRegion();
r2 = new RingRegion(LongRingspace.nextPoint(oEntry.getRegion().getEnd()), shifted_nEntry.getRegion().getEnd());
shifted_nEntry_1 = shifted_nEntry.replaceRegion(r1);
shifted_nEntry_2 = shifted_nEntry.replaceRegion(r2);
_ring.addEntry(shifted_nEntry_1);
_old.removeEntry(oEntry);
_new.removeEntry(nEntry);
_new.addEntry(shifted_nEntry_2);
}
break;
case disjoint:
case abPartial:
case baPartial:
throw new RuntimeException("shift makes these cases impossible");
default:
throw new RuntimeException("panic");
}
}
_ring.freeze(recipe.weightSpecs);
_ring = (SingleRing) _ring.simplify();
_ring.freeze(recipe.weightSpecs);
return _ring;
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class ProtoRegionList method merge.
static ProtoRegionList merge(ProtoRegionList l0, ProtoRegionList l1) {
System.out.println("\n\nmerge");
System.out.println(l0);
System.out.println(l1);
if (l0 == null) {
return l1;
} else if (l1 == null) {
return l0;
} else {
List<ProtoRegion> merged;
int i0;
int i1;
merged = new ArrayList<>();
if (l0.getFirstRegionStart() != l1.getFirstRegionStart()) {
throw new RuntimeException("list region start mismatch");
}
i0 = 0;
i1 = 0;
while (i0 < l0.size() || i1 < l1.size()) {
if (i0 > l0.size()) {
merged.add(l1.get(i1).duplicate());
i1++;
} else if (i1 > l1.size()) {
merged.add(l0.get(i0).duplicate());
i0++;
} else {
ProtoRegion pr0;
ProtoRegion pr1;
RingRegion rr0;
RingRegion rr1;
ProtoRegion intersection;
// determine splitEnd
pr0 = l0.get(i0);
pr1 = l1.get(i1);
rr0 = pr0.getRegion();
rr1 = pr1.getRegion();
intersection = ProtoRegion.intersect(pr0, pr1);
merged.add(intersection);
if (intersection.getRegion().getEnd() == rr0.getEnd()) {
i0++;
}
if (intersection.getRegion().getEnd() == rr1.getEnd()) {
i1++;
}
}
}
return new ProtoRegionList(merged);
}
}
use of com.ms.silverking.cloud.ring.RingRegion in project SilverKing by Morgan-Stanley.
the class ChecksumTreeDebug method main.
public static void main(String[] args) {
try {
if (args.length < 8) {
System.out.println("args: <gridConfig> <sourceIP> <namespace> <dhtConfigVersion> <ringName> <sourceRing> <targetRing> <ringRegion> [dataVersion]");
} else {
ChecksumTreeDebug ctd;
SKGridConfiguration gc;
IPAndPort sourceNode;
long namespace;
int dhtConfigVersion;
RingID ringID;
Pair<Long, Long> sourceRing;
Pair<Long, Long> targetRing;
ConvergencePoint sourceCP;
ConvergencePoint targetCP;
RingRegion ringRegion;
long dataVersion;
LWTPoolProvider.createDefaultWorkPools();
gc = SKGridConfiguration.parseFile(args[0]);
sourceNode = new IPAndPort(args[1], gc.getClientDHTConfiguration().getPort());
namespace = NamespaceUtil.nameToLong(args[2]);
dhtConfigVersion = Integer.parseInt(args[3]);
ringID = RingID.nameToRingID(args[4]);
sourceRing = getVersionPair(args[5]);
targetRing = getVersionPair(args[6]);
ringRegion = RingRegion.parseZKString(args[7]);
if (args.length >= 9) {
dataVersion = Long.parseLong(args[8]);
} else {
dataVersion = Long.MAX_VALUE;
}
sourceCP = new ConvergencePoint(dhtConfigVersion, new RingIDAndVersionPair(ringID, sourceRing), dataVersion);
targetCP = new ConvergencePoint(dhtConfigVersion, new RingIDAndVersionPair(ringID, targetRing), dataVersion);
ctd = new ChecksumTreeDebug();
ctd.debug(sourceNode, namespace, ringRegion, sourceCP, targetCP);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations