Search in sources :

Example 21 with DeletedTuple

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

the class TestTableCompactor method testCompactationMinor.

/**
 * Test a minor compactation
 * @throws StorageManagerException
 */
@Test(timeout = 60000)
public void testCompactationMinor() throws StorageManagerException {
    final List<Tuple> tupleList1 = new ArrayList<Tuple>();
    tupleList1.add(new Tuple("1", BoundingBox.FULL_SPACE, "abc".getBytes()));
    final SSTableKeyIndexReader reader1 = addTuplesToFileAndGetReader(tupleList1, 1);
    final List<Tuple> tupleList2 = new ArrayList<Tuple>();
    tupleList2.add(new DeletedTuple("2"));
    final SSTableKeyIndexReader reader2 = addTuplesToFileAndGetReader(tupleList2, 2);
    final SSTableKeyIndexReader ssTableIndexReader = exectuteCompactAndGetReader(reader1, reader2, false);
    boolean containsDeletedTuple = false;
    int counter = 0;
    for (final Tuple tuple : ssTableIndexReader) {
        counter++;
        if (tuple instanceof DeletedTuple) {
            containsDeletedTuple = true;
        }
    }
    Assert.assertEquals(2, counter);
    Assert.assertTrue(containsDeletedTuple);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 22 with DeletedTuple

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

the class TupleHelper method decodeTuple.

/**
 * Read the tuple from the input stream
 * @param inputStream
 * @return
 * @throws IOException
 */
public static Tuple decodeTuple(final InputStream inputStream) throws IOException {
    final byte[] keyLengthBytes = new byte[DataEncoderHelper.SHORT_BYTES];
    ByteStreams.readFully(inputStream, keyLengthBytes);
    final short keyLength = DataEncoderHelper.readShortFromByte(keyLengthBytes);
    final byte[] boxLengthBytes = new byte[DataEncoderHelper.INT_BYTES];
    ByteStreams.readFully(inputStream, boxLengthBytes);
    final int boxLength = DataEncoderHelper.readIntFromByte(boxLengthBytes);
    final byte[] dataLengthBytes = new byte[DataEncoderHelper.INT_BYTES];
    ByteStreams.readFully(inputStream, dataLengthBytes);
    final int dataLength = DataEncoderHelper.readIntFromByte(dataLengthBytes);
    final byte[] versionTimestampBytes = new byte[DataEncoderHelper.LONG_BYTES];
    ByteStreams.readFully(inputStream, versionTimestampBytes);
    final long versionTimestamp = DataEncoderHelper.readLongFromByte(versionTimestampBytes);
    final byte[] receivedTimestampBytes = new byte[DataEncoderHelper.LONG_BYTES];
    ByteStreams.readFully(inputStream, receivedTimestampBytes);
    final long receivedTimestamp = DataEncoderHelper.readLongFromByte(receivedTimestampBytes);
    final byte[] keyBytes = new byte[keyLength];
    ByteStreams.readFully(inputStream, keyBytes);
    final byte[] boxBytes = new byte[boxLength];
    ByteStreams.readFully(inputStream, boxBytes);
    final byte[] dataBytes = new byte[dataLength];
    ByteStreams.readFully(inputStream, dataBytes);
    final String keyString = new String(keyBytes);
    if (isDeletedTuple(boxBytes, dataBytes)) {
        return new DeletedTuple(keyString, versionTimestamp);
    }
    final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
    return new Tuple(keyString, boundingBox, dataBytes, versionTimestamp, receivedTimestamp);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Example 23 with DeletedTuple

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

the class TupleHelper method decodeTuple.

/**
 * Decode the tuple at the current reader position
 *
 * @param reader
 * @return
 * @throws IOException
 */
public static Tuple decodeTuple(final ByteBuffer byteBuffer) throws IOException {
    final short keyLength = byteBuffer.getShort();
    final int boxLength = byteBuffer.getInt();
    final int dataLength = byteBuffer.getInt();
    final long versionTimestamp = byteBuffer.getLong();
    final long receivedTimestamp = byteBuffer.getLong();
    final byte[] keyBytes = new byte[keyLength];
    byteBuffer.get(keyBytes, 0, keyBytes.length);
    final byte[] boxBytes = new byte[boxLength];
    byteBuffer.get(boxBytes, 0, boxBytes.length);
    final byte[] dataBytes = new byte[dataLength];
    byteBuffer.get(dataBytes, 0, dataBytes.length);
    final String keyString = new String(keyBytes);
    if (isDeletedTuple(boxBytes, dataBytes)) {
        return new DeletedTuple(keyString, versionTimestamp);
    }
    final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
    return new Tuple(keyString, boundingBox, dataBytes, versionTimestamp, receivedTimestamp);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Example 24 with DeletedTuple

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

the class TestTupleHelper method testTupleMisc.

/**
 * Test misc methods of a tuple
 */
@Test(timeout = 60000)
public void testTupleMisc() {
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1d, 2d), "".getBytes());
    Assert.assertTrue(tuple1.compareTo(tuple1) == 0);
    Assert.assertTrue(tuple1.getFormatedString().length() > 10);
    final Tuple tuple2 = new DeletedTuple("abc");
    Assert.assertTrue(tuple2.getFormatedString().length() > 10);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 25 with DeletedTuple

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

the class Memtable method delete.

/**
 * Delete a tuple, this is implemented by inserting a DeletedTuple object
 */
@Override
public void delete(final String key, final long timestamp) throws StorageManagerException {
    assert (usage.get() > 0);
    final Tuple deleteTuple = new DeletedTuple(key, timestamp);
    put(deleteTuple);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) 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