use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class KDtreeSpacePartitioner 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 String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(regionToSplit);
// Calculate the covering bounding boxes
final BoundingBox parentBox = regionToSplit.getConveringBox();
final int splitDimension = getSplitDimension(regionToSplit);
final BoundingBox leftBoundingBox = parentBox.splitAndGetLeft(splitPosition, splitDimension, true);
final BoundingBox rightBoundingBox = parentBox.splitAndGetRight(splitPosition, splitDimension, false);
// Only one system executes the split, therefore we can determine the child ids
distributionRegionZookeeperAdapter.createNewChild(parentPath, 0, leftBoundingBox, distributionGroupName);
distributionRegionZookeeperAdapter.createNewChild(parentPath, 1, rightBoundingBox, distributionGroupName);
// Update state
distributionRegionZookeeperAdapter.setStateForDistributionGroup(parentPath, DistributionRegionState.SPLITTING);
waitUntilChildrenAreCreated(regionToSplit, 2);
allocateSystems(regionToSplit, 2);
setStateToRedistributionActiveAndWait(regionToSplit, 2);
} catch (ZookeeperException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class QuadtreeSpacePartitioner method splitRegion.
@Override
public List<DistributionRegion> splitRegion(final DistributionRegion regionToSplit, final Collection<BoundingBox> samples) throws BBoxDBException {
try {
logger.info("Splitting region {}", regionToSplit.getIdentifier());
final String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(regionToSplit);
final BoundingBox box = regionToSplit.getConveringBox();
final List<BoundingBox> childBoxes = createBoundingBoxes(box);
final int numberOfChilden = childBoxes.size();
for (int i = 0; i < numberOfChilden; i++) {
final BoundingBox childBox = childBoxes.get(i);
distributionRegionZookeeperAdapter.createNewChild(parentPath, i, childBox, distributionGroupName);
}
// Update state
distributionRegionZookeeperAdapter.setStateForDistributionGroup(parentPath, DistributionRegionState.SPLITTING);
waitUntilChildrenAreCreated(regionToSplit, numberOfChilden);
allocateSystems(regionToSplit, numberOfChilden);
setStateToRedistributionActiveAndWait(regionToSplit, numberOfChilden);
return regionToSplit.getDirectChildren();
} catch (ZookeeperException | ZookeeperNotFoundException | ResourceAllocationException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class SpacePartitionerCache method getSpacePartitionerForGroupName.
/**
* Get the distribution region for the given group name
* @param groupName
* @return
* @throws BBoxDBException
* @throws ZookeeperException
* @throws ZookeeperNotFoundException
*/
public synchronized SpacePartitioner getSpacePartitionerForGroupName(final String groupName) throws BBoxDBException {
try {
if (!spacePartitioner.containsKey(groupName)) {
final String path = zookeeperClient.getDistributionGroupAdapter().getDistributionGroupPath(groupName);
final long version = NodeMutationHelper.getNodeMutationVersion(zookeeperClient, path, this);
// Create callback list
if (!callbacks.containsKey(groupName)) {
final Set<DistributionRegionCallback> callback = new CopyOnWriteArraySet<>();
callbacks.put(groupName, callback);
}
// Create region id mapper
if (!distributionRegionIdMapper.containsKey(groupName)) {
final DistributionRegionIdMapper mapper = new DistributionRegionIdMapper(groupName);
distributionRegionIdMapper.put(groupName, mapper);
}
final SpacePartitioner adapter = zookeeperClient.getDistributionGroupAdapter().getSpaceparitioner(groupName, callbacks.get(groupName), distributionRegionIdMapper.get(groupName));
partitionerVersions.put(groupName, version);
spacePartitioner.put(groupName, adapter);
}
return spacePartitioner.get(groupName);
} catch (ZookeeperException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class BenchmarkFileInsertPerformance method handleLine.
/**
* Handle a line from the input file
* @param line
* @throws BBoxDBException
*/
protected void handleLine(String line) {
try {
final Polygon polygon = Polygon.fromGeoJson(line);
final byte[] tupleBytes = polygon.toGeoJson().getBytes();
final Tuple tuple = new Tuple(Long.toString(polygon.getId()), polygon.getBoundingBox(), tupleBytes);
final EmptyResultFuture insertFuture = bboxdbClient.insertTuple(table, tuple);
// register pending future
pendingFutures.put(insertFuture);
insertedTuples.incrementAndGet();
} catch (BBoxDBException e) {
System.err.println("Got an exeption while reading file: " + e);
System.exit(-1);
}
}
Aggregations