use of com.ms.silverking.numeric.RingInteger in project SilverKing by Morgan-Stanley.
the class TopologyRingCreator method nextRegion.
private int nextRegion(ProtoRegionList prList, RegionAllocationMode regionAllocationMode, SingleRing sourceRing, int regionIndex, Node node, int maxOwners, ReplicationType rType, Set<Node> remainingNodes) {
int minPotentialOwners;
int bestCandidateIndex;
if (debug) {
System.out.printf("TopologyRingCreator.nextRegion regionIndex %d maxOwners %d\n", regionIndex, maxOwners);
System.out.printf("regionAllocationMode %s\n", regionAllocationMode);
}
minPotentialOwners = Integer.MAX_VALUE;
bestCandidateIndex = -1;
RingInteger _candidateRegionIndex = new RingInteger(prList.size() - 1, lastCandidateValue);
for (int ii = 0; ii < prList.size(); ii++) {
int candidateRegionIndex = _candidateRegionIndex.getValue();
// for (int candidateRegionIndex = 0; candidateRegionIndex <
// prList.size(); candidateRegionIndex++) {
ProtoRegion candidateRegion;
boolean valid;
// Find a region not containing this node
if (debug) {
System.out.printf("TopologyRingCreator.nextRegion loop candidateRegionIndex %d\n", candidateRegionIndex);
}
// Now check to see if this region meets the ownership requirements
// of the current RegionAllocationMode
candidateRegion = prList.get(candidateRegionIndex);
if (!candidateRegion.contains(node) && candidateRegion.getOwners(rType).size() < maxOwners) {
if (debug) {
System.out.printf("candidateRegion %s\n", candidateRegion);
}
switch(regionAllocationMode) {
case Primary:
valid = sourceRing.pointOwnedByNode(candidateRegion.getRegion().getStart(), node, OwnerQueryMode.Primary);
break;
case Secondary:
valid = sourceRing.pointOwnedByNode(candidateRegion.getRegion().getStart(), node, OwnerQueryMode.Secondary);
break;
case Any:
valid = true;
break;
default:
throw new RuntimeException("panic");
}
if (valid) {
// return candidateRegionIndex;
Set<Node> potentialOwnersSet;
int potentialOwners;
potentialOwnersSet = new HashSet<>(remainingNodes);
potentialOwnersSet.removeAll(candidateRegion.getOwnersSet());
potentialOwners = potentialOwnersSet.size();
// (candidateRegion.totalOwners() + ii);
if (potentialOwners < minPotentialOwners) {
minPotentialOwners = potentialOwners;
bestCandidateIndex = candidateRegionIndex;
}
}
}
_candidateRegionIndex.increment();
}
return bestCandidateIndex;
}
use of com.ms.silverking.numeric.RingInteger in project SilverKing by Morgan-Stanley.
the class PingPongTest method threadedTest.
public void threadedTest(Test test, double durationSeconds, int threads) {
nextSemaphore = new RingInteger(0, threads - 1, 0);
semaphores = new Semaphore[threads];
for (int i = 0; i < threads; i++) {
semaphores[i] = new Semaphore(0);
}
for (int i = 0; i < threads; i++) {
new TestRunner(test, durationSeconds, i);
}
}
Aggregations