Search in sources :

Example 11 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testEmptyBoundingBoxQuery.

/**
 * Start a bounding box query without inserted tuples
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testEmptyBoundingBoxQuery() throws InterruptedException, ExecutionException, BBoxDBException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    NetworkQueryHelper.testBoundingBoxQuery(bboxDBClient, DISTRIBUTION_GROUP, false);
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Test(org.junit.Test)

Example 12 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class MembershipConnectionService method createConnection.

/**
 * Create a new connection to the given instance
 * @param distributedInstance
 */
private void createConnection(final BBoxDBInstance distributedInstance) {
    final String instanceName = distributedInstance.getStringValue();
    if (serverConnections.containsKey(distributedInstance.getInetSocketAddress())) {
        logger.info("We have already a connection to: {}", instanceName);
        return;
    }
    if (blacklist.contains(distributedInstance.getInetSocketAddress())) {
        logger.info("Not creating a connection to the blacklisted system: {}", instanceName);
        return;
    }
    logger.info("Opening connection to instance: {}", instanceName);
    final BBoxDBConnection connection = new BBoxDBConnection(distributedInstance.getInetSocketAddress());
    final BBoxDBClient client = connection.getBboxDBClient();
    client.setPagingEnabled(pagingEnabled);
    client.setTuplesPerPage(tuplesPerPage);
    client.setTupleStoreManagerRegistry(tupleStoreManagerRegistry);
    final boolean result = connection.connect();
    if (!result) {
        logger.info("Unable to open connection to: {}", instanceName);
    } else {
        logger.info("Connection successfully established: {}", instanceName);
        serverConnections.put(distributedInstance.getInetSocketAddress(), connection);
        knownInstances.put(distributedInstance.getInetSocketAddress(), distributedInstance);
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection)

Example 13 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class PackageRouter method sendInsertPackage.

/**
 * @param insertTupleRequest
 * @return
 * @throws InterruptedException
 * @throws PackageEncodeException
 * @throws TimeoutException
 * @throws ExecutionException
 */
protected boolean sendInsertPackage(final InsertTupleRequest insertTupleRequest) throws InterruptedException, PackageEncodeException {
    final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
    final RoutingHop routingHop = routingHeader.getRoutingHop();
    final BBoxDBInstance receiverInstance = routingHop.getDistributedInstance();
    final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(receiverInstance);
    if (connection == null) {
        logger.error("Unable to get a connection to system: {}", receiverInstance);
        return false;
    }
    final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
    final EmptyResultFuture insertFuture = bboxDBClient.insertTuple(insertTupleRequest.getTable().getFullname(), insertTupleRequest.getTuple(), routingHeader);
    try {
        insertFuture.waitForAll(ROUTING_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
        logger.warn("Routing timeout, retry routing: {}", connection);
        return false;
    }
    final boolean operationSuccess = (!insertFuture.isFailed());
    return operationSuccess;
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) TimeoutException(java.util.concurrent.TimeoutException)

Example 14 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TupleListFuture method performReadRepairForResult.

/**
 * Perform read repair for the given result
 *
 * @param allTuples
 * @param resultId
 * @throws InterruptedException
 * @throws BBoxDBException
 * @throws ZookeeperException
 */
private void performReadRepairForResult(final List<Tuple> allTuples, int resultId) throws InterruptedException, BBoxDBException, ZookeeperException {
    final List<Tuple> tupleResult = get(resultId);
    final BBoxDBConnection bboxDBConnection = getConnection(resultId);
    if (bboxDBConnection == null) {
        // Unable to perform read repair when the connection is not known
        return;
    }
    for (final Tuple tuple : allTuples) {
        final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystem(tablename, tuple.getBoundingBox(), true, bboxDBConnection.getServerAddress(), true);
        // System is not responsible for the tuple
        if (routingHeader.getHopCount() == 0) {
            return;
        }
        if (!tupleResult.contains(tuple)) {
            logger.info("Tuple {} is not contained in result {} from server {}, " + "performing read repair", tuple, tupleResult, bboxDBConnection.getConnectionName());
            final BBoxDBClient bboxDBClient = bboxDBConnection.getBboxDBClient();
            bboxDBClient.insertTuple(tablename, tuple, routingHeader);
        }
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Tuple(org.bboxdb.storage.entity.Tuple)

Example 15 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testCreateDistributionGroupTwoTimes.

/**
 * Test create a distribution group two times
 * @throws BBoxDBException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testCreateDistributionGroupTwoTimes() throws BBoxDBException, InterruptedException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    // Create distribution group
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor((short) 1).build();
    final EmptyResultFuture resultCreate = bboxDBClient.createDistributionGroup(DISTRIBUTION_GROUP, configuration);
    // Prevent retries
    resultCreate.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    resultCreate.waitForAll();
    Assert.assertTrue(resultCreate.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_DGROUP_EXISTS, resultCreate.getMessage(0));
    Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)27 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)26 Test (org.junit.Test)20 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)8 Tuple (org.bboxdb.storage.entity.Tuple)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)4 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)1 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)1 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)1 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)1 StorageManagerException (org.bboxdb.storage.StorageManagerException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 Before (org.junit.Before)1