Search in sources :

Example 31 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance 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 32 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance 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 33 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method queryVersionTime.

@Override
public TupleListFuture queryVersionTime(final String table, final long timestamp) throws BBoxDBException {
    if (membershipConnectionService.getNumberOfConnections() == 0) {
        throw new BBoxDBException("queryTime called, but connection list is empty");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for timestamp {} in table {}", timestamp, table);
    }
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, BoundingBox.FULL_SPACE);
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getVersionTimeFuture(table, timestamp, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new TupleListFuture(futureProvider, new DoNothingDuplicateResolver(), table);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) DoNothingDuplicateResolver(org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 34 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance 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 35 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method lockTuple.

@Override
public EmptyResultFuture lockTuple(final String table, final Tuple tuple) throws BBoxDBException {
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> supplier = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().createLockTupleFuture(table, tuple, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    // When version locking fails, try again with another version
    return new EmptyResultFuture(supplier, FutureRetryPolicy.RETRY_POLICY_NONE);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Aggregations

BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)78 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)28 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)25 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)14 List (java.util.List)13 RoutingHop (org.bboxdb.network.routing.RoutingHop)13 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)11 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)11 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)11 BoundingBox (org.bboxdb.commons.math.BoundingBox)9 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)8 Map (java.util.Map)7 HashMap (java.util.HashMap)6 ZookeeperBBoxDBInstanceAdapter (org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)6 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)6 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)6 OptionalDouble (java.util.OptionalDouble)4