Search in sources :

Example 41 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method queryBoundingBoxContinuous.

/**
 * Execute a continuous bounding box query
 * @throws BBoxDBException
 */
@Override
public TupleListFuture queryBoundingBoxContinuous(final String table, final BoundingBox boundingBox) throws BBoxDBException {
    final DistributionRegion distributionRegion = getRootNode(table);
    final List<DistributionRegion> regions = distributionRegion.getDistributionRegionsForBoundingBox(boundingBox);
    if (regions.size() != 1) {
        throw new BBoxDBException("The bounding box belongs to more than one distribution region, " + "this is not supported in continuous queries");
    }
    final DistributionRegion region = regions.get(0);
    final BBoxDBInstance firstSystem = region.getSystems().get(0);
    final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(firstSystem);
    return connection.getBboxDBClient().queryBoundingBoxContinuous(table, boundingBox);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 42 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method insertTuple.

@Override
public EmptyResultFuture insertTuple(final String table, final Tuple tuple) throws BBoxDBException {
    final DistributionRegion distributionRegion = getRootNode(table);
    final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
    final RoutingHeader routingHeader = new RoutingHeader((short) -1, hops);
    if (hops.isEmpty()) {
        final String errorMessage = "Insert tuple called, but hop list for bounding box is empty: " + tuple.getBoundingBox();
        throw new BBoxDBException(errorMessage);
    }
    // Determine the first system, it will route the request to the remaining systems
    final BBoxDBInstance system = hops.get(0).getDistributedInstance();
    final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(system);
    if (connection == null) {
        final String errorMessage = "Unable to insert tuple, no connection to system: " + system;
        throw new BBoxDBException(errorMessage);
    }
    return connection.getBboxDBClient().insertTuple(table, tuple, routingHeader);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 43 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method queryBoundingBox.

@Override
public TupleListFuture queryBoundingBox(final String table, final BoundingBox boundingBox) throws BBoxDBException {
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for bounding box {} in table {}", boundingBox, table);
    }
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, boundingBox);
        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().getQueryBoundingBoxFuture(table, boundingBox, 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)

Example 44 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class AbstractUtilizationPlacementStrategy method calculateSystemUsage.

/**
 * Calculate the usage of each system
 *
 * @return
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 */
protected Multiset<BBoxDBInstance> calculateSystemUsage() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final DistributionGroupAdapter zookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
    final List<String> distributionGroups = zookeeperAdapter.getDistributionGroups();
    // The overall usage
    final ImmutableMultiset.Builder<BBoxDBInstance> builder = ImmutableMultiset.builder();
    // Calculate usage for each distribution group
    for (final String groupName : distributionGroups) {
        final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(groupName);
        final DistributionRegion region = spacepartitioner.getRootNode();
        final Multiset<BBoxDBInstance> regionSystemUsage = DistributionRegionHelper.getSystemUtilization(region);
        // Merge results
        builder.addAll(regionSystemUsage);
    }
    return builder.build();
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 45 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class TupleStoreFlushZookeeperAdapter method accept.

@Override
public void accept(final TupleStoreName ssTableName, final Long flushTimestamp) {
    // Fetch the local instance
    final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
    try {
        final String distributionGroup = ssTableName.getDistributionGroup();
        final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion distributionGroupRoot = spacepartitioner.getRootNode();
        if (distributionGroupRoot == null) {
            logger.error("Root for {} is null, not executing callback", ssTableName);
            return;
        }
        final long regionId = ssTableName.getRegionId().getAsLong();
        final DistributionRegion distributionRegion = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionGroupRoot, regionId);
        logger.debug("Updating checkpoint for: {} to {}", ssTableName.getFullname(), flushTimestamp);
        final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        if (distributionRegionAdapter != null && distributionRegion != null) {
            distributionRegionAdapter.setCheckpointForDistributionRegion(distributionRegion, localInstance, flushTimestamp);
        }
    } catch (ZookeeperException | BBoxDBException e) {
        if (Thread.currentThread().isInterrupted()) {
            return;
        }
        logger.warn("Unable to find distribution region: ", e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Aggregations

DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)91 Test (org.junit.Test)45 BBoxDBException (org.bboxdb.misc.BBoxDBException)34 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)33 BoundingBox (org.bboxdb.commons.math.BoundingBox)27 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)23 ArrayList (java.util.ArrayList)17 List (java.util.List)17 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)16 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)15 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)15 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)14 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)11 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)10 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 RoutingHop (org.bboxdb.network.routing.RoutingHop)10 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)10