use of de.invesdwin.util.collections.iterable.ATransformingIterable in project invesdwin-context-persistence by subes.
the class HeapLiveSegment method rangeReverseValues.
@Override
public ICloseableIterable<V> rangeReverseValues(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
// we expect the read lock to be already locked from the outside
if (values == null || from != null && to != null && from.isBeforeNotNullSafe(to)) {
return EmptyCloseableIterable.getInstance();
}
if (from != null && !firstValue.isEmpty() && from.isBeforeOrEqualToNotNullSafe(firstValueKey)) {
if (from.isBeforeNotNullSafe(firstValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return firstValue.snapshot();
}
}
if (to != null && !lastValue.isEmpty() && to.isAfterOrEqualToNotNullSafe(lastValueKey)) {
if (to.isAfterNotNullSafe(lastValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return lastValue.snapshot();
}
}
final SortedMap<Long, V> headMap;
if (from == null) {
headMap = values.descendingMap();
} else {
headMap = values.descendingMap().tailMap(from.millisValue(), true);
}
final ICloseableIterable<Entry<Long, V>> tail = WrapperCloseableIterable.maybeWrap(headMap.entrySet());
final ICloseableIterable<Entry<Long, V>> skipping;
if (to == null) {
skipping = tail;
} else {
skipping = new ASkippingIterable<Entry<Long, V>>(tail) {
@Override
protected boolean skip(final Entry<Long, V> element) {
if (element.getKey() < to.millisValue()) {
throw new FastNoSuchElementException("LiveSegment rangeReverseValues end reached");
}
return false;
}
};
}
final ATransformingIterable<Entry<Long, V>, V> transforming = new ATransformingIterable<Entry<Long, V>, V>(skipping) {
@Override
protected V transform(final Entry<Long, V> value) {
return value.getValue();
}
};
if (readLock == DisabledLock.INSTANCE) {
return transforming;
} else {
// we expect the read lock to be already locked from the outside
return new BufferingIterator<>(transforming);
}
}
use of de.invesdwin.util.collections.iterable.ATransformingIterable in project invesdwin-context-persistence by subes.
the class HeapLiveSegment method rangeValues.
@Override
public ICloseableIterable<V> rangeValues(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
// we expect the read lock to be already locked from the outside
if (values == null || from != null && to != null && from.isAfterNotNullSafe(to)) {
return EmptyCloseableIterable.getInstance();
}
if (from != null && !lastValue.isEmpty() && from.isAfterOrEqualToNotNullSafe(lastValueKey)) {
if (from.isAfterNotNullSafe(lastValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return lastValue.snapshot();
}
}
if (to != null && !firstValue.isEmpty() && to.isBeforeOrEqualToNotNullSafe(firstValueKey)) {
if (to.isBeforeNotNullSafe(firstValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return firstValue.snapshot();
}
}
final SortedMap<Long, V> tailMap;
if (from == null) {
tailMap = values;
} else {
tailMap = values.tailMap(from.millisValue(), true);
}
final ICloseableIterable<Entry<Long, V>> tail = WrapperCloseableIterable.maybeWrap(tailMap.entrySet());
final ICloseableIterable<Entry<Long, V>> skipping;
if (to == null) {
skipping = tail;
} else {
skipping = new ASkippingIterable<Entry<Long, V>>(tail) {
@Override
protected boolean skip(final Entry<Long, V> element) {
if (element.getKey() > to.millisValue()) {
throw new FastNoSuchElementException("LiveSegment rangeValues end reached");
}
return false;
}
};
}
final ATransformingIterable<Entry<Long, V>, V> transforming = new ATransformingIterable<Entry<Long, V>, V>(skipping) {
@Override
protected V transform(final Entry<Long, V> value) {
return value.getValue();
}
};
if (readLock == DisabledLock.INSTANCE) {
return transforming;
} else {
// we expect the read lock to be already locked from the outside
return new BufferingIterator<>(transforming);
}
}
use of de.invesdwin.util.collections.iterable.ATransformingIterable in project invesdwin-context-persistence by subes.
the class MphTablePerformanceTest method testMphTablePerformance.
@Test
public void testMphTablePerformance() throws IOException {
final File directory = new File(ContextProperties.getCacheDirectory(), MphTablePerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdir(directory);
final File file = new File(directory, "testMphTablePerformance");
final Instant writesStart = new Instant();
final TableConfig<Long, Long> config = new TableConfig<Long, Long>().withKeySerializer(new SmartLongSerializer()).withValueSerializer(new SmartVLongSerializer());
final ATransformingIterable<FDate, com.indeed.util.core.Pair<Long, Long>> entries = new ATransformingIterable<FDate, com.indeed.util.core.Pair<Long, Long>>(newValues()) {
@Override
protected com.indeed.util.core.Pair<Long, Long> transform(final FDate value) {
return com.indeed.util.core.Pair.of(value.millisValue(), value.millisValue());
}
};
// can not append to an existing table
TableWriter.write(file, config, entries);
printProgress("WritesFinished", writesStart, VALUES, VALUES);
readIterator(file);
readGet(file);
}
use of de.invesdwin.util.collections.iterable.ATransformingIterable in project invesdwin-context-persistence by subes.
the class ASegmentedTimeSeriesStorageCache method readRangeValues.
public ICloseableIterable<V> readRangeValues(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
final FDate firstAvailableSegmentFrom = getFirstAvailableSegmentFrom(key);
if (firstAvailableSegmentFrom == null) {
return EmptyCloseableIterable.getInstance();
}
final FDate lastAvailableSegmentTo = getLastAvailableSegmentTo(key, to);
if (lastAvailableSegmentTo == null) {
return EmptyCloseableIterable.getInstance();
}
// adjust dates directly to prevent unnecessary segment calculations
final FDate adjFrom = FDates.max(from, firstAvailableSegmentFrom);
final FDate adjTo = FDates.min(to, lastAvailableSegmentTo);
final ICloseableIterable<TimeRange> segments = getSegments(adjFrom, adjTo, lastAvailableSegmentTo);
final ATransformingIterable<TimeRange, ICloseableIterable<V>> segmentQueries = new ATransformingIterable<TimeRange, ICloseableIterable<V>>(segments) {
@Override
protected ICloseableIterable<V> transform(final TimeRange value) {
return new ICloseableIterable<V>() {
@Override
public ICloseableIterator<V> iterator() {
final SegmentedKey<K> segmentedKey = new SegmentedKey<K>(key, value);
maybeInitSegment(segmentedKey);
final FDate segmentAdjFrom = FDates.max(adjFrom, value.getFrom());
final FDate segmentAdjTo = FDates.min(adjTo, value.getTo());
final Lock compositeReadLock = Locks.newCompositeLock(readLock, segmentedTable.getTableLock(segmentedKey).readLock());
return segmentedTable.getLookupTableCache(segmentedKey).readRangeValues(segmentAdjFrom, segmentAdjTo, compositeReadLock, skipFileFunction);
}
};
}
};
final ICloseableIterable<V> rangeValues = new FlatteningIterable<V>(segmentQueries);
return rangeValues;
}
use of de.invesdwin.util.collections.iterable.ATransformingIterable in project invesdwin-context-persistence by subes.
the class ASegmentedTimeSeriesStorageCache method readRangeValuesReverse.
public ICloseableIterable<V> readRangeValuesReverse(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
final FDate firstAvailableSegmentFrom = getFirstAvailableSegmentFrom(key);
final FDate lastAvailableSegmentTo = getLastAvailableSegmentTo(key, to);
// adjust dates directly to prevent unnecessary segment calculations
final FDate adjFrom = FDates.min(from, lastAvailableSegmentTo);
final FDate adjTo = FDates.max(to, firstAvailableSegmentFrom);
final ICloseableIterable<TimeRange> filteredSegments = getSegmentsReverse(adjFrom, adjTo, lastAvailableSegmentTo);
final ATransformingIterable<TimeRange, ICloseableIterable<V>> segmentQueries = new ATransformingIterable<TimeRange, ICloseableIterable<V>>(filteredSegments) {
@Override
protected ICloseableIterable<V> transform(final TimeRange value) {
return new ICloseableIterable<V>() {
@Override
public ICloseableIterator<V> iterator() {
final SegmentedKey<K> segmentedKey = new SegmentedKey<K>(key, value);
maybeInitSegment(segmentedKey);
final FDate segmentAdjFrom = FDates.min(adjFrom, value.getTo());
final FDate segmentAdjTo = FDates.max(adjTo, value.getFrom());
final Lock compositeReadLock = Locks.newCompositeLock(readLock, segmentedTable.getTableLock(segmentedKey).readLock());
return segmentedTable.getLookupTableCache(segmentedKey).readRangeValuesReverse(segmentAdjFrom, segmentAdjTo, compositeReadLock, skipFileFunction);
}
};
}
};
final ICloseableIterable<V> rangeValues = new FlatteningIterable<V>(segmentQueries);
return rangeValues;
}
Aggregations