HBASE-2496 Less ArrayList churn on the scan path

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@939030 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jean-Daniel Cryans 2010-04-28 17:52:43 +00:00
parent 0c50c92879
commit 369056d691
4 changed files with 30 additions and 14 deletions

View File

@ -537,6 +537,7 @@ Release 0.21.0 - Unreleased
(Todd Lipcon via Stack)
HBASE-2393 ThriftServer instantiates a new HTable per request
(Bogdan DRAGU via Stack)
HBASE-2496 Less ArrayList churn on the scan path
NEW FEATURES
HBASE-1961 HBase EC2 scripts

View File

@ -25,9 +25,9 @@ package org.apache.hadoop.hbase.regionserver;
* NOT thread-safe because it is not used in a multi-threaded context, yet.
*/
public class ColumnCount {
private byte [] bytes;
private int offset;
private int length;
private final byte [] bytes;
private final int offset;
private final int length;
private int count;
/**
@ -97,6 +97,15 @@ public class ColumnCount {
public int increment() {
return ++count;
}
/**
* Set the current count to a new count
* @param count new count to set
*/
public void setCount(int count) {
this.count = count;
}
/**
* Check to see if needed to fetch more versions

View File

@ -46,11 +46,11 @@ import org.apache.hadoop.hbase.util.Bytes;
*/
public class ExplicitColumnTracker implements ColumnTracker {
private int maxVersions;
private List<ColumnCount> columns;
private final int maxVersions;
private final List<ColumnCount> columns;
private final List<ColumnCount> columnsToReuse;
private int index;
private ColumnCount column;
private NavigableSet<byte[]> origColumns;
/**
* Default constructor.
@ -59,7 +59,11 @@ public class ExplicitColumnTracker implements ColumnTracker {
*/
public ExplicitColumnTracker(NavigableSet<byte[]> columns, int maxVersions) {
this.maxVersions = maxVersions;
this.origColumns = columns;
this.columns = new ArrayList<ColumnCount>(columns.size());
this.columnsToReuse = new ArrayList<ColumnCount>(columns.size());
for(byte [] column : columns) {
this.columnsToReuse.add(new ColumnCount(column,maxVersions));
}
reset();
}
@ -147,15 +151,16 @@ public class ExplicitColumnTracker implements ColumnTracker {
// Called between every row.
public void reset() {
buildColumnList(this.origColumns);
buildColumnList();
this.index = 0;
this.column = this.columns.get(this.index);
}
private void buildColumnList(NavigableSet<byte[]> columns) {
this.columns = new ArrayList<ColumnCount>(columns.size());
for(byte [] column : columns) {
this.columns.add(new ColumnCount(column,maxVersions));
private void buildColumnList() {
this.columns.clear();
this.columns.addAll(this.columnsToReuse);
for(ColumnCount col : this.columns) {
col.setCount(this.maxVersions);
}
}
}

View File

@ -1815,12 +1815,12 @@ public class HRegionServer implements HConstants, HRegionInterface,
throw e;
}
this.leases.renewLease(scannerName);
List<Result> results = new ArrayList<Result>();
List<Result> results = new ArrayList<Result>(nbRows);
long currentScanResultSize = 0;
List<KeyValue> values = new ArrayList<KeyValue>();
for (int i = 0; i < nbRows && currentScanResultSize < maxScannerResultSize; i++) {
requestCount.incrementAndGet();
// Collect values to be returned here
List<KeyValue> values = new ArrayList<KeyValue>();
boolean moreRows = s.next(values);
if (!values.isEmpty()) {
for (KeyValue kv : values) {
@ -1831,6 +1831,7 @@ public class HRegionServer implements HConstants, HRegionInterface,
if (!moreRows) {
break;
}
values.clear();
}
// Below is an ugly hack where we cast the InternalScanner to be a
// HRegion.RegionScanner. The alternative is to change InternalScanner