use of org.bboxdb.storage.tuplestore.DiskStorage 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.DiskStorage in project bboxdb by jnidzwetzki.
the class TupleStoreManagerRegistry method init.
/**
* Init the service
* @throws BBoxDBException
*/
@Override
public synchronized void init() throws InterruptedException, BBoxDBException {
if (!serviceState.isInNewState()) {
throw new BBoxDBException("Unable to init service is in state: " + serviceState.getState());
}
serviceState.dipatchToStarting();
final List<String> storageDirs = configuration.getStorageDirectories();
if (storageDirs.isEmpty()) {
throw new IllegalArgumentException("Unable to init storage registry without any data directory");
}
// Populate the sstable location map
for (final String directory : storageDirs) {
try {
tupleStoreLocations.putAll(TupleStoreLocator.scanDirectoryForExistingTables(directory));
final int flushThreadsPerStorage = configuration.getMemtableFlushThreadsPerStorage();
final DiskStorage storage = new DiskStorage(this, new File(directory), flushThreadsPerStorage);
storage.init();
storages.put(directory, storage);
} catch (StorageManagerException e) {
final String dataDirString = SSTableHelper.getDataDir(directory);
logger.error("Directory {} does not exists, exiting...", dataDirString);
System.exit(-1);
}
}
serviceState.dispatchToRunning();
}
use of org.bboxdb.storage.tuplestore.DiskStorage in project bboxdb by jnidzwetzki.
the class TupleStoreManagerRegistry method deleteTable.
/**
* Delete the given table
* @param table
* @throws StorageManagerException
*/
public void deleteTable(final TupleStoreName table, final boolean synchronous) throws StorageManagerException {
if (!table.isValid()) {
throw new StorageManagerException("Invalid tablename: " + table);
}
String storageDirectory = null;
synchronized (this) {
if (managerInstances.containsKey(table)) {
shutdownSStable(table);
}
if (!tupleStoreLocations.containsKey(table)) {
logger.error("Table {} not known during deletion", table.getFullname());
return;
}
storageDirectory = tupleStoreLocations.get(table);
tupleStoreLocations.remove(table);
}
final DiskStorage storage = storages.get(storageDirectory);
logger.info("Deleting table {} synchronous {}", table.getFullname(), synchronous);
if (synchronous) {
TupleStoreManager.deletePersistentTableData(storageDirectory, table);
} else {
storage.getPendingTableDeletions().add(table);
}
}
use of org.bboxdb.storage.tuplestore.DiskStorage in project bboxdb by jnidzwetzki.
the class TupleStoreManagerRegistry method createTable.
/**
* Create a new table
* @param tupleStoreName
* @param configuration
* @return
* @throws StorageManagerException
*/
public synchronized TupleStoreManager createTable(final TupleStoreName tupleStoreName, final TupleStoreConfiguration tupleStoreConfiguration) throws StorageManagerException {
// Find a new storage directory for the sstable manager
if (tupleStoreLocations.containsKey(tupleStoreName)) {
throw new StorageManagerException("Table already exist");
}
final String location = getLocationLowestUtilizedDataLocation();
tupleStoreLocations.put(tupleStoreName, location);
final DiskStorage storage = storages.get(location);
final TupleStoreManager tupleStoreManager = new TupleStoreManager(storage, tupleStoreName, configuration);
tupleStoreManager.create(tupleStoreConfiguration);
tupleStoreManager.init();
managerInstances.put(tupleStoreName, tupleStoreManager);
return tupleStoreManager;
}
use of org.bboxdb.storage.tuplestore.DiskStorage in project bboxdb by jnidzwetzki.
the class TupleStoreManagerRegistry method getTupleStoreManager.
/**
* Get the storage manager for a given table. If the storage manager does not
* exist, it will be created
*
* @return
*/
public synchronized TupleStoreManager getTupleStoreManager(final TupleStoreName tupleStoreName) throws StorageManagerException {
if (!tupleStoreName.isValid()) {
throw new StorageManagerException("Invalid tablename: " + tupleStoreName);
}
zookeeperObserver.registerTable(tupleStoreName);
// Instance is known
if (managerInstances.containsKey(tupleStoreName)) {
return managerInstances.get(tupleStoreName);
}
// Find a new storage directory for the sstable manager
if (!tupleStoreLocations.containsKey(tupleStoreName)) {
throw new StorageManagerException("Unknown location for table " + tupleStoreName.getFullname() + " does the table exist?");
}
final String location = tupleStoreLocations.get(tupleStoreName);
final DiskStorage storage = storages.get(location);
final TupleStoreManager sstableManager = new TupleStoreManager(storage, tupleStoreName, configuration);
sstableManager.init();
managerInstances.put(tupleStoreName, sstableManager);
return sstableManager;
}
Aggregations