Search in sources :

Example 16 with ZookeeperException

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

the class SpacePartitionerFactory method getSpacePartitionerForDistributionGroup.

/**
 * Return the space partitioner for the distribution group
 * @param mapper
 * @param callback
 * @throws ZookeeperNotFoundException
 */
public static SpacePartitioner getSpacePartitionerForDistributionGroup(final SpacePartitionerContext spacePartitionerContext) throws ZookeeperException {
    try {
        final String distributionGroup = spacePartitionerContext.getDistributionGroupName();
        final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroup);
        final String spacePartitionerString = config.getSpacePartitioner();
        // Instance the classname
        final Class<?> classObject = Class.forName(spacePartitionerString);
        if (classObject == null) {
            throw new ClassNotFoundException("Unable to locate class: " + spacePartitionerString);
        }
        final Object factoryObject = classObject.newInstance();
        if (!(factoryObject instanceof SpacePartitioner)) {
            throw new ClassNotFoundException(spacePartitionerString + " is not a instance of SpacePartitioner");
        }
        final SpacePartitioner spacePartitioner = (SpacePartitioner) factoryObject;
        spacePartitioner.init(spacePartitionerContext);
        return spacePartitioner;
    } catch (Exception e) {
        logger.warn("Unable to instance space partitioner for group: " + spacePartitionerContext.getDistributionGroupName(), e);
        throw new RuntimeException(e);
    }
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)

Example 17 with ZookeeperException

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

the class TupleStoreFlushZookeeperAdapter method accept.

@Override
public void accept(final TupleStoreName ssTableName, final Long flushTimestamp) {
    // Fetch the local instance
    final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
    try {
        final String distributionGroup = ssTableName.getDistributionGroup();
        final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion distributionGroupRoot = spacepartitioner.getRootNode();
        if (distributionGroupRoot == null) {
            logger.error("Root for {} is null, not executing callback", ssTableName);
            return;
        }
        final long regionId = ssTableName.getRegionId().getAsLong();
        final DistributionRegion distributionRegion = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionGroupRoot, regionId);
        logger.debug("Updating checkpoint for: {} to {}", ssTableName.getFullname(), flushTimestamp);
        final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        if (distributionRegionAdapter != null && distributionRegion != null) {
            distributionRegionAdapter.setCheckpointForDistributionRegion(distributionRegion, localInstance, flushTimestamp);
        }
    } catch (ZookeeperException | BBoxDBException e) {
        if (Thread.currentThread().isInterrupted()) {
            return;
        }
        logger.warn("Unable to find distribution region: ", e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 18 with ZookeeperException

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

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

the class TestRegionSyncer method testEventOnDelete.

@Test(timeout = 10000)
public void testEventOnDelete() throws InterruptedException, ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    createSplittedRoot(distributionRegionSyncer, root);
    // Tree children will be removed
    final CountDownLatch removedLatch = new CountDownLatch(3);
    final DistributionRegionCallback removedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.REMOVED) {
            removedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(removedCallback);
    distributionGroupAdapter.deleteDistributionGroup(GROUP);
    System.out.println("=== testEventOnDelete: Wait for removed latch");
    removedLatch.await();
    distributionRegionSyncer.unregisterCallback(removedCallback);
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 20 with ZookeeperException

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

the class TestRegionSyncer method testChangeState1.

@Test(timeout = 10000)
public void testChangeState1() throws InterruptedException, ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    Assert.assertEquals(DistributionRegionState.ACTIVE, root.getState());
    final CountDownLatch latch = new CountDownLatch(1);
    final DistributionRegionCallback callback = (e, r) -> {
        if (r.getState() == DistributionRegionState.ACTIVE_FULL) {
            latch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback);
    distributionRegionAdapter.setStateForDistributionRegion(root, DistributionRegionState.ACTIVE_FULL);
    latch.await();
    distributionRegionSyncer.unregisterCallback(callback);
    Assert.assertEquals(DistributionRegionState.ACTIVE_FULL, root.getState());
}
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) 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