Search in sources :

Example 36 with StorageManagerException

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;
}
Also used : ArrayList(java.util.ArrayList) Summary(io.prometheus.client.Summary) StorageManagerException(org.bboxdb.storage.StorageManagerException) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple) RejectedException(org.bboxdb.commons.RejectedException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 37 with StorageManagerException

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();
    }
}
Also used : File(java.io.File) RejectedException(org.bboxdb.commons.RejectedException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 38 with StorageManagerException

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");
}
Also used : ArrayList(java.util.ArrayList) StorageManagerException(org.bboxdb.storage.StorageManagerException) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore)

Example 39 with StorageManagerException

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;
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 40 with StorageManagerException

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;
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage)

Aggregations

StorageManagerException (org.bboxdb.storage.StorageManagerException)48 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)14 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)12 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)8 File (java.io.File)7 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)7 ReadOnlyTupleStore (org.bboxdb.storage.tuplestore.ReadOnlyTupleStore)6 List (java.util.List)5 RejectedException (org.bboxdb.commons.RejectedException)5 SpatialIndexEntry (org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)5 DiskStorage (org.bboxdb.storage.tuplestore.DiskStorage)5 RandomAccessFile (java.io.RandomAccessFile)4 Collectors (java.util.stream.Collectors)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)4 SSTableFacade (org.bboxdb.storage.sstable.reader.SSTableFacade)4