Search in sources :

Example 11 with DeletedTuple

use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testSingleTupleResponse.

/**
 * Try to encode and decode the single tuple response
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleResponse() throws PackageEncodeException, IOException {
    final String tablename = "table1";
    final Tuple tuple = new Tuple("abc", BoundingBox.FULL_SPACE, "databytes".getBytes());
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertFalse(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 12 with DeletedTuple

use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testSingleTupleDeletedResponse.

/**
 * Try to encode and decode the single tuple response - with deleted tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleDeletedResponse() throws PackageEncodeException, IOException {
    final String tablename = "table1";
    final Tuple tuple = new DeletedTuple("abc", 12);
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertTrue(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertEquals(singleTupleResponse.toString(), responseDecoded.toString());
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 13 with DeletedTuple

use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.

the class TestTupleHelper method encodeAndDecodeTuple2.

/**
 * Encode and decode a tuple
 * @throws IOException
 */
@Test(timeout = 60000)
public void encodeAndDecodeTuple2() throws IOException {
    final Tuple tuple = new DeletedTuple("abc");
    // Read from stream
    final byte[] bytes = TupleHelper.tupleToBytes(tuple);
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
    final Tuple readTuple = TupleHelper.decodeTuple(inputStream);
    Assert.assertEquals(tuple, readTuple);
    // Read from byte buffer
    final ByteBuffer bb = ByteBuffer.wrap(bytes);
    final Tuple readTuple2 = TupleHelper.decodeTuple(bb);
    Assert.assertEquals(tuple, readTuple2);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteBuffer(java.nio.ByteBuffer) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 14 with DeletedTuple

use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method deleteTuple.

@Override
public EmptyResultFuture deleteTuple(final String table, final String key, final long timestamp) throws BBoxDBException {
    final DeletedTuple tuple = new DeletedTuple(key);
    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().getInsertTupleFuture(table, tuple, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new EmptyResultFuture(supplier);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) 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 15 with DeletedTuple

use of org.bboxdb.storage.entity.DeletedTuple in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method queryKey.

@Override
public TupleListFuture queryKey(final String table, final String key) throws BBoxDBException {
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for key {} in table {}", key, table);
    }
    final DeletedTuple tuple = new DeletedTuple(key);
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(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().getQueryKeyFuture(table, key, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    final DuplicateResolver<Tuple> duplicateResolver = TupleStoreConfigurationCache.getInstance().getDuplicateResolverForTupleStore(table);
    return new TupleListFuture(futureProvider, duplicateResolver, 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) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Aggregations

DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)25 Tuple (org.bboxdb.storage.entity.Tuple)24 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)7 BoundingBox (org.bboxdb.commons.math.BoundingBox)6 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)5 ByteBuffer (java.nio.ByteBuffer)4 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)4 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)3 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)3 List (java.util.List)2 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)2 JoinedTupleResponse (org.bboxdb.network.packages.response.JoinedTupleResponse)2 TupleResponse (org.bboxdb.network.packages.response.TupleResponse)2 RoutingHop (org.bboxdb.network.routing.RoutingHop)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 AbstractTupleSink (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.AbstractTupleSink)1 TupleRedistributor (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor)1 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)1