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);
}
}
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;
}
}
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);
}
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);
}
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());
}
Aggregations