use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method getRootNode.
/**
* Get the root node from space partitioner
*
* @param fullname
* @return
* @throws BBoxDBException
*/
private DistributionRegion getRootNode(final String fullname) throws BBoxDBException {
final TupleStoreName tupleStoreName = new TupleStoreName(fullname);
final String distributionGroup = tupleStoreName.getDistributionGroup();
final SpacePartitioner distributionAdapter = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
return distributionAdapter.getRootNode();
}
use of org.bboxdb.distribution.partitioner.SpacePartitioner 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);
}
use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class TupleStoreZookeeperObserver method registerTable.
/**
* Register a new table, a callback is registered on the space partitioner
* to delete the table when it is split or merged
*
* @param tupleStoreName
*/
public void registerTable(final TupleStoreName tupleStoreName) {
if (!tupleStoreName.isDistributedTable()) {
return;
}
final String distributionGroup = tupleStoreName.getDistributionGroup();
final DistributionRegionEntity tableEntity = new DistributionRegionEntity(distributionGroup, tupleStoreName.getRegionId().getAsLong());
synchronized (knownRegions) {
if (knownRegions.contains(tableEntity)) {
return;
}
// Register callback
final DistributionRegionCallback callback = (e, r) -> {
handleCallback(tableEntity, e, r);
};
try {
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
spacePartitioner.registerCallback(callback);
knownRegions.add(tableEntity);
} catch (BBoxDBException e) {
logger.error("Unable to register callback", e);
}
}
}
use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class TupleStoreZookeeperObserver method deleteAllDeletedTables.
/**
* Delete all deleted tables
*
* @param distributionGroup
* @param allZookeeperTables
* @throws BBoxDBException
* @throws StorageManagerException
*/
private void deleteAllDeletedTables(final String distributionGroup, final List<String> allZookeeperTables) throws BBoxDBException, StorageManagerException {
final List<TupleStoreName> allLocalTables = registry.getAllTablesForDistributionGroup(distributionGroup);
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
for (final TupleStoreName localTable : allLocalTables) {
final String localTableName = localTable.getFullnameWithoutPrefix();
if (!allZookeeperTables.contains(localTableName)) {
logger.info("Table {} is not known in zookeeper, deleting local", localTableName);
final Collection<TupleStoreName> localTables = regionIdMapper.getAllLocalTables(localTable);
for (final TupleStoreName ssTableName : localTables) {
registry.deleteTable(ssTableName, false);
}
}
}
}
use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class TestZookeeperIntegration method testCreateAndDeleteDistributionGroup.
/**
* Test the deletion and the creation of an instance
* @throws Exception
*/
@Test(timeout = 60000)
public void testCreateAndDeleteDistributionGroup() throws Exception {
final KDtreeSpacePartitioner cacheGroup = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
Assert.assertTrue(cacheGroup.getRootNode().isLeafRegion());
System.out.println("---> Split");
final KDtreeSpacePartitioner kdTreeAdapter = (KDtreeSpacePartitioner) getSpacePartitioner();
kdTreeAdapter.splitNode(kdTreeAdapter.getRootNode(), (float) 20.0);
System.out.println("---> Split done");
// Test fresh copy
final SpacePartitioner freshGroup = getSpacePartitioner();
final DistributionRegion firstChildFresh = freshGroup.getRootNode().getDirectChildren().get(0);
Assert.assertEquals(20.0, firstChildFresh.getConveringBox().getCoordinateHigh(0), DELTA);
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
// Test cached instance
try {
cacheGroup.getRootNode().getDirectChildren().get(0);
// This should not happen
Assert.assertFalse(true);
} catch (BBoxDBException e) {
// Unable to get root on a space partitioner after shutdown
}
}
Aggregations