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);
}
}
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;
}
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;
}
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);
}
}
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);
}
}
};
}
Aggregations