Author: jgray
Date: Sat Oct 30 16:58:44 2010
New Revision: 1029118
URL: http://svn.apache.org/viewvc?rev=1029118&view=rev
Log:
HBASE-3162 Add TimeRange support into Increment to optimize for counters that
are partitioned on time
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/Increment.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Modified: hbase/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1029118&r1=1029117&r2=1029118&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Sat Oct 30 16:58:44 2010
@@ -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
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/Increment.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/Increment.java?rev=1029118&r1=1029117&r2=1029118&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/Increment.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/Increment.java Sat
Oct 30 16:58:44 2010
@@ -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 Writab
private byte [] row = null;
private long lockId = -1L;
private boolean writeToWAL = true;
+ private TimeRange tr = new TimeRange();
private Map<byte [], NavigableMap<byte [], Long>> familyMap =
new TreeMap<byte [], NavigableMap<byte [], Long>>(Bytes.BYTES_COMPARATOR);
@@ -144,6 +146,34 @@ public class Increment implements Writab
}
/**
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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 Writab
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 Writab
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");
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1029118&r1=1029117&r2=1029118&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Sat Oct 30 16:58:44 2010
@@ -71,6 +71,7 @@ import org.apache.hadoop.hbase.client.Sc
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
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
// 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<KeyValue> allKVs = new ArrayList<KeyValue>(increment.numColumns());
@@ -3025,6 +3029,7 @@ public class HRegion implements HeapSize
for (Map.Entry<byte [], Long> column : family.getValue().entrySet())
{
get.addColumn(family.getKey(), column.getKey());
}
+ get.setTimeRange(tr.getMin(), tr.getMax());
List<KeyValue> results = getLastIncrement(get);
// Iterate the input columns and update existing values if they were