NonSyncTimeRangeTracker(final TimeRangeTracker trt) { this.minimumTimestamp = trt.getMin(); this.maximumTimestamp = trt.getMax(); }
@Override public long getMaxTimestamp() { return timeRange == null? Long.MAX_VALUE: timeRangeTracker.getMax(); }
@Override public String toString() { return "[" + getMin() + "," + getMax() + "]"; }
SyncTimeRangeTracker(final TimeRangeTracker trt) { this.minimumTimestamp.set(trt.getMin()); this.maximumTimestamp.set(trt.getMax()); }
/** * This method used to serialize TimeRangeTracker (TRT) by protobuf while this breaks the * forward compatibility on HFile.(See HBASE-21008) In previous hbase version ( < 2.0.0 ) we use * DataOutput to serialize TRT, these old versions don't have capability to deserialize TRT * which is serialized by protobuf. So we need to revert the change of serializing * TimeRangeTracker back to DataOutput. For more information, please check HBASE-21012. * @param tracker TimeRangeTracker needed to be serialized. * @return byte array filled with serialized TimeRangeTracker. * @throws IOException if something goes wrong in writeLong. */ public static byte[] toByteArray(TimeRangeTracker tracker) throws IOException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { try (DataOutputStream dos = new DataOutputStream(bos)) { dos.writeLong(tracker.getMin()); dos.writeLong(tracker.getMax()); return bos.toByteArray(); } } }
/** * @return Make a TimeRange from current state of <code>this</code>. */ TimeRange toTimeRange() { long min = getMin(); long max = getMax(); // Initial TimeRangeTracker timestamps are the opposite of what you want for a TimeRange. Fix! if (min == INITIAL_MIN_TIMESTAMP) { min = TimeRange.INITIAL_MIN_TIMESTAMP; } if (max == INITIAL_MAX_TIMESTAMP) { max = TimeRange.INITIAL_MAX_TIMESTAMP; } return new TimeRange(min, max); }
@Override public OptionalLong getMaximumTimestamp() { return timeRangeTracker == null ? OptionalLong.empty() : OptionalLong.of(timeRangeTracker.getMax()); }
public boolean shouldSeek(TimeRange tr, long oldestUnexpiredTS) { return !isEmpty() && (tr.isAllTime() || timeRangeTracker.includesTimeRange(tr)) && timeRangeTracker.getMax() >= oldestUnexpiredTS; }
@Override public String toString() { String res = "type=" + this.getClass().getSimpleName() + ", "; res += "empty=" + (isEmpty()? "yes": "no") + ", "; res += "cellCount=" + getCellsCount() + ", "; res += "cellSize=" + getDataSize() + ", "; res += "totalHeapSize=" + getHeapSize() + ", "; res += "min timestamp=" + timeRangeTracker.getMin() + ", "; res += "max timestamp=" + timeRangeTracker.getMax(); return res; }
/** * Check if the range has ANY overlap with TimeRange * @param tr TimeRange, it expects [minStamp, maxStamp) * @return True if there is overlap, false otherwise */ public boolean includesTimeRange(final TimeRange tr) { return (getMin() < tr.getMax() && getMax() >= tr.getMin()); }
public CompositeImmutableSegment(CellComparator comparator, List<ImmutableSegment> segments) { super(comparator, segments); this.segments = segments; for (ImmutableSegment s : segments) { this.timeRangeTracker.includeTimestamp(s.getTimeRangeTracker().getMax()); this.timeRangeTracker.includeTimestamp(s.getTimeRangeTracker().getMin()); this.keySize += s.getDataSize(); } }
@Test public void testLegacySerialization() throws IOException { ByteArrayOutputStream data = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(data); output.writeLong(100); output.writeLong(200); TimeRangeTracker tgt = TimeRangeTracker.parseFrom(data.toByteArray()); assertEquals(100, tgt.getMin()); assertEquals(200, tgt.getMax()); }
assertTrue(trr.getMax() == calls * threadCount); assertTrue(trr.getMin() == 0);
m -> m.getTimeRangeTracker().getMin()).min().getAsLong()); assertEquals(currentTs, memstore.getSegments().stream().mapToLong( m -> m.getTimeRangeTracker().getMax()).max().getAsLong()); m -> m.getTimeRangeTracker().getMin()).min().getAsLong()); assertEquals(currentTs, memstore.getSegments().stream().mapToLong( m -> m.getTimeRangeTracker().getMax()).max().getAsLong()); m -> m.getTimeRangeTracker().getMin()).min().getAsLong()); assertEquals(currentTs, memstore.getSegments().stream().mapToLong( m -> m.getTimeRangeTracker().getMax()).max().getAsLong());
assertTrue(max == trt.getMax());
@Test public void testAlwaysDecrementingSetsMaximum() { TimeRangeTracker trr = getTimeRangeTracker(); trr.includeTimestamp(3); trr.includeTimestamp(2); trr.includeTimestamp(1); assertTrue(trr.getMin() != TimeRangeTracker.INITIAL_MIN_TIMESTAMP); assertTrue(trr.getMax() != -1 /*The initial max value*/); }
@Test public void testTimeRangeTrackerNullIsSameAsTimeRangeNull() throws IOException { TimeRangeTracker src = getTimeRangeTracker(1, 2); byte[] bytes = TimeRangeTracker.toByteArray(src); TimeRange tgt = TimeRangeTracker.parseFrom(bytes).toTimeRange(); assertEquals(src.getMin(), tgt.getMin()); assertEquals(src.getMax(), tgt.getMax()); }