Search in sources :

Example 46 with BoundingBox

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;
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple)

Example 47 with BoundingBox

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);
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 48 with BoundingBox

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);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) InputParseException(org.bboxdb.commons.InputParseException) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 49 with BoundingBox

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++;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 50 with BoundingBox

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);
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) SamplingBasedSplitStrategy(org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SplitpointStrategy(org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10