Search in sources :

Example 6 with RejectedException

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));
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) BeforeClass(org.junit.BeforeClass) RejectedException(org.bboxdb.commons.RejectedException) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) Tuple(org.bboxdb.storage.entity.Tuple) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) List(java.util.List) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Lists(com.google.common.collect.Lists) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) Assert(org.junit.Assert) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) Before(org.junit.Before) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 7 with RejectedException

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();
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) Test(org.junit.Test)

Example 8 with RejectedException

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;
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 9 with RejectedException

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);
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 10 with RejectedException

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());
            }
        }
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) StorageManagerException(org.bboxdb.storage.StorageManagerException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

RejectedException (org.bboxdb.commons.RejectedException)10 BBoxDBException (org.bboxdb.misc.BBoxDBException)7 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)7 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)6 Test (org.junit.Test)6 Lists (com.google.common.collect.Lists)5 Iterator (java.util.Iterator)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)5 Tuple (org.bboxdb.storage.entity.Tuple)5 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)5 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)5 AfterClass (org.junit.AfterClass)5 Assert (org.junit.Assert)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 IOException (java.io.IOException)4 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)4 BoundingBoxSelectOperator (org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator)4