Search in sources :

Example 36 with BBoxDBInstance

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

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

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

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

the class TupleRedistributor method registerRegion.

/**
 * Register a new region for distribution
 * @param distributionRegion
 * @throws StorageManagerException
 * @throws ZookeeperException
 */
public void registerRegion(final DistributionRegion distributionRegion) throws StorageManagerException {
    final ArrayList<AbstractTupleSink> sinks = new ArrayList<>();
    final Collection<BBoxDBInstance> instances = distributionRegion.getSystems();
    final MembershipConnectionService membershipConnectionService = MembershipConnectionService.getInstance();
    final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
    for (final BBoxDBInstance instance : instances) {
        if (instance.socketAddressEquals(localInstance)) {
            final TupleStoreName localTableName = tupleStoreName.cloneWithDifferntRegionId(distributionRegion.getRegionId());
            final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
            final TupleStoreConfiguration config = readTuplestoreConfig(localTableName, tupleStoreAdapter);
            final TupleStoreManager storageManager = tupleStoreManagerRegistry.createTableIfNotExist(localTableName, config);
            final LocalTupleSink tupleSink = new LocalTupleSink(tupleStoreName, storageManager);
            sinks.add(tupleSink);
            logger.info("Redistributing data to local table {}", localTableName.getFullname());
        } else {
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final NetworkTupleSink tupleSink = new NetworkTupleSink(tupleStoreName, connection);
            sinks.add(tupleSink);
            logger.info("Redistributing data to remote system {}", instance.getInetSocketAddress());
        }
    }
    registerRegion(distributionRegion, sinks);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) ArrayList(java.util.ArrayList) MembershipConnectionService(org.bboxdb.distribution.membership.MembershipConnectionService) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 40 with BBoxDBInstance

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

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