Search in sources :

Example 1 with RoutingHop

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

the class TestRoutingHeader method testRoutingHeaderHopParser1.

/**
 * Test the hop parser
 */
@Test(timeout = 60000)
public void testRoutingHeaderHopParser1() {
    final RoutingHeader routingHeader = new RoutingHeader((short) 0, new ArrayList<RoutingHop>());
    // Get routing list as string and parse list
    final String stringRoutingList = routingHeader.getRoutingListAsString();
    routingHeader.setRoutingList(stringRoutingList);
    final List<RoutingHop> parsedRoutingList = routingHeader.getRoutingList();
    Assert.assertEquals(0, parsedRoutingList.size());
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) Test(org.junit.Test)

Example 2 with RoutingHop

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

the class DistributionRegionHelper method getRegionsForPredicateAndBox.

/**
 * Add the leaf nodes systems that are covered by the bounding box
 * @param rootRegion
 * @param boundingBox
 * @param systems
 * @return
 */
public static List<RoutingHop> getRegionsForPredicateAndBox(final DistributionRegion rootRegion, final BoundingBox boundingBox, final Predicate<DistributionRegionState> statePredicate) {
    final Map<InetSocketAddress, RoutingHop> hops = new HashMap<>();
    final List<DistributionRegion> regions = rootRegion.getThisAndChildRegions();
    for (final DistributionRegion region : regions) {
        if (!boundingBox.overlaps(region.getConveringBox())) {
            continue;
        }
        if (!statePredicate.test(region.getState())) {
            continue;
        }
        for (final BBoxDBInstance system : region.getSystems()) {
            if (!hops.containsKey(system.getInetSocketAddress())) {
                final RoutingHop routingHop = new RoutingHop(system, new ArrayList<Long>());
                hops.put(system.getInetSocketAddress(), routingHop);
            }
            final RoutingHop routingHop = hops.get(system.getInetSocketAddress());
            routingHop.addRegion(region.getRegionId());
        }
    }
    return new ArrayList<>(hops.values());
}
Also used : HashMap(java.util.HashMap) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 3 with RoutingHop

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

the class BBoxDBCluster method queryVersionTime.

@Override
public TupleListFuture queryVersionTime(final String table, final long timestamp) throws BBoxDBException {
    if (membershipConnectionService.getNumberOfConnections() == 0) {
        throw new BBoxDBException("queryTime called, but connection list is empty");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for timestamp {} in table {}", timestamp, table);
    }
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, BoundingBox.FULL_SPACE);
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getVersionTimeFuture(table, timestamp, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new TupleListFuture(futureProvider, new DoNothingDuplicateResolver(), table);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) DoNothingDuplicateResolver(org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 4 with RoutingHop

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

the class BBoxDBCluster method lockTuple.

@Override
public EmptyResultFuture lockTuple(final String table, final Tuple tuple) throws BBoxDBException {
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> supplier = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().createLockTupleFuture(table, tuple, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    // When version locking fails, try again with another version
    return new EmptyResultFuture(supplier, FutureRetryPolicy.RETRY_POLICY_NONE);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 5 with RoutingHop

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

the class BBoxDBCluster method insertTuple.

@Override
public EmptyResultFuture insertTuple(final String table, final Tuple tuple) throws BBoxDBException {
    final DistributionRegion distributionRegion = getRootNode(table);
    final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
    final RoutingHeader routingHeader = new RoutingHeader((short) -1, hops);
    if (hops.isEmpty()) {
        final String errorMessage = "Insert tuple called, but hop list for bounding box is empty: " + tuple.getBoundingBox();
        throw new BBoxDBException(errorMessage);
    }
    // Determine the first system, it will route the request to the remaining systems
    final BBoxDBInstance system = hops.get(0).getDistributedInstance();
    final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(system);
    if (connection == null) {
        final String errorMessage = "Unable to insert tuple, no connection to system: " + system;
        throw new BBoxDBException(errorMessage);
    }
    return connection.getBboxDBClient().insertTuple(table, tuple, routingHeader);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

RoutingHop (org.bboxdb.network.routing.RoutingHop)16 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)15 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)12 ArrayList (java.util.ArrayList)11 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 List (java.util.List)9 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)8 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)5 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)4 Test (org.junit.Test)3 InetSocketAddress (java.net.InetSocketAddress)2 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)2 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)2 Tuple (org.bboxdb.storage.entity.Tuple)2 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)2 HashMap (java.util.HashMap)1 Collectors (java.util.stream.Collectors)1 RejectedException (org.bboxdb.commons.RejectedException)1