Search in sources :

Example 1 with Tuple

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

the class ContinuousBoundingBoxClientQuery method fetchAndSendNextTuples.

@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
    try {
        long sendTuplesInThisPage = 0;
        clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
        while (queryActive) {
            if (sendTuplesInThisPage >= tuplesPerPage) {
                clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
                clientConnectionHandler.flushPendingCompressionPackages();
                return;
            }
            // Send next tuple or wait
            final Tuple tuple = tupleQueue.take();
            final JoinedTuple joinedTuple = new JoinedTuple(tuple, requestTable.getFullname());
            clientConnectionHandler.writeResultTuple(packageSequence, joinedTuple);
            totalSendTuples++;
            sendTuplesInThisPage++;
        }
        // All tuples are send
        clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
        clientConnectionHandler.flushPendingCompressionPackages();
    } catch (InterruptedException e) {
        logger.debug("Got interrupted excetion");
        close();
        Thread.currentThread().interrupt();
    }
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 2 with Tuple

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

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

the class JoinedTupleResponse method decodePackage.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 */
public static JoinedTupleResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_JOINED_TUPLE);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final List<String> tupleStoreNames = new ArrayList<>();
    final List<Tuple> tuples = new ArrayList<>();
    final int numberOfTuples = encodedPackage.getInt();
    for (int i = 0; i < numberOfTuples; i++) {
        final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
        tupleStoreNames.add(tupleAndTable.getTable());
        tuples.add(tupleAndTable.getTuple());
    }
    final JoinedTuple joinedTuple = new JoinedTuple(tuples, tupleStoreNames);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after encoding: " + encodedPackage.remaining());
    }
    return new JoinedTupleResponse(requestId, joinedTuple);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 4 with Tuple

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

the class RequestWorker method runThread.

@Override
protected void runThread() throws Exception {
    while (!Thread.currentThread().isInterrupted()) {
        try {
            final TupleListFuture future = queue.take();
            synchronized (activeWorker) {
                activeWorker.incrementAndGet();
                activeWorker.notifyAll();
            }
            if (future != null) {
                future.waitForAll();
                final Iterator<Tuple> iter = future.iterator();
                while (iter.hasNext()) {
                    iter.next();
                }
            }
            synchronized (activeWorker) {
                activeWorker.decrementAndGet();
                activeWorker.notifyAll();
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
    }
}
Also used : TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) Tuple(org.bboxdb.storage.entity.Tuple)

Example 5 with Tuple

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

the class NetworkTupleEncoderDecoder method decode.

/**
 * Convert a ByteBuffer into a TupleAndTable object
 * @param encodedPackage
 * @return
 */
public static TupleAndTable decode(final ByteBuffer encodedPackage) {
    final short tableLength = encodedPackage.getShort();
    final short keyLength = encodedPackage.getShort();
    final int bBoxLength = encodedPackage.getInt();
    final int dataLength = encodedPackage.getInt();
    final long timestamp = encodedPackage.getLong();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] keyBytes = new byte[keyLength];
    encodedPackage.get(keyBytes, 0, keyBytes.length);
    final String key = new String(keyBytes);
    final byte[] boxBytes = new byte[bBoxLength];
    encodedPackage.get(boxBytes, 0, boxBytes.length);
    final byte[] dataBytes = new byte[dataLength];
    encodedPackage.get(dataBytes, 0, dataBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
    Tuple tuple = null;
    if (TupleHelper.isDeletedTuple(boxBytes, dataBytes)) {
        tuple = new DeletedTuple(key, timestamp);
    } else {
        tuple = new Tuple(key, boundingBox, dataBytes, timestamp);
    }
    return new TupleAndTable(tuple, table);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Tuple(org.bboxdb.storage.entity.Tuple)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)198 Test (org.junit.Test)123 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)104 BoundingBox (org.bboxdb.commons.math.BoundingBox)62 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)58 ArrayList (java.util.ArrayList)41 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)25 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)24 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)18 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)18 ByteBuffer (java.nio.ByteBuffer)17 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)13 IOException (java.io.IOException)11 List (java.util.List)11 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)11 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)11 StorageManagerException (org.bboxdb.storage.StorageManagerException)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11