Search in sources :

Example 1 with DeletedTuple

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

the class NetworkTupleEncoderDecoder method decode.

/**
 * Convert a ByteBuffer into a TupleAndTable object
 * @param encodedPackage
 * @return
 */
public static TupleAndTable decode(final ByteBuffer encodedPackage) {
    final short tableLength = encodedPackage.getShort();
    final short keyLength = encodedPackage.getShort();
    final int bBoxLength = encodedPackage.getInt();
    final int dataLength = encodedPackage.getInt();
    final long timestamp = encodedPackage.getLong();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] keyBytes = new byte[keyLength];
    encodedPackage.get(keyBytes, 0, keyBytes.length);
    final String key = new String(keyBytes);
    final byte[] boxBytes = new byte[bBoxLength];
    encodedPackage.get(boxBytes, 0, boxBytes.length);
    final byte[] dataBytes = new byte[dataLength];
    encodedPackage.get(dataBytes, 0, dataBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
    Tuple tuple = null;
    if (TupleHelper.isDeletedTuple(boxBytes, dataBytes)) {
        tuple = new DeletedTuple(key, timestamp);
    } else {
        tuple = new Tuple(key, boundingBox, dataBytes, timestamp);
    }
    return new TupleAndTable(tuple, table);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple)

Example 2 with DeletedTuple

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

the class TestSSTable method createTupleList.

/**
 * Helper method for creating some test tuples
 *
 * @return
 */
protected List<Tuple> createTupleList() {
    final List<Tuple> tupleList = new ArrayList<Tuple>();
    tupleList.add(new Tuple("1", BoundingBox.FULL_SPACE, "abc".getBytes()));
    tupleList.add(new Tuple("2", BoundingBox.FULL_SPACE, "def".getBytes()));
    tupleList.add(new Tuple("3", BoundingBox.FULL_SPACE, "geh".getBytes()));
    tupleList.add(new Tuple("4", BoundingBox.FULL_SPACE, "ijk".getBytes()));
    tupleList.add(new DeletedTuple("4"));
    return tupleList;
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Example 3 with DeletedTuple

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

the class TestStorageManager method testDeleteTuple3.

/**
 * Test the mass deletion of tuples
 * @throws StorageManagerException
 * @throws InterruptedException
 * @throws RejectedException
 */
@Test(timeout = 60000)
public void testDeleteTuple3() throws StorageManagerException, InterruptedException, RejectedException {
    int MAX_TUPLES = getNumberOfTuplesForBigInsert();
    System.out.println("Inserting tuples...");
    for (int i = 0; i < MAX_TUPLES; i++) {
        final Tuple createdTuple = new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, Integer.toString(i).getBytes());
        storageManager.put(createdTuple);
    }
    storageManager.flush();
    System.out.println("Deleting tuples...");
    for (int i = 0; i < MAX_TUPLES; i++) {
        storageManager.delete(Integer.toString(i), MicroSecondTimestampProvider.getNewTimestamp());
    }
    storageManager.flush();
    System.out.println("Reading tuples...");
    // Fetch the deleted tuples
    for (int i = 0; i < MAX_TUPLES; i++) {
        final List<Tuple> readTuples = storageManager.get(Integer.toString(i));
        Assert.assertEquals(1, readTuples.size());
        Assert.assertTrue(readTuples.get(0) instanceof DeletedTuple);
    }
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 4 with DeletedTuple

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

the class TestStorageManager method testDeleteTuple2.

@Test(timeout = 60000)
public void testDeleteTuple2() throws StorageManagerException, InterruptedException, RejectedException {
    int MAX_TUPLES = 100000;
    int SPECIAL_TUPLE = MAX_TUPLES / 2;
    int DELETE_AFTER = (int) (MAX_TUPLES * 0.75);
    // Ensure that the tuple is not contained in the storage manager
    final List<Tuple> readTuples = storageManager.get(Integer.toString(SPECIAL_TUPLE));
    Assert.assertTrue(readTuples.isEmpty());
    for (int i = 0; i < MAX_TUPLES; i++) {
        final Tuple createdTuple = new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, Integer.toString(i).getBytes());
        storageManager.put(createdTuple);
        if (i == DELETE_AFTER) {
            storageManager.delete(Integer.toString(SPECIAL_TUPLE), MicroSecondTimestampProvider.getNewTimestamp());
        }
    }
    // Let the storage manager swap the memtables out
    storageManager.flush();
    // Fetch the deleted tuple
    final List<Tuple> readTuples2 = storageManager.get(Integer.toString(SPECIAL_TUPLE));
    Assert.assertEquals(1, readTuples2.size());
    Assert.assertTrue(readTuples2.get(0) instanceof DeletedTuple);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 5 with DeletedTuple

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

the class TestStorageManager method testDeleteTuple.

@Test(timeout = 60000)
public void testDeleteTuple() throws StorageManagerException, InterruptedException, RejectedException {
    int MAX_TUPLES = 100000;
    int SPECIAL_TUPLE = MAX_TUPLES / 2;
    for (int i = 0; i < MAX_TUPLES; i++) {
        final Tuple createdTuple = new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, Integer.toString(i).getBytes());
        storageManager.put(createdTuple);
        if (i == SPECIAL_TUPLE) {
            storageManager.delete(Integer.toString(SPECIAL_TUPLE), createdTuple.getVersionTimestamp() + 1);
        }
    }
    storageManager.flush();
    final List<Tuple> readTuples = storageManager.get(Integer.toString(SPECIAL_TUPLE));
    Assert.assertEquals(1, readTuples.size());
    Assert.assertTrue(readTuples.get(0) instanceof DeletedTuple);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

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