Search in sources :

Example 1 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class ContinuousBoundingBoxClientQuery method init.

/**
 * Init the query
 * @param tupleStoreManagerRegistry
 * @throws BBoxDBException
 */
protected void init() throws BBoxDBException {
    try {
        final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
        final String fullname = requestTable.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
        final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
        final List<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(boundingBox, requestTable);
        if (localTables.size() != 1) {
            logger.error("Got more than one table for the continuous query {}", localTables);
            close();
            return;
        }
        final TupleStoreName tupleStoreName = localTables.get(0);
        storageManager = QueryHelper.getTupleStoreManager(storageRegistry, tupleStoreName);
        storageManager.registerInsertCallback(tupleInsertCallback);
        // Remove tuple store insert listener on connection close
        clientConnectionHandler.addConnectionClosedHandler((c) -> close());
    } catch (StorageManagerException | ZookeeperException e) {
        logger.error("Got an exception during query init", e);
        close();
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 2 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class KeyClientQuery method computeTuples.

/**
 * Fetch the tuples for the given key and remove the duplicates
 */
protected void computeTuples() {
    try {
        final String fullname = requestTable.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
        final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
        final List<TupleStoreName> localTables = regionIdMapper.getAllLocalTables(requestTable);
        for (final TupleStoreName tupleStoreName : localTables) {
            final TupleStoreManager storageManager = clientConnectionHandler.getStorageRegistry().getTupleStoreManager(tupleStoreName);
            final List<Tuple> tuplesInTable = storageManager.get(key);
            tuplesForKey.addAll(tuplesInTable);
        }
        removeDuplicates(localTables);
    } catch (BBoxDBException | StorageManagerException e) {
        logger.error("Got an exception while fetching tuples for key " + key, e);
        tuplesForKey.clear();
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 3 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class StreamClientQuery method determineLocalTables.

/**
 * Determine the local tables
 * @param requestTables
 */
private void determineLocalTables(final List<TupleStoreName> requestTables) {
    try {
        for (final TupleStoreName requestTable : requestTables) {
            final String fullname = requestTable.getDistributionGroup();
            final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
            final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
            final List<TupleStoreName> localTablesForTable = regionIdMapper.getAllLocalTables(requestTable);
            localTablesForTable.sort((c1, c2) -> c1.compareTo(c2));
            localTables.put(requestTable, localTablesForTable);
        }
        // Check all tables have the same amount of local tables
        int elementSize = -1;
        for (final List<TupleStoreName> elements : localTables.values()) {
            if (elementSize == -1) {
                elementSize = elements.size();
            }
            if (elementSize != elements.size()) {
                throw new IllegalArgumentException("Got invalid element size: " + elementSize + " / " + elements.size());
            }
        }
    } catch (BBoxDBException e) {
        logger.error("Got exception while reading local tables", e);
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 4 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testMergingSupported.

/**
 * Test merging supported
 * @throws ZookeeperException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testMergingSupported() throws ZookeeperException, BBoxDBException {
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    final DistributionRegion rootNode = spacePartitioner.getRootNode();
    Assert.assertTrue(distributionRegionAdapter.isMergingSupported(rootNode));
    distributionRegionAdapter.setMergingSupported(rootNode, false);
    Assert.assertFalse(distributionRegionAdapter.isMergingSupported(rootNode));
    distributionRegionAdapter.setMergingSupported(rootNode, true);
    Assert.assertTrue(distributionRegionAdapter.isMergingSupported(rootNode));
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 5 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testTableCreateDelete.

/**
 * Test the table deletion and creation
 * @throws ZookeeperException
 * @throws BBoxDBException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testTableCreateDelete() throws Exception {
    final TupleStoreAdapter tupleStoreAdapter = zookeeperClient.getTupleStoreAdapter();
    final SpacePartitioner spacePartitioner = getSpacePartitioner();
    final DistributionRegion rootNode = spacePartitioner.getRootNode();
    final String rootPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(rootNode);
    distributionRegionAdapter.addSystemToDistributionRegion(rootPath, ZookeeperClientFactory.getLocalInstanceName());
    final TupleStoreName tupleStoreName = new TupleStoreName(TEST_GROUP + "_tabletest");
    final TupleStoreName tupleStoreName0 = new TupleStoreName(TEST_GROUP + "_tabletest_0");
    final TupleStoreConfiguration configuration = TupleStoreConfigurationBuilder.create().build();
    tupleStoreAdapter.writeTuplestoreConfiguration(tupleStoreName, configuration);
    final TupleStoreManagerRegistry storageRegistry = new TupleStoreManagerRegistry();
    storageRegistry.init();
    storageRegistry.deleteTable(tupleStoreName0, true);
    storageRegistry.createTable(tupleStoreName0, configuration);
    storageRegistry.getTupleStoreManager(tupleStoreName0);
    Assert.assertTrue(storageRegistry.isStorageManagerKnown(tupleStoreName0));
    System.out.println("=== Executing deletion");
    tupleStoreAdapter.deleteTable(tupleStoreName0);
    Thread.sleep(5000);
    Assert.assertFalse(storageRegistry.isStorageManagerKnown(tupleStoreName0));
    storageRegistry.shutdown();
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) 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