Search in sources :

Example 31 with ZookeeperException

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

Example 32 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException 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);
    }
}
Also used : SamplingBasedSplitStrategy(org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy) DistributionRegionSyncerHelper(org.bboxdb.distribution.region.DistributionRegionSyncerHelper) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SplitpointStrategy(org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy) BoundingBox(org.bboxdb.commons.math.BoundingBox) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ArrayList(java.util.ArrayList) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) InputParseException(org.bboxdb.commons.InputParseException) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) MathUtil(org.bboxdb.commons.MathUtil) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 33 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException 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);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 34 with ZookeeperException

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

Example 35 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException 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);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)37 BBoxDBException (org.bboxdb.misc.BBoxDBException)24 BoundingBox (org.bboxdb.commons.math.BoundingBox)17 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)17 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)16 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)13 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)13 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)10 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)9 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)9 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)9 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)9 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)9 Assert (org.junit.Assert)9 Test (org.junit.Test)9 Set (java.util.Set)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)8