From 5abb3867c04b2b5cece0bebe386bb4de5f140ebe Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Sat, 30 Oct 2010 16:58:44 +0000 Subject: [PATCH] HBASE-3162 Add TimeRange support into Increment to optimize for counters that are partitioned on time git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1029118 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/hadoop/hbase/client/Increment.java | 33 +++++++++++++++++++ .../hadoop/hbase/regionserver/HRegion.java | 5 +++ 3 files changed, 40 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index c80828cfe5d..d2784f273b0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1065,6 +1065,8 @@ Release 0.21.0 - Unreleased a RS no longer present HBASE-3174 Add ability for Get operations to enable/disable use of block caching + HBASE-3162 Add TimeRange support into Increment to optimize for counters + that are partitioned on time NEW FEATURES HBASE-1961 HBase EC2 scripts diff --git a/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/src/main/java/org/apache/hadoop/hbase/client/Increment.java index 082a6703763..3aec67f6210 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/Increment.java +++ b/src/main/java/org/apache/hadoop/hbase/client/Increment.java @@ -27,6 +27,7 @@ import java.util.NavigableMap; 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 @@ public class Increment implements Writable { 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); @@ -143,6 +145,34 @@ public class Increment implements Writable { return this; } + /** + * 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 @@ public class Increment implements Writable { 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 @@ public class Increment implements Writable { 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"); diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index ccaa2fc4f99..dd2955d71b3 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -71,6 +71,7 @@ import org.apache.hadoop.hbase.client.Scan; 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 @@ public class HRegion implements HeapSize { // , Writable{ newGet.addColumn(family, qualifier); } } + newGet.setTimeRange(get.getTimeRange().getMin(), + get.getTimeRange().getMax()); iscan = new InternalScan(newGet); } @@ -3002,6 +3005,7 @@ public class HRegion implements HeapSize { // , Writable{ // 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 @@ public class HRegion implements HeapSize { // , Writable{ 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