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