use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleKeyQuery method handleQuery.
@Override
public /**
* Handle a key query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
final Runnable queryRunable = new ExceptionSafeRunnable() {
@Override
public void runThread() throws Exception {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
return;
}
final QueryKeyRequest queryKeyRequest = QueryKeyRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryKeyRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final String key = queryKeyRequest.getKey();
final ClientQuery clientQuery = new KeyClientQuery(key, queryKeyRequest.isPagingEnabled(), queryKeyRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, requestTable);
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
@Override
protected void afterExceptionHook() {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackageNE(responsePackage);
}
};
// Submit the runnable to our pool
if (clientConnectionHandler.getThreadPool().isShutdown()) {
logger.warn("Thread pool is shutting down, don't execute query: {}", packageSequence);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_SHUTDOWN);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
clientConnectionHandler.getThreadPool().submit(queryRunable);
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleVersionTimeQuery method handleQuery.
@Override
public /**
* Handle a time query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
return;
}
final QueryVersionTimeRequest queryRequest = QueryVersionTimeRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() != 1) {
throw new IllegalArgumentException("This operator tree needs 1 storage manager");
}
final FullTablescanOperator tablescanOperator = new FullTablescanOperator(storageManager.get(0));
final long timestamp = queryRequest.getTimestamp();
final Operator opeator = new NewerAsVersionTimeSelectionOperator(timestamp, tablescanOperator);
return opeator;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
return;
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class MemtableWriterRunnable method flushMemtableToDisk.
/**
* Flush a memtable to disk
* @param memtable
* @param sstableManager
*/
protected void flushMemtableToDisk(final Memtable memtable, final TupleStoreManager sstableManager) {
SSTableFacade facade = null;
try {
// Don't write empty memtables to disk
if (!memtable.isEmpty()) {
final TupleStoreName sstableName = sstableManager.getTupleStoreName();
final String dataDirectory = basedir.getAbsolutePath();
final int tableNumber = writeMemtable(dataDirectory, memtable, sstableManager);
final int sstableKeyCacheEntries = storage.getTupleStoreManagerRegistry().getConfiguration().getSstableKeyCacheEntries();
facade = new SSTableFacade(dataDirectory, sstableName, tableNumber, sstableKeyCacheEntries);
facade.init();
}
sstableManager.replaceMemtableWithSSTable(memtable, facade);
sendCallbacks(memtable, sstableManager);
memtable.deleteOnClose();
memtable.release();
} catch (Throwable e) {
deleteWrittenFacade(facade);
if (sstableManager.getSstableManagerState() == TupleStoreManagerState.READ_ONLY) {
logger.debug("Rejected memtable write:", e);
return;
}
logger.error("Exception while flushing memtable", e);
if (Thread.currentThread().isInterrupted()) {
logger.debug("Got Exception while flushing memtable, but thread was interrupted. " + "Ignoring exception.");
Thread.currentThread().interrupt();
return;
}
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class DistributedRecoveryService method handleOutdatedRegions.
/**
* Handle the outdated distribution regions
* @param distributionGroupName
* @param outdatedRegions
*/
protected void handleOutdatedRegions(final String distributionGroupName, final List<OutdatedDistributionRegion> outdatedRegions) {
for (final OutdatedDistributionRegion outdatedDistributionRegion : outdatedRegions) {
final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(outdatedDistributionRegion.getNewestInstance());
final long regionId = outdatedDistributionRegion.getDistributedRegion().getRegionId();
final List<TupleStoreName> allTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(storageRegistry, distributionGroupName, regionId);
for (final TupleStoreName ssTableName : allTables) {
try {
runRecoveryForTable(ssTableName, outdatedDistributionRegion, connection.getBboxDBClient());
} catch (RejectedException | StorageManagerException | ExecutionException e) {
logger.error("Got an exception while performing recovery for table: " + ssTableName.getFullname());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Got an exception while performing recovery for table: " + ssTableName.getFullname());
}
}
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class RegionMerger method mergeDataByLocalRead.
/**
* Merge data by local data read
*
* @param region
* @param tupleStoreName
* @param tupleRedistributor
* @param childRegion
* @throws StorageManagerException
* @throws TupleStoreManagerRegistry
*/
private void mergeDataByLocalRead(final DistributionRegion region, final TupleStoreName tupleStoreName, final TupleRedistributor tupleRedistributor, final DistributionRegion childRegion) throws StorageManagerException {
final long regionId = region.getRegionId();
final TupleStoreName childRegionName = tupleStoreName.cloneWithDifferntRegionId(regionId);
final TupleStoreManager tupleStoreManager = registry.getTupleStoreManager(childRegionName);
final List<ReadOnlyTupleStore> storages = new ArrayList<>();
try {
storages.addAll(tupleStoreManager.aquireStorage());
for (final ReadOnlyTupleStore storage : storages) {
for (final Tuple tuple : storage) {
tupleRedistributor.redistributeTuple(tuple);
}
}
} catch (Exception e) {
throw e;
} finally {
tupleStoreManager.releaseStorage(storages);
}
}
Aggregations