use of org.bboxdb.misc.BBoxDBException 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);
}
use of org.bboxdb.misc.BBoxDBException 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.misc.BBoxDBException 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.misc.BBoxDBException 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;
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class TestBoundingBoxQuery method runExperiment.
/**
* Run the experiment with the max dimension size
* @param boundingBox
* @param bboxDBConnection
* @param sampleSize
* @throws BBoxDBException
* @throws IOException
*/
protected void runExperiment(final double maxDimensionSize, final BoundingBox boundingBox, final BBoxDB bboxDBConnection) {
try {
System.out.println("# Simulating with max dimension size: " + maxDimensionSize);
long totalElapsedTime = 0;
for (int execution = 0; execution < RETRIES; execution++) {
final Stopwatch stopwatch = Stopwatch.createStarted();
executeQueries(maxDimensionSize, boundingBox, bboxDBConnection);
final long elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
System.out.println("#" + elapsedTime);
totalElapsedTime += elapsedTime;
}
System.out.println(maxDimensionSize + "\t" + totalElapsedTime / RETRIES);
} catch (Exception e) {
System.err.println("Got exception while executing experiment: " + e);
System.exit(-1);
}
}
Aggregations