Search in sources :

Example 51 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader 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 52 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class InsertTupleHandler method processPackageLocally.

/**
 * @param packageSequence
 * @param clientConnectionHandler
 * @param insertTupleRequest
 * @param routingHeader
 * @throws BBoxDBException
 * @throws RejectedException
 * @throws PackageEncodeException
 */
private void processPackageLocally(final short packageSequence, final ClientConnectionHandler clientConnectionHandler, final InsertTupleRequest insertTupleRequest) throws BBoxDBException, RejectedException, PackageEncodeException {
    final Tuple tuple = insertTupleRequest.getTuple();
    final TupleStoreName requestTable = insertTupleRequest.getTable();
    final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
    final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
    final RoutingHop localHop = routingHeader.getRoutingHop();
    PackageRouter.checkLocalSystemNameMatchesAndThrowException(localHop);
    final List<Long> distributionRegions = localHop.getDistributionRegions();
    processInsertPackage(tuple, requestTable, storageRegistry, distributionRegions);
    forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
Also used : TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) RoutingHop(org.bboxdb.network.routing.RoutingHop) Tuple(org.bboxdb.storage.entity.Tuple)

Aggregations

RoutingHeader (org.bboxdb.network.routing.RoutingHeader)52 Test (org.junit.Test)18 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)16 RoutingHop (org.bboxdb.network.routing.RoutingHop)15 ArrayList (java.util.ArrayList)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)11 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)11 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 List (java.util.List)10 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 ByteBuffer (java.nio.ByteBuffer)9 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)6 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)6