use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class SamplingHelper method processTupleStores.
/**
* Process the facades for the table and create samples
* @param storages
* @param splitDimension
* @param boundingBox
* @param floatIntervals
* @return
* @throws StorageManagerException
*/
private static List<BoundingBox> processTupleStores(final List<ReadOnlyTupleStore> storages) throws StorageManagerException {
final int samplesPerStorage = 100;
final List<BoundingBox> samples = new ArrayList<>();
logger.debug("Fetching {} samples per storage", samplesPerStorage);
for (final ReadOnlyTupleStore storage : storages) {
if (!storage.acquire()) {
continue;
}
final long numberOfTuples = storage.getNumberOfTuples();
final int sampleOffset = Math.max(10, (int) (numberOfTuples / samplesPerStorage));
for (long position = 0; position < numberOfTuples; position = position + sampleOffset) {
final Tuple tuple = storage.getTupleAtPosition(position);
final BoundingBox tupleBoundingBox = tuple.getBoundingBox();
// Ignore tuples with an empty box (e.g. deleted tuples)
if (tupleBoundingBox == null || tupleBoundingBox.equals(BoundingBox.FULL_SPACE)) {
continue;
}
samples.add(tupleBoundingBox);
}
storage.release();
}
return samples;
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class AbstractGridSpacePartitioner method createRootNode.
@Override
public void createRootNode(final DistributionGroupConfiguration configuration) throws BBoxDBException {
// [[0.0,5.0]:[0.0,5.0]];0.5;0.5
final String spConfig = spacePartitionerContext.getSpacePartitionerConfig();
if (spConfig.isEmpty()) {
throw new BBoxDBException("Got empty space partitioner config");
}
final String[] splitConfig = spConfig.split(";");
checkConfigParameter(configuration, splitConfig);
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 = new BoundingBox(splitConfig[0]);
distributionRegionZookeeperAdapter.setBoundingBoxForPath(rootPath, rootBox);
// Create grid
createCells(splitConfig, configuration, rootPath, rootBox);
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_REGION_STATE, DistributionRegionState.SPLIT.getStringValue().getBytes());
NodeMutationHelper.markNodeMutationAsComplete(zookeeperClient, rootPath);
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method getDestinationForMerge.
@Override
public DistributionRegion getDestinationForMerge(final List<DistributionRegion> source) throws BBoxDBException {
try {
assert (source.size() == 2) : "We can only merge 2 regions";
final BoundingBox bbox = BoundingBox.getCoveringBox(source.get(0).getConveringBox(), source.get(1).getConveringBox());
final DistributionRegion parent = source.get(0).getParent();
final String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(parent);
final int childNumber = (int) parent.getHighestChildNumber();
final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, childNumber, bbox, distributionGroupName);
SpacePartitionerHelper.allocateSystemsToRegion(childPath, distributionGroupName, new ArrayList<>(), zookeeperClient);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.ACTIVE);
return distributionRegionZookeeperAdapter.getNodeForPath(source.get(0).getRootRegion(), childPath);
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method createGridInDimension.
/**
* Create the cell grid
* @param splitConfig
* @param parentPath
* @param box
* @param dimension
* @throws ZookeeperException
* @throws InputParseException
* @throws ZookeeperNotFoundException
* @throws ResourceAllocationException
*/
private void createGridInDimension(final String[] splitConfig, final String parentPath, final BoundingBox box, final int dimension) throws ZookeeperException, InputParseException, ZookeeperNotFoundException, ResourceAllocationException {
logger.info("Processing dimension {}", dimension);
if (dimension == 0) {
final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, 0, box, distributionGroupName);
SpacePartitionerHelper.allocateSystemsToRegion(childPath, distributionGroupName, new ArrayList<BBoxDBInstance>(), zookeeperClient);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.ACTIVE);
return;
}
final String stepIntervalString = splitConfig[dimension];
final double stepInterval = MathUtil.tryParseDouble(stepIntervalString, () -> "Unable to parse" + stepIntervalString);
BoundingBox boundingBoxToSplit = box;
int childNumber = 0;
while (boundingBoxToSplit != null) {
final double splitPos = boundingBoxToSplit.getCoordinateLow(dimension) + stepInterval;
BoundingBox nodeBox;
if (splitPos >= boundingBoxToSplit.getCoordinateHigh(dimension)) {
nodeBox = boundingBoxToSplit;
boundingBoxToSplit = null;
} else {
nodeBox = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, false);
boundingBoxToSplit = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, true);
}
final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, childNumber, nodeBox, distributionGroupName);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.SPLIT);
createGridInDimension(splitConfig, childPath, nodeBox, dimension - 1);
childNumber++;
}
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class KDtreeSpacePartitioner method splitRegion.
/**
* Split the node at the given position
* @param regionToSplit
* @param splitPosition
* @throws ZookeeperException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
@Override
public List<DistributionRegion> splitRegion(final DistributionRegion regionToSplit, final Collection<BoundingBox> samples) throws BBoxDBException {
try {
final SplitpointStrategy splitpointStrategy = new SamplingBasedSplitStrategy(samples);
final int splitDimension = getSplitDimension(regionToSplit);
final BoundingBox regionBox = regionToSplit.getConveringBox();
final double splitPosition = splitpointStrategy.getSplitPoint(splitDimension, regionBox);
splitNode(regionToSplit, splitPosition);
return regionToSplit.getDirectChildren();
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
Aggregations