Search in sources :

Example 1 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName 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)

Example 2 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class KeyClientQuery method computeTuples.

/**
 * Fetch the tuples for the given key and remove the duplicates
 */
protected void computeTuples() {
    try {
        final String fullname = requestTable.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
        final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
        final List<TupleStoreName> localTables = regionIdMapper.getAllLocalTables(requestTable);
        for (final TupleStoreName tupleStoreName : localTables) {
            final TupleStoreManager storageManager = clientConnectionHandler.getStorageRegistry().getTupleStoreManager(tupleStoreName);
            final List<Tuple> tuplesInTable = storageManager.get(key);
            tuplesForKey.addAll(tuplesInTable);
        }
        removeDuplicates(localTables);
    } catch (BBoxDBException | StorageManagerException e) {
        logger.error("Got an exception while fetching tuples for key " + key, e);
        tuplesForKey.clear();
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 3 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class StreamClientQuery method determineLocalTables.

/**
 * Determine the local tables
 * @param requestTables
 */
private void determineLocalTables(final List<TupleStoreName> requestTables) {
    try {
        for (final TupleStoreName requestTable : requestTables) {
            final String fullname = requestTable.getDistributionGroup();
            final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
            final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
            final List<TupleStoreName> localTablesForTable = regionIdMapper.getAllLocalTables(requestTable);
            localTablesForTable.sort((c1, c2) -> c1.compareTo(c2));
            localTables.put(requestTable, localTablesForTable);
        }
        // Check all tables have the same amount of local tables
        int elementSize = -1;
        for (final List<TupleStoreName> elements : localTables.values()) {
            if (elementSize == -1) {
                elementSize = elements.size();
            }
            if (elementSize != elements.size()) {
                throw new IllegalArgumentException("Got invalid element size: " + elementSize + " / " + elements.size());
            }
        }
    } catch (BBoxDBException e) {
        logger.error("Got exception while reading local tables", e);
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 4 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class StreamClientQuery method setupNewIterator.

/**
 * Setup a new iterator with the next local table
 */
protected boolean setupNewIterator() {
    if (activeOperatorIterator != null && !activeOperatorIterator.hasNext()) {
        logger.warn("setupNewIterator() called, but old iterator is not exhaustet. Ignoring call");
        return false;
    }
    if (getNumberOfTablesToProcess() == 0) {
        logger.warn("setupNewIterator() called, but localTables are empty");
        return false;
    }
    try {
        final List<TupleStoreManager> storageManagers = new ArrayList<>();
        final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
        for (final TupleStoreName tupleStoreName : requestTables) {
            final TupleStoreName sstableName = localTables.get(tupleStoreName).remove(0);
            final TupleStoreManager storageManager = QueryHelper.getTupleStoreManager(storageRegistry, sstableName);
            storageManagers.add(storageManager);
        }
        activeOperator = operatorTreeBuilder.buildOperatorTree(storageManagers);
        activeOperatorIterator = activeOperator.iterator();
        return true;
    } catch (StorageManagerException | ZookeeperException e) {
        logger.warn("Got exception while fetching tuples", e);
    }
    return false;
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 5 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class HandleBoundingBoxQuery method handleQuery.

@Override
public /**
 * Handle a bounding box 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 already known, please close old query first", packageSequence);
            return;
        }
        final QueryBoundingBoxRequest queryRequest = QueryBoundingBoxRequest.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 BoundingBox boundingBox = queryRequest.getBoundingBox();
                final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
                return operator;
            }
        };
        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));
    }
}
Also used : QueryBoundingBoxRequest(org.bboxdb.network.packages.request.QueryBoundingBoxRequest) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) 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)

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