Search in sources :

Example 21 with DistributionRegionIdMapper

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);
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

Example 22 with DistributionRegionIdMapper

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);
            }
        }
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 23 with DistributionRegionIdMapper

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);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

Example 24 with DistributionRegionIdMapper

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);
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 25 with DistributionRegionIdMapper

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);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)25 Test (org.junit.Test)14 BoundingBox (org.bboxdb.commons.math.BoundingBox)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)9 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 StorageManagerException (org.bboxdb.storage.StorageManagerException)5 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)3 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)2 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)2 Tuple (org.bboxdb.storage.entity.Tuple)2 RejectedException (org.bboxdb.commons.RejectedException)1 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)1 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)1 TupleRedistributor (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor)1 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1