Search in sources :

Example 16 with StorageManagerException

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

the class SSTableKeyIndexReader method iterator.

/**
 * Iterate over the tuples in the sstable
 */
@Override
public Iterator<Tuple> iterator() {
    return new Iterator<Tuple>() {

        protected int entry = 0;

        protected int lastEntry = getNumberOfEntries() - 1;

        @Override
        public boolean hasNext() {
            return entry <= lastEntry;
        }

        @Override
        public Tuple next() {
            if (entry > lastEntry) {
                throw new IllegalStateException("Requesting wrong position: " + entry + " of " + lastEntry);
            }
            try {
                final Tuple tuple = sstableReader.getTupleAtPosition(convertEntryToPosition(entry));
                entry++;
                return tuple;
            } catch (StorageManagerException e) {
                logger.error("Got exception while iterating (requesting entry " + (entry - 1) + " of " + lastEntry + ")", e);
            }
            return null;
        }

        @Override
        public void remove() {
            throw new IllegalStateException("Remove is not supported");
        }
    };
}
Also used : Iterator(java.util.Iterator) StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 17 with StorageManagerException

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

the class SSTableKeyIndexReader method getPositionsForTuple.

/**
 * Scan the index file for the tuple position
 * @param key
 * @return
 * @throws StorageManagerException
 */
public List<Integer> getPositionsForTuple(final String key) throws StorageManagerException {
    try {
        int firstEntry = 0;
        int lastEntry = getNumberOfEntries() - 1;
        // Check key is > then first value
        final String firstValue = getKeyForIndexEntry(firstEntry);
        if (firstValue.equals(key)) {
            return fillKeyPositionArrayFromIndexEntry(key, firstEntry);
        }
        // Not found
        if (firstValue.compareTo(key) > 0) {
            return new ArrayList<>();
        }
        // Check if key is < then first value
        final String lastValue = getKeyForIndexEntry(lastEntry);
        if (lastValue.equals(key)) {
            return fillKeyPositionArrayFromIndexEntry(key, lastEntry);
        }
        // Not found
        if (lastValue.compareTo(key) < 0) {
            return new ArrayList<>();
        }
        // Binary search for key
        do {
            int curEntry = (int) ((lastEntry - firstEntry) / 2.0) + firstEntry;
            /*				if(logger.isDebugEnabled()) {
					logger.debug("Low: " + firstEntry + " Up: " + lastEntry + " Pos: " + curEntry);
				}*/
            final String curEntryValue = getKeyForIndexEntry(curEntry);
            if (curEntryValue.equals(key)) {
                return fillKeyPositionArrayFromIndexEntry(key, curEntry);
            }
            if (key.compareTo(curEntryValue) > 0) {
                firstEntry = curEntry + 1;
            } else {
                lastEntry = curEntry - 1;
            }
        } while (firstEntry <= lastEntry);
    } catch (IOException e) {
        throw new StorageManagerException("Error while reading index file", e);
    }
    // Not found during binary scan
    return new ArrayList<>();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 18 with StorageManagerException

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

the class SSTableReader method getTupleAtPosition.

/**
 * Get tuple at the given position
 *
 * @param position
 * @return The tuple
 * @throws StorageManagerException
 */
public synchronized Tuple getTupleAtPosition(final int position) throws StorageManagerException {
    try {
        // The memory was unmapped
        if (memory == null) {
            logger.warn("Read request to unmapped memory for relation: " + name);
            return null;
        }
        memory.position(position);
        final Tuple tuple = TupleHelper.decodeTuple(memory);
        final int newPosition = memory.position();
        final int readBytes = newPosition - position;
        readTuplesTotal.inc();
        readTuplesBytes.inc(readBytes);
        return tuple;
    } catch (Exception e) {
        try {
            throw new StorageManagerException("Exception while decoding Position: " + position + " Size " + fileChannel.size(), e);
        } catch (IOException e1) {
            throw new StorageManagerException(e);
        }
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) Tuple(org.bboxdb.storage.entity.Tuple) IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 19 with StorageManagerException

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

the class SSTableCheckpointRunnable method createCheckpointIfNeeded.

/**
 * Create a checkpoint if needed
 * @param storageRegistry
 * @param ssTableName
 */
protected void createCheckpointIfNeeded(final TupleStoreManagerRegistry storageRegistry, final TupleStoreName ssTableName) {
    try {
        final TupleStoreManager ssTableManager = storageRegistry.getTupleStoreManager(ssTableName);
        createCheckpoint(ssTableManager);
    } catch (InterruptedException e) {
        logger.debug("Got interrupted exception, stopping checkpoint thread");
        Thread.currentThread().interrupt();
    } catch (StorageManagerException e) {
        logger.error("Got exception while creating checkpoint", e);
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 20 with StorageManagerException

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

the class ContinuousBoundingBoxClientQuery method init.

/**
 * Init the query
 * @param tupleStoreManagerRegistry
 * @throws BBoxDBException
 */
protected void init() throws BBoxDBException {
    try {
        final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
        final String fullname = requestTable.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
        final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
        final List<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(boundingBox, requestTable);
        if (localTables.size() != 1) {
            logger.error("Got more than one table for the continuous query {}", localTables);
            close();
            return;
        }
        final TupleStoreName tupleStoreName = localTables.get(0);
        storageManager = QueryHelper.getTupleStoreManager(storageRegistry, tupleStoreName);
        storageManager.registerInsertCallback(tupleInsertCallback);
        // Remove tuple store insert listener on connection close
        clientConnectionHandler.addConnectionClosedHandler((c) -> close());
    } catch (StorageManagerException | ZookeeperException e) {
        logger.error("Got an exception during query init", e);
        close();
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

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