use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.
the class TestTableCompactor method testCompactorRunnable.
/**
* Test the compactor runnable
* @throws RejectedException
* @throws StorageManagerException
* @throws InterruptedException
* @throws BBoxDBException
*/
@Test(timeout = 60000)
public void testCompactorRunnable() throws StorageManagerException, RejectedException, BBoxDBException, InterruptedException {
storageRegistry.createTable(TEST_RELATION, new TupleStoreConfiguration());
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TEST_RELATION);
Assert.assertTrue(storageManager.getServiceState().isInRunningState());
// Create file 1
for (int i = 0; i < 1000; i++) {
storageManager.put(new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, "abc".getBytes()));
}
storageManager.flush();
// Create file 2
for (int i = 0; i < 1000; i++) {
storageManager.put(new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, "abc".getBytes()));
}
storageManager.flush();
final List<DiskStorage> storages = storageRegistry.getAllStorages();
Assert.assertEquals(1, storages.size());
final SSTableServiceRunnable ssTableCompactorRunnable = new SSTableServiceRunnable(storages.get(0));
ssTableCompactorRunnable.forceMajorCompact(storageManager);
// Test exception handler
final List<ReadOnlyTupleStore> writtenStorages = storageManager.aquireStorage();
storageManager.releaseStorage(writtenStorages);
storageManager.shutdown();
final List<SSTableFacade> tupleStorages = writtenStorages.stream().filter(r -> r instanceof SSTableFacade).map(r -> (SSTableFacade) r).collect(Collectors.toList());
Assert.assertFalse(tupleStorages.isEmpty());
ssTableCompactorRunnable.handleCompactException(tupleStorages);
}
use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.
the class TupleStoreManager method getAllTupleVersionsForKey.
/**
* Get all tuples for a given key
* @param tuple
* @param activeStorage
* @return
* @throws StorageManagerException
*/
public List<Tuple> getAllTupleVersionsForKey(final String key) throws StorageManagerException {
List<ReadOnlyTupleStore> aquiredStorages = null;
try {
aquiredStorages = aquireStorage();
final List<Tuple> resultTuples = new ArrayList<>();
for (final ReadOnlyTupleStore readOnlyTupleStorage : aquiredStorages) {
final List<Tuple> possibleTuples = readOnlyTupleStorage.get(key);
resultTuples.addAll(possibleTuples);
}
return resultTuples;
} catch (Exception e) {
throw e;
} finally {
releaseStorage(aquiredStorages);
}
}
use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.
the class RegionSplitter method spreadTupleStores.
/**
* Spread a given tuple store onto new systems
* @param region
* @param sstableManager
* @param ssTableManager
* @param tupleRedistributor
* @param onlyInMemoryData
* @throws StorageManagerException
*/
private void spreadTupleStores(final TupleStoreManager ssTableManager, final TupleRedistributor tupleRedistributor) throws BBoxDBException {
final List<ReadOnlyTupleStore> storages = new ArrayList<>();
try {
final List<ReadOnlyTupleStore> aquiredStorages = ssTableManager.aquireStorage();
storages.addAll(aquiredStorages);
final int totalSotrages = aquiredStorages.size();
for (int i = 0; i < totalSotrages; i++) {
final ReadOnlyTupleStore storage = aquiredStorages.get(i);
logger.info("Spread tuple storage {} number {} of {}", storage.getInternalName(), i, totalSotrages - 1);
spreadStorage(tupleRedistributor, storage);
}
logger.info("Final statistics for spread ({}): {}", ssTableManager.getTupleStoreName().getFullname(), tupleRedistributor.getStatistics());
} catch (Exception e) {
throw new BBoxDBException(e);
} finally {
ssTableManager.releaseStorage(storages);
}
}
use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.
the class SamplingHelper method processTupleStores.
/**
* Process the facades for the table and create samples
* @param storages
* @param splitDimension
* @param boundingBox
* @param floatIntervals
* @return
* @throws StorageManagerException
*/
private static List<BoundingBox> processTupleStores(final List<ReadOnlyTupleStore> storages) throws StorageManagerException {
final int samplesPerStorage = 100;
final List<BoundingBox> samples = new ArrayList<>();
logger.debug("Fetching {} samples per storage", samplesPerStorage);
for (final ReadOnlyTupleStore storage : storages) {
if (!storage.acquire()) {
continue;
}
final long numberOfTuples = storage.getNumberOfTuples();
final int sampleOffset = Math.max(10, (int) (numberOfTuples / samplesPerStorage));
for (long position = 0; position < numberOfTuples; position = position + sampleOffset) {
final Tuple tuple = storage.getTupleAtPosition(position);
final BoundingBox tupleBoundingBox = tuple.getBoundingBox();
// Ignore tuples with an empty box (e.g. deleted tuples)
if (tupleBoundingBox == null || tupleBoundingBox.equals(BoundingBox.FULL_SPACE)) {
continue;
}
samples.add(tupleBoundingBox);
}
storage.release();
}
return samples;
}
use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.
the class ConnectionMainteinanceRunnable method sendKeepAlivePackage.
/**
* Build a keep alive package (with or without gossip)
* @return
* @return
*/
private EmptyResultFuture sendKeepAlivePackage() {
final TupleStoreManagerRegistry tupleStoreManagerRegistry = bboxDBClient.getTupleStoreManagerRegistry();
if (tupleStoreManagerRegistry == null) {
return bboxDBClient.sendKeepAlivePackage();
}
final List<TupleStoreName> tables = tupleStoreManagerRegistry.getAllTables();
if (tables.isEmpty()) {
return bboxDBClient.sendKeepAlivePackage();
}
lastGossipTableName = ListHelper.getElementRandom(tables);
List<ReadOnlyTupleStore> storages = new ArrayList<>();
try {
final TupleStoreManager tupleStoreManager = tupleStoreManagerRegistry.getTupleStoreManager(lastGossipTableName);
try {
storages = tupleStoreManager.aquireStorage();
if (storages.isEmpty()) {
return bboxDBClient.sendKeepAlivePackage();
}
final ReadOnlyTupleStore tupleStore = ListHelper.getElementRandom(storages);
if (tupleStore.getNumberOfTuples() > 0) {
return sendKeepAliveWithGossip(tupleStoreManager, tupleStore);
}
} catch (Exception e) {
throw e;
} finally {
tupleStoreManager.releaseStorage(storages);
}
} catch (StorageManagerException e) {
logger.error("Got exception while reading tuples", e);
}
return bboxDBClient.sendKeepAlivePackage();
}
Aggregations