/** * Check if the range has any overlap with TimeRange * @param tr TimeRange * @return True if there is overlap, false otherwise */ // This method came from TimeRangeTracker. We used to go there for this function but better // to come here to the immutable, unsynchronized datastructure at read time. public boolean includesTimeRange(final TimeRange tr) { if (this.allTime) { return true; } assert tr.getMin() >= 0; return getMin() < tr.getMax() && getMax() >= tr.getMin(); }
@Override public OptionalLong getMinimumTimestamp() { TimeRange tr = getReader().timeRange; return tr != null ? OptionalLong.of(tr.getMin()) : OptionalLong.empty(); }
/** * 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 static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange) { if (timeRange == null) { timeRange = TimeRange.allTime(); } return HBaseProtos.TimeRange.newBuilder().setFrom(timeRange.getMin()) .setTo(timeRange.getMax()) .build(); } }
public static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange) { if (timeRange == null) { timeRange = TimeRange.allTime(); } return HBaseProtos.TimeRange.newBuilder().setFrom(timeRange.getMin()) .setTo(timeRange.getMax()) .build(); } }
@Override public Result get(Get get) throws IOException { TimeRange range = get.getTimeRange(); String spec = buildRowSpec(get.getRow(), get.getFamilyMap(), range.getMin(), range.getMax(), get.getMaxVersions()); if (get.getFilter() != null) { LOG.warn("filters not supported on gets"); } Result[] results = getResults(spec); if (results.length > 0) { if (results.length > 1) { LOG.warn("too many results for get (" + results.length + ")"); } return results[0]; } else { return new Result(); } }
setColumnFamilyTimeRange(entry.getKey(), tr.getMin(), tr.getMax());
/** * Do a specific Get on passed <code>columnFamily</code> and column qualifiers. * @param mutation Mutation we are doing this Get for. * @param store Which column family on row (TODO: Go all Gets in one go) * @param coordinates Cells from <code>mutation</code> used as coordinates applied to Get. * @return Return list of Cells found. */ private List<Cell> get(Mutation mutation, HStore store, List<Cell> coordinates, IsolationLevel isolation, TimeRange tr) throws IOException { // Sort the cells so that they match the order that they appear in the Get results. Otherwise, // we won't be able to find the existing values if the cells are not specified in order by the // client since cells are in an array list. // TODO: I don't get why we are sorting. St.Ack 20150107 sort(coordinates, store.getComparator()); Get get = new Get(mutation.getRow()); if (isolation != null) { get.setIsolationLevel(isolation); } for (Cell cell: coordinates) { get.addColumn(store.getColumnFamilyDescriptor().getName(), CellUtil.cloneQualifier(cell)); } // Increments carry time range. If an Increment instance, put it on the Get. if (tr != null) { get.setTimeRange(tr.getMin(), tr.getMax()); } return get(get, false); }
@Test public void testGet() throws Exception{ byte[] row = "row".getBytes(); byte[] fam = "fam".getBytes(); byte[] qf1 = "qf1".getBytes(); long ts = System.currentTimeMillis(); int maxVersions = 2; Get get = new Get(row); get.addColumn(fam, qf1); get.setTimeRange(ts, ts+1); get.setMaxVersions(maxVersions); ClientProtos.Get getProto = ProtobufUtil.toGet(get); Get desGet = ProtobufUtil.toGet(getProto); assertTrue(Bytes.equals(get.getRow(), desGet.getRow())); Set<byte[]> set = null; Set<byte[]> desSet = null; for(Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()){ assertTrue(desGet.getFamilyMap().containsKey(entry.getKey())); set = entry.getValue(); desSet = desGet.getFamilyMap().get(entry.getKey()); for(byte [] qualifier : set){ assertTrue(desSet.contains(qualifier)); } } assertEquals(get.getMaxVersions(), desGet.getMaxVersions()); TimeRange tr = get.getTimeRange(); TimeRange desTr = desGet.getTimeRange(); assertEquals(tr.getMax(), desTr.getMax()); assertEquals(tr.getMin(), desTr.getMin()); }
TimeRange range10 = new TimeRange(1, time+10); hTableInterface.increment(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L) .setTimeRange(range10.getMin(), range10.getMax())); checkRowValue(ROW_A, Bytes.toBytes(11L)); assertEquals(MyObserver.tr10.getMin(), range10.getMin()); assertEquals(MyObserver.tr10.getMax(), range10.getMax()); List<Row> actions = Arrays.asList(new Row[] { new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()), new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()) }); Object[] results3 = new Object[actions.size()]; Object[] results1 = results3; hTableInterface.batch(actions, results1); assertEquals(MyObserver.tr2.getMin(), range2.getMin()); assertEquals(MyObserver.tr2.getMax(), range2.getMax()); for (Object r2 : results1) {
TimeRange range10 = new TimeRange(1, time + 10); Result r = table.append(new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("b")) .setTimeRange(range10.getMin(), range10.getMax())); checkRowValue(table, ROW, Bytes.toBytes("ab")); assertEquals(MyObserver.tr10.getMin(), range10.getMin()); assertEquals(MyObserver.tr10.getMax(), range10.getMax()); time = EnvironmentEdgeManager.currentTime(); Arrays.asList(new Row[] { new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("c")) .setTimeRange(range2.getMin(), range2.getMax()), new Append(ROW).addColumn(TEST_FAMILY, QUAL, Bytes.toBytes("c")) .setTimeRange(range2.getMin(), range2.getMax()) }); Object[] results1 = new Object[actions.size()]; table.batch(actions, results1); assertEquals(MyObserver.tr2.getMin(), range2.getMin()); assertEquals(MyObserver.tr2.getMax(), range2.getMax()); for (Object r2 : results1) {
/** * Convert a protocol buffer Mutate to an Append * @param cellScanner * @param proto the protocol buffer Mutate to convert * @return the converted client Append * @throws IOException */ public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.APPEND : type.name(); Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = toTimeRange(proto.getTimeRange()); append.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return append; }
/** * Convert a protocol buffer Mutate to an Append * @param cellScanner * @param proto the protocol buffer Mutate to convert * @return the converted client Append * @throws IOException */ public static Append toAppend(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.APPEND : type.name(); Append append = toDelta((Bytes row) -> new Append(row.get(), row.getOffset(), row.getLength()), Append::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); append.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return append; }
/** * Convert a protocol buffer Mutate to an Increment * * @param proto the protocol buffer Mutate to convert * @return the converted client Increment * @throws IOException */ public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.INCREMENT : type.name(); Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()), Increment::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = protoToTimeRange(proto.getTimeRange()); increment.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return increment; }
/** * Convert a protocol buffer Mutate to an Increment * * @param proto the protocol buffer Mutate to convert * @return the converted client Increment * @throws IOException */ public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner) throws IOException { MutationType type = proto.getMutateType(); assert type == MutationType.INCREMENT : type.name(); Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()), Increment::add, proto, cellScanner); if (proto.hasTimeRange()) { TimeRange timeRange = toTimeRange(proto.getTimeRange()); increment.setTimeRange(timeRange.getMin(), timeRange.getMax()); } return increment; }
@Test public void testRangeConstruction() throws IOException { TimeRange defaultRange = TimeRange.allTime(); assertEquals(0L, defaultRange.getMin()); assertEquals(Long.MAX_VALUE, defaultRange.getMax()); assertTrue(defaultRange.isAllTime()); TimeRange oneArgRange = new TimeRange(0L); assertEquals(0L, oneArgRange.getMin()); assertEquals(Long.MAX_VALUE, oneArgRange.getMax()); assertTrue(oneArgRange.isAllTime()); TimeRange oneArgRange2 = new TimeRange(1); assertEquals(1, oneArgRange2.getMin()); assertEquals(Long.MAX_VALUE, oneArgRange2.getMax()); assertFalse(oneArgRange2.isAllTime()); TimeRange twoArgRange = new TimeRange(0L, Long.MAX_VALUE); assertEquals(0L, twoArgRange.getMin()); assertEquals(Long.MAX_VALUE, twoArgRange.getMax()); assertTrue(twoArgRange.isAllTime()); TimeRange twoArgRange2 = new TimeRange(0L, Long.MAX_VALUE - 1); assertEquals(0L, twoArgRange2.getMin()); assertEquals(Long.MAX_VALUE - 1, twoArgRange2.getMax()); assertFalse(twoArgRange2.isAllTime()); TimeRange twoArgRange3 = new TimeRange(1, Long.MAX_VALUE); assertEquals(1, twoArgRange3.getMin()); assertEquals(Long.MAX_VALUE, twoArgRange3.getMax()); assertFalse(twoArgRange3.isAllTime()); }
private void testTimeRangeIfSomeCellsAreDroppedInFlush(int maxVersion) throws IOException { init(this.name.getMethodName(), TEST_UTIL.getConfiguration(), ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(maxVersion).build()); long currentTs = 100; long minTs = currentTs; // the extra cell won't be flushed to disk, // so the min of timerange will be different between memStore and hfile. for (int i = 0; i != (maxVersion + 1); ++i) { this.store.add(new KeyValue(row, family, qf1, ++currentTs, (byte[])null), null); if (i == 1) { minTs = currentTs; } } flushStore(store, id++); Collection<HStoreFile> files = store.getStorefiles(); assertEquals(1, files.size()); HStoreFile f = files.iterator().next(); f.initReader(); StoreFileReader reader = f.getReader(); assertEquals(minTs, reader.timeRange.getMin()); assertEquals(currentTs, reader.timeRange.getMax()); }
@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()); }
assertEquals(get.getMaxVersions(), scan.getMaxVersions()); assertEquals(get.getRowOffsetPerColumnFamily(), scan.getRowOffsetPerColumnFamily()); assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin()); assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax()); assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0"))); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin()); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax());