use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method getDestinationForMerge.
@Override
public DistributionRegion getDestinationForMerge(final List<DistributionRegion> source) throws BBoxDBException {
try {
assert (source.size() == 2) : "We can only merge 2 regions";
final BoundingBox bbox = BoundingBox.getCoveringBox(source.get(0).getConveringBox(), source.get(1).getConveringBox());
final DistributionRegion parent = source.get(0).getParent();
final String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(parent);
final int childNumber = (int) parent.getHighestChildNumber();
final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, childNumber, bbox, distributionGroupName);
SpacePartitionerHelper.allocateSystemsToRegion(childPath, distributionGroupName, new ArrayList<>(), zookeeperClient);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.ACTIVE);
return distributionRegionZookeeperAdapter.getNodeForPath(source.get(0).getRootRegion(), childPath);
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method splitComplete.
@Override
public void splitComplete(final DistributionRegion sourceRegion, final List<DistributionRegion> destination) throws BBoxDBException {
try {
logger.info("Split done deleting: {}", sourceRegion.getIdentifier());
distributionRegionZookeeperAdapter.deleteChild(sourceRegion);
// Children are ready
for (final DistributionRegion childRegion : destination) {
distributionRegionZookeeperAdapter.setStateForDistributionRegion(childRegion, DistributionRegionState.ACTIVE);
}
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DynamicgridSpacePartitioner method mergeComplete.
@Override
public void mergeComplete(final List<DistributionRegion> source, final DistributionRegion destination) throws BBoxDBException {
try {
for (final DistributionRegion childRegion : source) {
logger.info("Merge done deleting: {}", childRegion.getIdentifier());
distributionRegionZookeeperAdapter.deleteChild(childRegion);
}
distributionRegionZookeeperAdapter.setStateForDistributionRegion(destination, DistributionRegionState.ACTIVE);
} catch (ZookeeperException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.region.DistributionRegion 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.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method lockTuple.
@Override
public EmptyResultFuture lockTuple(final String table, final Tuple tuple) throws BBoxDBException {
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> supplier = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(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().createLockTupleFuture(table, tuple, routingHeader);
futures.add(future);
}
return futures;
};
// When version locking fails, try again with another version
return new EmptyResultFuture(supplier, FutureRetryPolicy.RETRY_POLICY_NONE);
}
Aggregations