use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method queryJoin.
/* (non-Javadoc)
* @see org.bboxdb.network.client.BBoxDB#queryJoin
*/
@Override
public JoinedTupleListFuture queryJoin(final List<String> tableNames, final BoundingBox boundingBox) throws BBoxDBException {
if (membershipConnectionService.getNumberOfConnections() == 0) {
throw new BBoxDBException("queryJoin called, but connection list is empty");
}
if (logger.isDebugEnabled()) {
logger.debug("Query by for join {} on tables {}", boundingBox, tableNames);
}
final String fullname = tableNames.get(0);
final DistributionRegion distributionRegion = getRootNode(fullname);
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().getJoinFuture(tableNames, boundingBox, routingHeader);
futures.add(future);
}
return futures;
};
return new JoinedTupleListFuture(futureProvider);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method queryInsertedTime.
@Override
public TupleListFuture queryInsertedTime(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().getInsertedTimeFuture(table, timestamp, 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 BBoxDBCluster method queryKey.
@Override
public TupleListFuture queryKey(final String table, final String key) throws BBoxDBException {
if (logger.isDebugEnabled()) {
logger.debug("Query by for key {} in table {}", key, table);
}
final DeletedTuple tuple = new DeletedTuple(key);
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, tuple.getBoundingBox());
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().getQueryKeyFuture(table, key, routingHeader);
futures.add(future);
}
return futures;
};
final DuplicateResolver<Tuple> duplicateResolver = TupleStoreConfigurationCache.getInstance().getDuplicateResolverForTupleStore(table);
return new TupleListFuture(futureProvider, duplicateResolver, table);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method queryBoundingBoxAndTime.
@Override
public TupleListFuture queryBoundingBoxAndTime(final String table, final BoundingBox boundingBox, final long timestamp) throws BBoxDBException {
if (membershipConnectionService.getNumberOfConnections() == 0) {
throw new BBoxDBException("queryBoundingBoxAndTime called, but connection list is empty");
}
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().getBoundingBoxAndTimeFuture(table, boundingBox, timestamp, 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 RoutingHeaderHelper method getRoutingHeaderForLocalSystem.
/**
* Get the routing header for the local system
* @param table
* @param serverAddress
* @param tuple
* @throws ZookeeperException
* @throws BBoxDBException
* @throws InterruptedException
*/
public static RoutingHeader getRoutingHeaderForLocalSystem(final String table, BoundingBox boundingBox, final boolean allowEmptyHop, final InetSocketAddress serverAddress, final boolean write) throws ZookeeperException, BBoxDBException, InterruptedException {
final TupleStoreName ssTableName = new TupleStoreName(table);
final String distributionGroup = ssTableName.getDistributionGroup();
final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion distributionRegion = spacepartitioner.getRootNode();
if (boundingBox == null) {
boundingBox = BoundingBox.FULL_SPACE;
}
final List<RoutingHop> hops = getLocalHops(boundingBox, distributionRegion, write);
if (hops == null || hops.isEmpty()) {
if (!allowEmptyHop) {
throw new BBoxDBException("Got empty result list when query for write: " + boundingBox + " / in table " + table);
}
return new RoutingHeader((short) 0, new ArrayList<>());
}
// Filter the local hop
final List<RoutingHop> connectionHop = hops.stream().filter(r -> r.getDistributedInstance().getInetSocketAddress().equals(serverAddress)).collect(Collectors.toList());
if (!allowEmptyHop && connectionHop.isEmpty()) {
throw new BBoxDBException("Unable to find host " + serverAddress + " in global routing list: " + hops);
}
return new RoutingHeader((short) 0, connectionHop);
}
Aggregations