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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations