Search in sources :

Example 21 with SpacePartitioner

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

Example 22 with SpacePartitioner

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);
}
Also used : SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) Logger(org.slf4j.Logger) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) LoggerFactory(org.slf4j.LoggerFactory) RoutingHop(org.bboxdb.network.routing.RoutingHop) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHopHelper(org.bboxdb.network.routing.RoutingHopHelper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 23 with SpacePartitioner

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);
        }
    }
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Logger(org.slf4j.Logger) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) Collection(java.util.Collection) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) TupleStoreConfigurationCache(org.bboxdb.distribution.TupleStoreConfigurationCache) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) WatchedEvent(org.apache.zookeeper.WatchedEvent) ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) HashSet(java.util.HashSet) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 24 with SpacePartitioner

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

Example 25 with SpacePartitioner

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
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Aggregations

SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)29 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)15 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)14 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 StorageManagerException (org.bboxdb.storage.StorageManagerException)9 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RejectedException (org.bboxdb.commons.RejectedException)3 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)3 SpacePartitionerCache (org.bboxdb.distribution.partitioner.SpacePartitionerCache)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)3 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)3 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)3 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)3 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)3 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2