Search in sources :

Example 1 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException 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 ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class QueryHelper method handleNonExstingTable.

/**
 * Handle a non existing table
 * @param requestTable
 * @param clientConnectionHandler
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static boolean handleNonExstingTable(final TupleStoreName requestTable, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    // Table is locally known, prevent expensive zookeeper call
    final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
    if (storageRegistry.isStorageManagerKnown(requestTable)) {
        return true;
    }
    final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
    try {
        final boolean tableKnown = tupleStoreAdapter.isTableKnown(requestTable);
        if (!tableKnown) {
            clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_NOT_EXIST));
            return false;
        }
    } catch (ZookeeperException e) {
        logger.error("Got an exception while query for table", e);
        return false;
    }
    return true;
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 3 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class StreamClientQuery method setupNewIterator.

/**
 * Setup a new iterator with the next local table
 */
protected boolean setupNewIterator() {
    if (activeOperatorIterator != null && !activeOperatorIterator.hasNext()) {
        logger.warn("setupNewIterator() called, but old iterator is not exhaustet. Ignoring call");
        return false;
    }
    if (getNumberOfTablesToProcess() == 0) {
        logger.warn("setupNewIterator() called, but localTables are empty");
        return false;
    }
    try {
        final List<TupleStoreManager> storageManagers = new ArrayList<>();
        final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
        for (final TupleStoreName tupleStoreName : requestTables) {
            final TupleStoreName sstableName = localTables.get(tupleStoreName).remove(0);
            final TupleStoreManager storageManager = QueryHelper.getTupleStoreManager(storageRegistry, sstableName);
            storageManagers.add(storageManager);
        }
        activeOperator = operatorTreeBuilder.buildOperatorTree(storageManagers);
        activeOperatorIterator = activeOperator.iterator();
        return true;
    } catch (StorageManagerException | ZookeeperException e) {
        logger.warn("Got exception while fetching tuples", e);
    }
    return false;
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 4 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method createSplittedRoot.

/**
 * Create a splitted root
 * @param distributionRegionSyncer
 * @param root
 * @return
 * @throws ZookeeperException
 * @throws InterruptedException
 */
private String createSplittedRoot(final DistributionRegionSyncer distributionRegionSyncer, final DistributionRegion root) throws ZookeeperException, InterruptedException {
    final BoundingBox leftBoundingBox = root.getConveringBox().splitAndGetLeft(0, 0, true);
    final BoundingBox rightBoundingBox = root.getConveringBox().splitAndGetRight(0, 0, true);
    final String regionPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(root);
    final CountDownLatch latchLevel0 = new CountDownLatch(1);
    final DistributionRegionCallback level0Callback = (e, r) -> {
        if (root.getDirectChildren().size() == 2) {
            latchLevel0.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(level0Callback);
    distributionRegionAdapter.createNewChild(regionPath, 0, leftBoundingBox, GROUP);
    distributionRegionAdapter.createNewChild(regionPath, 1, rightBoundingBox, GROUP);
    latchLevel0.await();
    distributionRegionSyncer.unregisterCallback(level0Callback);
    Assert.assertEquals(2, root.getDirectChildren().size());
    Assert.assertTrue(root.getChildNumber(0) != null);
    Assert.assertTrue(root.getChildNumber(1) != null);
    return GROUP;
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method waitForSystemsCallback.

@Test(timeout = 10000)
public void waitForSystemsCallback() throws ZookeeperException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    Assert.assertEquals(0, root.getHighestChildNumber());
    final DistributionRegionCallback callback = (e, r) -> {
        if (r.equals(root)) {
            latch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback);
    final BBoxDBInstance newInstance = new BBoxDBInstance("localhost:8443");
    final String path = distributionRegionAdapter.getZookeeperPathForDistributionRegion(root);
    distributionRegionAdapter.addSystemToDistributionRegion(path, newInstance);
    latch.await();
    distributionRegionSyncer.unregisterCallback(callback);
    Assert.assertTrue(root.getSystems().contains(newInstance));
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Aggregations

ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)37 BBoxDBException (org.bboxdb.misc.BBoxDBException)24 BoundingBox (org.bboxdb.commons.math.BoundingBox)17 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)17 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)16 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)13 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)13 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)10 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)9 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)9 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)9 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)9 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)9 Assert (org.junit.Assert)9 Test (org.junit.Test)9 Set (java.util.Set)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)8