Search in sources :

Example 96 with Tuple

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

the class SSTableWriter method addData.

/**
 * Add the list of tuples to the sstable
 * @param tuples
 * @throws StorageManagerException
 */
public void addData(final List<Tuple> tuples) throws StorageManagerException {
    if (sstableOutputStream == null) {
        final String error = "Trying to add a memtable to a non ready SSTable writer";
        logger.error(error);
        throw new StorageManagerException(error);
    }
    try {
        for (final Tuple tuple : tuples) {
            addNextTuple(tuple);
        }
    } catch (StorageManagerException e) {
        exceptionDuringWrite = true;
        throw e;
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 97 with Tuple

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

the class SSTableCompactor method executeCompactation.

/**
 * Execute the compactation of the input sstables
 *
 * @return success or failure
 */
public void executeCompactation() throws StorageManagerException {
    try {
        // The iterators
        final List<Iterator<Tuple>> iterators = sstableIndexReader.stream().map(r -> r.iterator()).collect(Collectors.toList());
        final DuplicateResolver<Tuple> newestKeyResolver = TupleDuplicateResolverFactory.build(tupleStoreManager.getTupleStoreConfiguration());
        final SortedIteratorMerger<Tuple> sortedIteratorMerger = new SortedIteratorMerger<>(iterators, TupleHelper.TUPLE_KEY_COMPARATOR, newestKeyResolver);
        for (final Tuple tuple : sortedIteratorMerger) {
            checkForThreadTermination();
            addTupleToWriter(tuple);
        }
        readTuples = sortedIteratorMerger.getReadElements();
    } catch (StorageManagerException e) {
        handleErrorDuringCompact();
        throw e;
    } finally {
        closeSSTableWriter();
    }
}
Also used : SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Tuple(org.bboxdb.storage.entity.Tuple) TupleHelper(org.bboxdb.storage.util.TupleHelper) LoggerFactory(org.slf4j.LoggerFactory) SSTableConst(org.bboxdb.storage.sstable.SSTableConst) SortedIteratorMerger(org.bboxdb.commons.SortedIteratorMerger) Collectors(java.util.stream.Collectors) TupleDuplicateResolverFactory(org.bboxdb.storage.sstable.duplicateresolver.TupleDuplicateResolverFactory) ArrayList(java.util.ArrayList) DuplicateResolver(org.bboxdb.commons.DuplicateResolver) List(java.util.List) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) StorageManagerException(org.bboxdb.storage.StorageManagerException) Iterator(java.util.Iterator) SortedIteratorMerger(org.bboxdb.commons.SortedIteratorMerger) StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Example 98 with Tuple

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

the class KeepAliveHandler method checkLocalTuples.

/**
 * @param tupleStoreManagerRegistry
 * @param tupleStoreName
 * @param tuple
 * @throws BBoxDBException
 * @throws StorageManagerException
 */
private boolean checkLocalTuples(final TupleStoreManagerRegistry tupleStoreManagerRegistry, final TupleStoreName tupleStoreName, final Tuple tuple) throws BBoxDBException {
    final String fullname = tupleStoreName.getDistributionGroup();
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
    final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
    final Collection<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(tuple.getBoundingBox(), tupleStoreName);
    for (final TupleStoreName localTupleStoreName : localTables) {
        try {
            final TupleStoreManager storageManager = tupleStoreManagerRegistry.getTupleStoreManager(localTupleStoreName);
            final String key = tuple.getKey();
            final List<Tuple> localTuples = storageManager.get(key);
            if (localTables.isEmpty()) {
                logger.error("Got empty tuple list during gossip");
                return false;
            }
            final List<Long> localVersions = getSortedVersionList(localTuples);
            final long gossipTupleVersion = tuple.getVersionTimestamp();
            return checkLocalTupleVersions(localVersions, gossipTupleVersion, key);
        } catch (StorageManagerException e) {
            logger.error("Got exception while reading tuples", e);
        }
    }
    return true;
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Tuple(org.bboxdb.storage.entity.Tuple) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 99 with Tuple

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

the class NewestTupleDuplicateResolver method removeDuplicates.

@Override
public void removeDuplicates(final List<Tuple> unconsumedDuplicates) {
    Tuple newestTuple = null;
    for (final Tuple tuple : unconsumedDuplicates) {
        newestTuple = TupleHelper.returnMostRecentTuple(newestTuple, tuple);
    }
    unconsumedDuplicates.clear();
    if (newestTuple != null) {
        unconsumedDuplicates.add(newestTuple);
    }
}
Also used : Tuple(org.bboxdb.storage.entity.Tuple)

Example 100 with Tuple

use of org.bboxdb.storage.entity.Tuple 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");
        }
    };
}
Also used : Iterator(java.util.Iterator) StorageManagerException(org.bboxdb.storage.StorageManagerException) 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