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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations