use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.
the class TupleStoreManager method get.
/**
* Search for the most recent version of the tuple
* @param key
* @return The tuple or null
* @throws StorageManagerException
*/
public List<Tuple> get(final String key) throws StorageManagerException {
if (!serviceState.isInRunningState()) {
throw new StorageManagerException("Storage manager is not ready: " + tupleStoreName.getFullname() + " state: " + serviceState);
}
final Summary.Timer requestTimer = getRequestLatency.startTimer();
final List<ReadOnlyTupleStore> aquiredStorages = new ArrayList<>();
final List<Tuple> tupleList = new ArrayList<>();
try {
aquiredStorages.addAll(aquireStorage());
for (final ReadOnlyTupleStore tupleStorage : aquiredStorages) {
final List<Tuple> resultTuples = tupleStorage.get(key);
tupleList.addAll(resultTuples);
}
} catch (Exception e) {
throw e;
} finally {
releaseStorage(aquiredStorages);
requestTimer.observeDuration();
}
final DuplicateResolver<Tuple> resolver = TupleDuplicateResolverFactory.build(tupleStoreConfiguration);
resolver.removeDuplicates(tupleList);
return tupleList;
}
use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.
the class TupleStoreManager method createSSTableDirIfNeeded.
/**
* Ensure that the directory for the given table exists
* @throws StorageManagerException
*/
protected void createSSTableDirIfNeeded() throws StorageManagerException {
final String storageDir = storage.getBasedir().getAbsolutePath();
final String dgroupDir = SSTableHelper.getDistributionGroupDir(storageDir, tupleStoreName);
final File dgroupDirHandle = new File(dgroupDir);
if (!dgroupDirHandle.exists()) {
logger.info("Create a new directory for dgroup {} ({})", tupleStoreName.getDistributionGroup(), dgroupDir);
final boolean mkdirResult = dgroupDirHandle.mkdirs();
assert (mkdirResult == true) : "Unable to create dir: " + dgroupDirHandle;
try {
writeDistributionGroupMetaData();
} catch (Exception e) {
logger.error("Unable to write meta data", e);
}
}
final String ssTableDir = SSTableHelper.getSSTableDir(storageDir, tupleStoreName);
final File ssTableDirHandle = new File(ssTableDir);
if (!ssTableDirHandle.exists()) {
logger.info("Create a new dir for table {} ({}) ", tupleStoreName.getFullname(), ssTableDirHandle);
ssTableDirHandle.mkdir();
}
}
use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.
the class TupleStoreManager method aquireStorage.
/**
* Try to acquire all needed tables
* @return
* @throws StorageManagerException
*/
public List<ReadOnlyTupleStore> aquireStorage() throws StorageManagerException {
for (int execution = 0; execution < Const.OPERATION_RETRY; execution++) {
final List<ReadOnlyTupleStore> aquiredStorages = new ArrayList<>();
final List<ReadOnlyTupleStore> knownStorages = tupleStoreInstances.getAllTupleStorages();
for (final ReadOnlyTupleStore tupleStorage : knownStorages) {
final boolean canBeUsed = tupleStorage.acquire();
if (!canBeUsed) {
if (execution == Const.OPERATION_RETRY - 1) {
logger.error("Unable to aquire: {} with {} retries", tupleStorage, execution);
}
break;
} else {
aquiredStorages.add(tupleStorage);
}
}
if (knownStorages.size() == aquiredStorages.size()) {
return aquiredStorages;
} else {
// one or more storages could not be acquired
// release storages and retry
releaseStorage(aquiredStorages);
try {
// Wait some time and try again
Thread.sleep(10);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
throw new StorageManagerException("Unable to aquire all sstables in " + Const.OPERATION_RETRY + " retries");
}
use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.
the class TupleStoreManager method checkSSTableDir.
/**
* Ensure that the storage directory does exist
*
* @param directoryHandle
* @throws StorageManagerException
*/
public void checkSSTableDir(final File directoryHandle) throws StorageManagerException {
if (!directoryHandle.isDirectory()) {
final String message = "Storage directory is not an directory: " + directoryHandle;
final StorageManagerException exception = new StorageManagerException(message);
serviceState.dispatchToFailed(exception);
logger.error(message);
throw exception;
}
}
use of org.bboxdb.storage.StorageManagerException 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