use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class AbstractSpacePartitioner method allocateSystems.
/**
* Allocate systems to the children
* @param regionToSplit
* @param numberOfChilden
* @throws ZookeeperException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
protected void allocateSystems(final DistributionRegion regionToSplit, final int numberOfChilden) throws ZookeeperException, ZookeeperNotFoundException, ResourceAllocationException {
// The first child is stored on the same systems as the parent
final DistributionRegion firstRegion = regionToSplit.getDirectChildren().get(0);
final String firstRegionPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(firstRegion);
SpacePartitionerHelper.copySystemsToRegion(regionToSplit.getSystems(), firstRegionPath, zookeeperClient);
final List<BBoxDBInstance> blacklistSystems = regionToSplit.getSystems();
// For the remaining node, a new resource allocation is performed
for (int i = 1; i < numberOfChilden; i++) {
final DistributionRegion region = regionToSplit.getDirectChildren().get(i);
final String path = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(region);
final String fullname = region.getDistributionGroupName();
SpacePartitionerHelper.allocateSystemsToRegion(path, fullname, blacklistSystems, zookeeperClient);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class AbstractTreeSpacePartitoner method setStateToRedistributionActiveAndWait.
/**
* Set children to active and wait
* @param numberOfChilden2
*/
protected void setStateToRedistributionActiveAndWait(final DistributionRegion regionToSplit, final int numberOfChilden) throws ZookeeperException {
// update state
for (final DistributionRegion region : regionToSplit.getAllChildren()) {
final String childPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(region);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.REDISTRIBUTION_ACTIVE);
}
waitForSplitCompleteZookeeperCallback(regionToSplit, numberOfChilden);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method getMergeCandidates.
@Override
public List<List<DistributionRegion>> getMergeCandidates(final DistributionRegion distributionRegion) {
final List<List<DistributionRegion>> result = new ArrayList<>();
final List<DistributionRegion> children = distributionRegion.getParent().getDirectChildren();
children.sort((e1, e2) -> e1.getConveringBox().getIntervalForDimension(0).compareTo(e2.getConveringBox().getIntervalForDimension(0)));
for (int pos = 0; pos < children.size(); pos++) {
final DistributionRegion region = children.get(pos);
// Use the left and the right region as merge candidates
if (region.equals(distributionRegion)) {
if (pos - 1 >= 0) {
result.add(Arrays.asList(distributionRegion, children.get(pos - 1)));
}
if (pos + 1 < children.size()) {
result.add(Arrays.asList(distributionRegion, children.get(pos + 1)));
}
break;
}
}
return result;
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method splitNode.
/**
* Split the node at the given split point
* @param regionToSplit
* @param splitPosition
* @throws BBoxDBException
* @throws ResourceAllocationException
*/
public void splitNode(final DistributionRegion regionToSplit, final double splitPosition) throws BBoxDBException, ResourceAllocationException {
try {
logger.debug("Write split at pos {} into zookeeper", splitPosition);
final DistributionRegion parent = regionToSplit.getParent();
final String sourcePath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(regionToSplit);
final String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(parent);
// Calculate the covering bounding boxes
final BoundingBox parentBox = regionToSplit.getConveringBox();
final BoundingBox leftBoundingBox = parentBox.splitAndGetLeft(splitPosition, 0, true);
final BoundingBox rightBoundingBox = parentBox.splitAndGetRight(splitPosition, 0, false);
final String fullname = distributionGroupName;
// Only one system executes the split, therefore we can determine the child ids
final int oldNumberOfhildren = parent.getDirectChildren().size();
final long childNumber = parent.getHighestChildNumber();
final String child1Path = distributionRegionZookeeperAdapter.createNewChild(parentPath, (int) childNumber + 1, leftBoundingBox, fullname);
final String child2Path = distributionRegionZookeeperAdapter.createNewChild(parentPath, (int) childNumber + 2, rightBoundingBox, fullname);
// Update state
distributionRegionZookeeperAdapter.setStateForDistributionGroup(sourcePath, DistributionRegionState.SPLITTING);
final Predicate<DistributionRegion> predicate = (r) -> r.getDirectChildren().size() == oldNumberOfhildren + 2;
DistributionRegionSyncerHelper.waitForPredicate(predicate, regionToSplit, distributionRegionSyncer);
// The first child is stored on the same systems as the parent
SpacePartitionerHelper.copySystemsToRegion(regionToSplit.getSystems(), child1Path, zookeeperClient);
final List<BBoxDBInstance> blacklistSystems = regionToSplit.getSystems();
SpacePartitionerHelper.allocateSystemsToRegion(child2Path, fullname, blacklistSystems, zookeeperClient);
} catch (ZookeeperException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class TupleRedistributor method getStatistics.
/**
* Get the statistics for the redistribution
* @return
*/
public String getStatistics() {
final StringBuilder sb = new StringBuilder();
sb.append("Input tuples: " + redistributedTuples);
float totalRedistributedTuples = 0;
for (final DistributionRegion region : regionMap.keySet()) {
if (regionMap.get(region).isEmpty()) {
sb.append(", no systems for regionid " + region.getRegionId());
} else {
final long forwarededTuples = regionMap.get(region).get(0).getSinkedTuples();
final float percent = ((float) forwarededTuples / (float) redistributedTuples * 100);
sb.append(", forwared " + forwarededTuples + " to regionid " + region.getRegionId());
sb.append(String.format(" (%.2f %%)", percent));
totalRedistributedTuples = totalRedistributedTuples + forwarededTuples;
}
}
final float percent = ((float) totalRedistributedTuples / (float) redistributedTuples * 100);
sb.append(" Total redistributed tuples: " + totalRedistributedTuples);
sb.append(String.format(" (%.2f %%)", percent));
return sb.toString();
}
Aggregations