Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (revision 1028936) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (working copy) @@ -71,6 +71,7 @@ import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.filter.IncompatibleFilterException; import org.apache.hadoop.hbase.io.HeapSize; +import org.apache.hadoop.hbase.io.TimeRange; import org.apache.hadoop.hbase.io.hfile.BlockCache; import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.regionserver.wal.HLog; @@ -2946,6 +2947,8 @@ newGet.addColumn(family, qualifier); } } + newGet.setTimeRange(get.getTimeRange().getMin(), + get.getTimeRange().getMax()); iscan = new InternalScan(newGet); } @@ -3002,6 +3005,7 @@ // TODO: Use RWCC to make this set of increments atomic to reads byte [] row = increment.getRow(); checkRow(row); + TimeRange tr = increment.getTimeRange(); boolean flush = false; WALEdit walEdits = null; List allKVs = new ArrayList(increment.numColumns()); @@ -3025,6 +3029,7 @@ for (Map.Entry column : family.getValue().entrySet()) { get.addColumn(family.getKey(), column.getKey()); } + get.setTimeRange(tr.getMin(), tr.getMax()); List results = getLastIncrement(get); // Iterate the input columns and update existing values if they were Index: src/main/java/org/apache/hadoop/hbase/client/Increment.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/Increment.java (revision 1028936) +++ src/main/java/org/apache/hadoop/hbase/client/Increment.java (working copy) @@ -27,6 +27,7 @@ import java.util.Set; import java.util.TreeMap; +import org.apache.hadoop.hbase.io.TimeRange; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.Writable; @@ -48,6 +49,7 @@ private byte [] row = null; private long lockId = -1L; private boolean writeToWAL = true; + private TimeRange tr = new TimeRange(); private Map> familyMap = new TreeMap>(Bytes.BYTES_COMPARATOR); @@ -144,6 +146,34 @@ } /** + * Gets the TimeRange used for this increment. + * @return TimeRange + */ + public TimeRange getTimeRange() { + return this.tr; + } + + /** + * Sets the TimeRange to be used on the Get for this increment. + *

+ * This is useful for when you have counters that only last for specific + * periods of time (ie. counters that are partitioned by time). By setting + * the range of valid times for this increment, you can potentially gain + * some performance with a more optimal Get operation. + *

+ * This range is used as [minStamp, maxStamp). + * @param minStamp minimum timestamp value, inclusive + * @param maxStamp maximum timestamp value, exclusive + * @throws IOException if invalid time range + * @return this + */ + public Increment setTimeRange(long minStamp, long maxStamp) + throws IOException { + tr = new TimeRange(minStamp, maxStamp); + return this; + } + + /** * Method for retrieving the keys in the familyMap * @return keys in the current familyMap */ @@ -241,6 +271,8 @@ throw new IOException("unsupported version"); } this.row = Bytes.readByteArray(in); + this.tr = new TimeRange(); + tr.readFields(in); this.lockId = in.readLong(); int numFamilies = in.readInt(); if (numFamilies == 0) { @@ -270,6 +302,7 @@ throws IOException { out.writeByte(INCREMENT_VERSION); Bytes.writeByteArray(out, this.row); + tr.write(out); out.writeLong(this.lockId); if (familyMap.size() == 0) { throw new IOException("At least one column required");