Search in sources :

Example 1 with ResourceAllocationException

use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.

the class SpacePartitionerHelper method allocateSystemsToRegion.

/**
 * Allocate the required amount of systems to the given region
 *
 * @param region
 * @param zookeeperClient
 * @throws ZookeeperException
 * @throws ResourceAllocationException
 * @throws ZookeeperNotFoundException
 */
public static void allocateSystemsToRegion(final String regionPath, final String distributionGroupName, final Collection<BBoxDBInstance> blacklist, final ZookeeperClient zookeeperClient) throws ZookeeperException, ResourceAllocationException, ZookeeperNotFoundException {
    final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroupName);
    final short replicationFactor = config.getReplicationFactor();
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final List<BBoxDBInstance> availableSystems = distributedInstanceManager.getInstances();
    final String placementStrategy = config.getPlacementStrategy();
    final ResourcePlacementStrategy resourcePlacementStrategy = ResourcePlacementStrategyFactory.getInstance(placementStrategy);
    if (resourcePlacementStrategy == null) {
        throw new ResourceAllocationException("Unable to instanciate the ressource " + "placement strategy");
    }
    // The blacklist, to prevent duplicate allocations
    final Set<BBoxDBInstance> allocationSystems = new HashSet<>();
    final Set<BBoxDBInstance> blacklistedSystems = new HashSet<>();
    blacklistedSystems.addAll(blacklist);
    for (short i = 0; i < replicationFactor; i++) {
        final BBoxDBInstance instance = resourcePlacementStrategy.getInstancesForNewRessource(availableSystems, blacklistedSystems);
        allocationSystems.add(instance);
        blacklistedSystems.add(instance);
    }
    logger.info("Allocated new ressource to {} with blacklist {}", allocationSystems, blacklist);
    zookeeperClient.getDistributionRegionAdapter().allocateSystemsToRegion(regionPath, allocationSystems);
}
Also used : BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) ResourcePlacementStrategy(org.bboxdb.distribution.placement.ResourcePlacementStrategy) HashSet(java.util.HashSet)

Example 2 with ResourceAllocationException

use of org.bboxdb.distribution.placement.ResourceAllocationException 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)

Example 3 with ResourceAllocationException

use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method getSystemForNewRessources.

/**
 * Find a system with free resources
 * @return
 * @throws ResourceAllocationException
 */
private BBoxDBConnection getSystemForNewRessources() throws ResourceAllocationException {
    final List<BBoxDBInstance> serverConnections = membershipConnectionService.getAllInstances();
    if (serverConnections == null) {
        throw new ResourceAllocationException("Server connections are null");
    }
    final BBoxDBInstance system = resourcePlacementStrategy.getInstancesForNewRessource(serverConnections);
    return membershipConnectionService.getConnectionForInstance(system);
}
Also used : BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException)

Example 4 with ResourceAllocationException

use of org.bboxdb.distribution.placement.ResourceAllocationException 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 5 with ResourceAllocationException

use of org.bboxdb.distribution.placement.ResourceAllocationException 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)

Aggregations

ResourceAllocationException (org.bboxdb.distribution.placement.ResourceAllocationException)6 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)4 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)4 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)3 SamplingBasedSplitStrategy (org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy)2 SplitpointStrategy (org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy)2 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 InputParseException (org.bboxdb.commons.InputParseException)1 MathUtil (org.bboxdb.commons.MathUtil)1 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)1 ResourcePlacementStrategy (org.bboxdb.distribution.placement.ResourcePlacementStrategy)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1