Search in sources :

Example 11 with StorageManagerException

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

the class RTreeMMFReader method getEntriesForRegion.

@Override
public synchronized List<SpatialIndexEntry> getEntriesForRegion(final BoundingBox boundingBox) throws StorageManagerException {
    final List<SpatialIndexEntry> resultList = new ArrayList<>();
    final Queue<Integer> readTasks = new LinkedTransferQueue<>();
    readTasks.add(firstNodePos);
    try {
        while (!readTasks.isEmpty()) {
            final int position = readTasks.remove();
            memory.position(position);
            final DirectoryNode directoryNode = new DirectoryNode();
            directoryNode.initFromByteBuffer(memory, maxNodeSize);
            if (directoryNode.getBoundingBox().overlaps(boundingBox)) {
                readTasks.addAll(directoryNode.getChildNodes());
                final List<SpatialIndexEntry> foundEntries = directoryNode.getIndexEntries().stream().filter(e -> e.getBoundingBox().overlaps(boundingBox)).collect(Collectors.toList());
                resultList.addAll(foundEntries);
            }
        }
        return resultList;
    } catch (IOException e) {
        throw new StorageManagerException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) Logger(org.slf4j.Logger) DataEncoderHelper(org.bboxdb.commons.io.DataEncoderHelper) UnsafeMemoryHelper(org.bboxdb.commons.io.UnsafeMemoryHelper) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) AbstractRTreeReader(org.bboxdb.storage.sstable.spatialindex.rtree.AbstractRTreeReader) List(java.util.List) Queue(java.util.Queue) StorageManagerException(org.bboxdb.storage.StorageManagerException) FileChannel(java.nio.channels.FileChannel) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) MappedByteBuffer(java.nio.MappedByteBuffer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 12 with StorageManagerException

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

the class TupleStoreLocator method scanDirectoryForExistingTables.

/**
 * Scan the given directory for existing sstables
 * @param storageDirectory
 * @return
 * @throws StorageManagerException
 */
public static Map<TupleStoreName, String> scanDirectoryForExistingTables(final String storageDirectory) throws StorageManagerException {
    final String dataDirString = SSTableHelper.getDataDir(storageDirectory);
    final File dataDir = new File(dataDirString);
    if (!dataDir.exists()) {
        throw new StorageManagerException("Root dir does not exist: " + dataDir);
    }
    final Map<TupleStoreName, String> sstableLocations = new HashMap<>();
    // Distribution groups
    for (final File fileEntry : dataDir.listFiles()) {
        if (!fileEntry.isDirectory()) {
            continue;
        }
        final String distributionGroup = fileEntry.getName();
        assert (DistributionGroupHelper.validateDistributionGroupName(distributionGroup)) : "Invalid name: " + distributionGroup;
        final Map<TupleStoreName, String> tablesInDir = handleDistributionGroupEntry(storageDirectory, fileEntry, distributionGroup);
        sstableLocations.putAll(tablesInDir);
    }
    return sstableLocations;
}
Also used : HashMap(java.util.HashMap) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) File(java.io.File)

Example 13 with StorageManagerException

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

the class KeepAliveHandler method checkLocalTuples.

/**
 * @param tupleStoreManagerRegistry
 * @param tupleStoreName
 * @param tuple
 * @throws BBoxDBException
 * @throws StorageManagerException
 */
private boolean checkLocalTuples(final TupleStoreManagerRegistry tupleStoreManagerRegistry, final TupleStoreName tupleStoreName, final Tuple tuple) throws BBoxDBException {
    final String fullname = tupleStoreName.getDistributionGroup();
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
    final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
    final Collection<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(tuple.getBoundingBox(), tupleStoreName);
    for (final TupleStoreName localTupleStoreName : localTables) {
        try {
            final TupleStoreManager storageManager = tupleStoreManagerRegistry.getTupleStoreManager(localTupleStoreName);
            final String key = tuple.getKey();
            final List<Tuple> localTuples = storageManager.get(key);
            if (localTables.isEmpty()) {
                logger.error("Got empty tuple list during gossip");
                return false;
            }
            final List<Long> localVersions = getSortedVersionList(localTuples);
            final long gossipTupleVersion = tuple.getVersionTimestamp();
            return checkLocalTupleVersions(localVersions, gossipTupleVersion, key);
        } catch (StorageManagerException e) {
            logger.error("Got exception while reading tuples", e);
        }
    }
    return true;
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Tuple(org.bboxdb.storage.entity.Tuple) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 14 with StorageManagerException

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

the class SSTableFacade method init.

@Override
public void init() throws InterruptedException, BBoxDBException {
    try {
        if (ssTableReader == null || ssTableKeyIndexReader == null) {
            logger.warn("init called but sstable reader or index reader is null");
            return;
        }
        ssTableReader.init();
        ssTableKeyIndexReader.init();
        ssTableKeyIndexReader.activateKeyCache(keyCacheElements);
        // Spatial index
        final File spatialIndexFile = getSpatialIndexFile(directory, tablename, tablenumber);
        loadSpatialIndex(spatialIndexFile);
        // Bloom filter
        final File bloomFilterFile = getBloomFilterFile(directory, tablename, tablenumber);
        loadBloomFilter(bloomFilterFile);
    } catch (StorageManagerException e) {
        throw new BBoxDBException(e);
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 15 with StorageManagerException

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

the class SSTableFacade method getAllTuplesInBoundingBox.

@Override
public Iterator<Tuple> getAllTuplesInBoundingBox(final BoundingBox boundingBox) {
    assert (usage.get() > 0);
    List<SpatialIndexEntry> entries;
    try {
        entries = spatialIndex.getEntriesForRegion(boundingBox);
    } catch (StorageManagerException e) {
        throw new RuntimeException(e);
    }
    final Iterator<SpatialIndexEntry> entryIterator = entries.iterator();
    return new Iterator<Tuple>() {

        @Override
        public boolean hasNext() {
            return entryIterator.hasNext();
        }

        @Override
        public Tuple next() {
            final SpatialIndexEntry entry = entryIterator.next();
            final int tuplePosition = entry.getValue();
            try {
                return ssTableReader.getTupleAtPosition(tuplePosition);
            } catch (StorageManagerException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

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