use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class TestRegionIdMapper method testMappingDisappears1.
/**
* Wait until mapping disappears
* @throws InterruptedException
* @throws TimeoutException
*/
@Test(timeout = 10000)
public void testMappingDisappears1() throws TimeoutException, InterruptedException {
final DistributionRegionIdMapper regionIdMapper = new DistributionRegionIdMapper(DISTRIBUTION_REGION_NAME);
regionIdMapper.waitUntilMappingDisappears(3);
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper 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.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class TestSpacePartitionerCache method testRootNodeRefresh.
@Test(timeout = 60000)
public void testRootNodeRefresh() throws Exception {
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
final KDtreeSpacePartitioner oldSpacepartitionier = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion oldRootNode = oldSpacepartitionier.getRootNode();
final DistributionRegionIdMapper mapper = oldSpacepartitionier.getDistributionRegionIdMapper();
Assert.assertEquals(0, mapper.getAllRegionIds().size());
mapper.addMapping(3, BoundingBox.FULL_SPACE);
Assert.assertEquals(1, mapper.getAllRegionIds().size());
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
final KDtreeSpacePartitioner newSpacepartitionier1 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion newRootNode = newSpacepartitionier1.getRootNode();
Assert.assertFalse(oldRootNode == newRootNode);
Assert.assertEquals(0, mapper.getAllRegionIds().size());
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
Thread.sleep(1000);
final KDtreeSpacePartitioner newSpacepartitionier2 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion newRootNode2 = newSpacepartitionier2.getRootNode();
Assert.assertFalse(newRootNode2 == newRootNode);
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method processInsertPackage.
/**
* Insert the table into the local storage
* @param tuple
* @param requestTable
* @param storageRegistry
* @param routingHeader
* @throws StorageManagerException
* @throws RejectedException
* @throws BBoxDBException
*/
protected void processInsertPackage(final Tuple tuple, final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final List<Long> distributionRegions) throws RejectedException {
try {
final String fullname = requestTable.getDistributionGroup();
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final Collection<TupleStoreName> localTables = regionIdMapper.convertRegionIdToTableNames(requestTable, distributionRegions);
if (localTables.isEmpty()) {
throw new BBoxDBException("Got no local tables for routed package");
}
// Are some tables unknown and needs to be created?
final boolean unknownTables = localTables.stream().anyMatch((t) -> !storageRegistry.isStorageManagerKnown(t));
// Expensive call (involves Zookeeper interaction)
if (unknownTables) {
createMissingTables(requestTable, storageRegistry, localTables);
}
// Insert tuples
for (final TupleStoreName tupleStoreName : localTables) {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(tupleStoreName);
storageManager.put(tuple);
}
} catch (RejectedException e) {
throw e;
} catch (Throwable e) {
throw new RejectedException(e);
}
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class SpacePartitionerCache method getSpacePartitionerForGroupName.
/**
* Get the distribution region for the given group name
* @param groupName
* @return
* @throws BBoxDBException
* @throws ZookeeperException
* @throws ZookeeperNotFoundException
*/
public synchronized SpacePartitioner getSpacePartitionerForGroupName(final String groupName) throws BBoxDBException {
try {
if (!spacePartitioner.containsKey(groupName)) {
final String path = zookeeperClient.getDistributionGroupAdapter().getDistributionGroupPath(groupName);
final long version = NodeMutationHelper.getNodeMutationVersion(zookeeperClient, path, this);
// Create callback list
if (!callbacks.containsKey(groupName)) {
final Set<DistributionRegionCallback> callback = new CopyOnWriteArraySet<>();
callbacks.put(groupName, callback);
}
// Create region id mapper
if (!distributionRegionIdMapper.containsKey(groupName)) {
final DistributionRegionIdMapper mapper = new DistributionRegionIdMapper(groupName);
distributionRegionIdMapper.put(groupName, mapper);
}
final SpacePartitioner adapter = zookeeperClient.getDistributionGroupAdapter().getSpaceparitioner(groupName, callbacks.get(groupName), distributionRegionIdMapper.get(groupName));
partitionerVersions.put(groupName, version);
spacePartitioner.put(groupName, adapter);
}
return spacePartitioner.get(groupName);
} catch (ZookeeperException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
Aggregations