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