Search in sources :

Example 1 with DistributionRegionIdMapper

use of org.bboxdb.distribution.region.DistributionRegionIdMapper 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 DistributionRegionIdMapper

use of org.bboxdb.distribution.region.DistributionRegionIdMapper 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 DistributionRegionIdMapper

use of org.bboxdb.distribution.region.DistributionRegionIdMapper 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 DistributionRegionIdMapper

use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.

the class TestRegionIdMapper method testMappingDisappears3.

/**
 * Wait until mapping disappears
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test(timeout = 10000)
public void testMappingDisappears3() throws TimeoutException, InterruptedException {
    final DistributionRegionIdMapper regionIdMapper = new DistributionRegionIdMapper(DISTRIBUTION_REGION_NAME);
    regionIdMapper.addMapping(3, new BoundingBox(15d, 18d, 15d, 18d));
    final Runnable runable = new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(2000);
                regionIdMapper.removeMapping(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    final Thread thread = new Thread(runable);
    thread.start();
    regionIdMapper.waitUntilMappingDisappears(3, 5, TimeUnit.SECONDS);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

Example 5 with DistributionRegionIdMapper

use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.

the class TestRegionIdMapper method testGetAll.

/**
 * Get all known mappings
 */
@Test(timeout = 60000)
public void testGetAll() {
    final DistributionRegionIdMapper regionIdMapper = new DistributionRegionIdMapper(DISTRIBUTION_REGION_NAME);
    regionIdMapper.addMapping(1, new BoundingBox(1d, 2d, 1d, 2d));
    regionIdMapper.addMapping(2, new BoundingBox(10d, 20d, 10d, 20d));
    regionIdMapper.addMapping(3, new BoundingBox(15d, 18d, 15d, 18d));
    final List<TupleStoreName> mappingResult = regionIdMapper.getAllLocalTables(DEFAULT_SSTABLE_NAME);
    Assert.assertEquals(3, mappingResult.size());
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

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