Search in sources :

Example 26 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException 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);
    }
}
Also used : ArrayList(java.util.ArrayList) 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 27 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class TupleStoreManagerRegistry method deleteAllTablesInDistributionGroup.

/**
 * Delete all tables that are part of the distribution group
 * @param distributionGroupName
 * @throws StorageManagerException
 */
public synchronized void deleteAllTablesInDistributionGroup(final String distributionGroupName) throws StorageManagerException {
    // Memtables
    logger.info("Shuting down active memtables for distribution group: {}", distributionGroupName);
    final Predicate<TupleStoreName> deleteTablePredicate = (t) -> (t.getDistributionGroup().equals(distributionGroupName));
    shutdownAndDeleteTablesForPredicate(deleteTablePredicate, true);
    // Delete the group dir
    for (final String directory : storages.keySet()) {
        logger.info("Deleting all local stored data for distribution group {} in path {} ", distributionGroupName, directory);
        executePendingDeletes(directory);
        deleteMedatadaOfDistributionGroup(distributionGroupName, directory);
        final String groupDirName = SSTableHelper.getDistributionGroupDir(directory, distributionGroupName);
        final File groupDir = new File(groupDirName);
        final String[] children = groupDir.list();
        if (children != null && children.length > 0) {
            final List<String> childList = Arrays.asList(children);
            throw new StorageManagerException("Unable to delete non empty dir: " + groupDirName + " / " + childList);
        }
        if (groupDir.exists()) {
            logger.debug("Deleting {}", groupDir);
            groupDir.delete();
        }
    }
}
Also used : Arrays(java.util.Arrays) Multiset(com.google.common.collect.Multiset) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SSTableHelper(org.bboxdb.storage.sstable.SSTableHelper) BBoxDBService(org.bboxdb.misc.BBoxDBService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HashMultiset(com.google.common.collect.HashMultiset) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) BBoxDBConfigurationManager(org.bboxdb.misc.BBoxDBConfigurationManager) StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ServiceState(org.bboxdb.commons.ServiceState) List(java.util.List) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreLocator(org.bboxdb.storage.tuplestore.TupleStoreLocator) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) File(java.io.File)

Example 28 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException 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();
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) File(java.io.File)

Example 29 with StorageManagerException

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

Example 30 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException 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;
}
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