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