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