use of org.bboxdb.commons.RejectedException in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery4.
/**
* Simple BBox query - across multiple tables on disk - after compact
* @throws StorageManagerException
* @throws InterruptedException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery4() throws StorageManagerException, InterruptedException, RejectedException, IOException {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TABLE_1);
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value".getBytes());
final Tuple tuple2 = new Tuple("2", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value2".getBytes());
final Tuple tuple3 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
storageManager.put(tuple1);
storageManager.flush();
storageManager.put(tuple2);
storageManager.flush();
storageManager.put(tuple3);
storageManager.flush();
final BoundingBox queryBoundingBox = new BoundingBox(0.0, 5.0, 0.0, 5.0);
final Operator spatialIndexReadOperator = new FullTablescanOperator(storageManager);
final Operator queryPlan = new BoundingBoxSelectOperator(queryBoundingBox, spatialIndexReadOperator);
final Iterator<JoinedTuple> iterator = queryPlan.iterator();
final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
final List<Tuple> resultTupleList = resultList.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList.size());
Assert.assertFalse(resultTupleList.contains(tuple1));
Assert.assertTrue(resultTupleList.contains(tuple2));
Assert.assertTrue(resultTupleList.contains(tuple3));
}
use of org.bboxdb.commons.RejectedException in project bboxdb by jnidzwetzki.
the class TestExceptionSafeRunnable method testDefaultImplementation2.
@Test(timeout = 60000)
public void testDefaultImplementation2() throws InterruptedException {
final ExceptionSafeRunnable runnable = new ExceptionSafeRunnable() {
@Override
protected void runThread() throws Exception {
throw new RejectedException("Exception");
}
};
final Thread thread = new Thread(runnable);
thread.start();
thread.join();
}
use of org.bboxdb.commons.RejectedException in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method handleRequest.
@Override
public /**
* Handle the insert tuple request
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Got insert tuple request");
}
try {
final InsertTupleRequest insertTupleRequest = InsertTupleRequest.decodeTuple(encodedPackage);
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
if (!routingHeader.isRoutedPackage()) {
final String errorMessage = "Error while inserting tuple - package is not routed";
logger.error(errorMessage);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, errorMessage);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
// Needs to be rerouted?
if (routingHeader.getHop() == -1) {
routingHeader.dispatchToNextHop();
final RoutingHop localHop = routingHeader.getRoutingHop();
if (PackageRouter.checkLocalSystemNameMatches(localHop)) {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
} else {
logger.debug("Rerouting package {}", packageSequence);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} else {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} catch (RejectedException e) {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_LOCAL_OPERATION_REJECTED_RETRY + " " + e.getMessage());
clientConnectionHandler.writeResultPackage(responsePackage);
} catch (Throwable e) {
logger.error("Error while inserting tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.commons.RejectedException in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method processInsertPackage.
/**
* Insert the table into the local storage
* @param tuple
* @param requestTable
* @param storageRegistry
* @param routingHeader
* @throws StorageManagerException
* @throws RejectedException
* @throws BBoxDBException
*/
protected void processInsertPackage(final Tuple tuple, final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final List<Long> distributionRegions) throws RejectedException {
try {
final String fullname = requestTable.getDistributionGroup();
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final Collection<TupleStoreName> localTables = regionIdMapper.convertRegionIdToTableNames(requestTable, distributionRegions);
if (localTables.isEmpty()) {
throw new BBoxDBException("Got no local tables for routed package");
}
// Are some tables unknown and needs to be created?
final boolean unknownTables = localTables.stream().anyMatch((t) -> !storageRegistry.isStorageManagerKnown(t));
// Expensive call (involves Zookeeper interaction)
if (unknownTables) {
createMissingTables(requestTable, storageRegistry, localTables);
}
// Insert tuples
for (final TupleStoreName tupleStoreName : localTables) {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(tupleStoreName);
storageManager.put(tuple);
}
} catch (RejectedException e) {
throw e;
} catch (Throwable e) {
throw new RejectedException(e);
}
}
use of org.bboxdb.commons.RejectedException in project bboxdb by jnidzwetzki.
the class DistributedRecoveryService method handleOutdatedRegions.
/**
* Handle the outdated distribution regions
* @param distributionGroupName
* @param outdatedRegions
*/
protected void handleOutdatedRegions(final String distributionGroupName, final List<OutdatedDistributionRegion> outdatedRegions) {
for (final OutdatedDistributionRegion outdatedDistributionRegion : outdatedRegions) {
final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(outdatedDistributionRegion.getNewestInstance());
final long regionId = outdatedDistributionRegion.getDistributedRegion().getRegionId();
final List<TupleStoreName> allTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(storageRegistry, distributionGroupName, regionId);
for (final TupleStoreName ssTableName : allTables) {
try {
runRecoveryForTable(ssTableName, outdatedDistributionRegion, connection.getBboxDBClient());
} catch (RejectedException | StorageManagerException | ExecutionException e) {
logger.error("Got an exception while performing recovery for table: " + ssTableName.getFullname());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Got an exception while performing recovery for table: " + ssTableName.getFullname());
}
}
}
}
Aggregations