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;
}
}
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();
}
}
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;
}
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);
}
}
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");
}
};
}
Aggregations