use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class DistributionRegionHelper method processRegion.
/**
* Test if there is an outdated region
*
* @param distributedInstance
* @param result
* @param distributionGroupZookeeperAdapter
* @param regionToInspect
* @return
* @throws ZookeeperException
* @throws BBoxDBException
*/
private static OutdatedDistributionRegion processRegion(final BBoxDBInstance distributedInstance, final ZookeeperClient zookeeperClient, final DistributionRegion regionToInspect) throws ZookeeperException, BBoxDBException {
final Map<BBoxDBInstance, Long> versions = new HashMap<>();
for (final BBoxDBInstance instance : regionToInspect.getSystems()) {
final long version = zookeeperClient.getDistributionRegionAdapter().getCheckpointForDistributionRegion(regionToInspect, instance);
versions.put(instance, version);
}
if (!versions.containsKey(distributedInstance)) {
throw new BBoxDBException("Unable to find local instance for region: " + distributedInstance + " / " + regionToInspect);
}
final Optional<Entry<BBoxDBInstance, Long>> newestInstanceOptional = versions.entrySet().stream().reduce((a, b) -> a.getValue() > b.getValue() ? a : b);
if (!newestInstanceOptional.isPresent()) {
return null;
}
final long localVersion = versions.get(distributedInstance);
final Entry<BBoxDBInstance, Long> newestInstance = newestInstanceOptional.get();
if (!newestInstance.getKey().equals(distributedInstance)) {
return new OutdatedDistributionRegion(regionToInspect, newestInstance.getKey(), localVersion);
}
return null;
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class AbstractSpacePartitioner method getRootNode.
@Override
public DistributionRegion getRootNode() throws BBoxDBException {
synchronized (this) {
if (distributionRegionSyncer == null) {
this.distributionRegionSyncer = new DistributionRegionSyncer(spacePartitionerContext);
spacePartitionerContext.getDistributionRegionMapper().clear();
}
}
if (!active) {
throw new BBoxDBException("Get root node on a non active space partitoner called");
}
return distributionRegionSyncer.getRootNode();
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class AbstractTreeSpacePartitoner method createRootNode.
@Override
public void createRootNode(final DistributionGroupConfiguration configuration) throws BBoxDBException {
try {
final String distributionGroup = spacePartitionerContext.getDistributionGroupName();
final String rootPath = distributionGroupZookeeperAdapter.getDistributionGroupRootElementPath(distributionGroup);
zookeeperClient.createDirectoryStructureRecursive(rootPath);
final int nameprefix = distributionGroupZookeeperAdapter.getNextTableIdForDistributionGroup(distributionGroup);
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_NAMEPREFIX, Integer.toString(nameprefix).getBytes());
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_SYSTEMS, "".getBytes());
final BoundingBox rootBox = getRootBox(configuration);
distributionRegionZookeeperAdapter.setBoundingBoxForPath(rootPath, rootBox);
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_REGION_STATE, DistributionRegionState.ACTIVE.getStringValue().getBytes());
SpacePartitionerHelper.allocateSystemsToRegion(rootPath, distributionGroup, new HashSet<>(), zookeeperClient);
NodeMutationHelper.markNodeMutationAsComplete(zookeeperClient, rootPath);
} catch (ZookeeperException | ResourceAllocationException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method splitRegion.
@Override
public List<DistributionRegion> splitRegion(final DistributionRegion regionToSplit, final Collection<BoundingBox> samples) throws BBoxDBException {
try {
final SplitpointStrategy splitpointStrategy = new SamplingBasedSplitStrategy(samples);
final BoundingBox regionBox = regionToSplit.getConveringBox();
final double splitPosition = splitpointStrategy.getSplitPoint(0, regionBox);
splitNode(regionToSplit, splitPosition);
return regionToSplit.getDirectChildren();
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.misc.BBoxDBException 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);
}
}
Aggregations