Search in sources :

Example 71 with TupleStoreName

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);
    }
}
Also used : QueryKeyRequest(org.bboxdb.network.packages.request.QueryKeyRequest) KeyClientQuery(org.bboxdb.network.server.KeyClientQuery) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ClientQuery(org.bboxdb.network.server.ClientQuery) KeyClientQuery(org.bboxdb.network.server.KeyClientQuery) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 72 with TupleStoreName

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;
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) QueryVersionTimeRequest(org.bboxdb.network.packages.request.QueryVersionTimeRequest) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 73 with TupleStoreName

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;
        }
    }
}
Also used : SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName)

Example 74 with TupleStoreName

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());
            }
        }
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) StorageManagerException(org.bboxdb.storage.StorageManagerException) ExecutionException(java.util.concurrent.ExecutionException)

Example 75 with TupleStoreName

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);
    }
}
Also used : ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9