diff --git a/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 09de2ac..b698836 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -520,8 +520,8 @@ public class HConnectionManager implements HConstants { HRegionInfo currentRegion; Scan scan = new Scan(startKey); scan.addColumn(CATALOG_FAMILY, REGIONINFO_QUALIFIER); - int rows = this.conf.getInt("hbase.meta.scanner.caching", 100); - scan.setCaching(rows); + long bufferSize = this.conf.getLong("hbase.meta.scan.buffer", 100000); + scan.setBufferSize(bufferSize); ScannerCallable s = new ScannerCallable(this, (Bytes.equals(tableName, HConstants.META_TABLE_NAME) ? HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME), scan); diff --git a/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/src/main/java/org/apache/hadoop/hbase/client/HTable.java index 7ec95cb..bb8ebc3 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -55,26 +55,23 @@ import java.util.concurrent.atomic.AtomicInteger; /** * Used to communicate with a single HBase table. - *
- * This class is not thread safe for writes. - * Gets, puts, and deletes take out a row lock for the duration - * of their operation. Scans (currently) do not respect - * row locking. + *
+ * This class is not thread safe for writes. Gets, puts, and deletes take out a + * row lock for the duration of their operation. Scans (currently) do not + * respect row locking. */ public class HTable implements HTableInterface { private final HConnection connection; - private final byte [] tableName; + private final byte[] tableName; protected final int scannerTimeout; private volatile Configuration configuration; private final ArrayList- * The default value comes from {@code hbase.client.scanner.caching}. + * Get the number of bytes to buffer that will be passed to scanners. + * + * @return the number of bytes to buffer */ - public int getScannerCaching() { - return scannerCaching; + public long getScanBufferSize() { + return scanBufferSize; } /** - * Sets the number of rows that a scanner will fetch at once. - *
- * This will override the value specified by - * {@code hbase.client.scanner.caching}. - * Increasing this value will reduce the amount of work needed each time - * {@code next()} is called on a scanner, at the expense of memory use - * (since more rows will need to be maintained in memory by the scanners). - * @param scannerCaching the number of rows a scanner will fetch at once. + * Set the number of bytes to buffer that will be passed to scanners. + * + * @param scanBufferSize the number of bytes to buffer */ - public void setScannerCaching(int scannerCaching) { - this.scannerCaching = scannerCaching; + public void setScanBufferSize(long scanBufferSize) { + this.scanBufferSize = scanBufferSize; } public HTableDescriptor getTableDescriptor() throws IOException { @@ -283,19 +281,21 @@ public class HTable implements HTableInterface { /** * Gets the starting row key for every region in the currently open table. - *
+ *
* This is mainly useful for the MapReduce integration. + * * @return Array of region starting row keys * @throws IOException if a remote or network exception occurs */ - public byte [][] getStartKeys() throws IOException { + public byte[][] getStartKeys() throws IOException { return getStartEndKeys().getFirst(); } /** * Gets the ending row key for every region in the currently open table. - *+ *
* This is mainly useful for the MapReduce integration. + * * @return Array of region ending row keys * @throws IOException if a remote or network exception occurs */ @@ -306,20 +306,21 @@ public class HTable implements HTableInterface { /** * Gets the starting and ending row keys for every region in the currently * open table. - *+ *
* This is mainly useful for the MapReduce integration. + * * @return Pair of arrays of region starting and ending row keys * @throws IOException if a remote or network exception occurs */ @SuppressWarnings("unchecked") - public Pair+ *
* This is mainly useful for the MapReduce integration. + * * @return A map of HRegionInfo with it's server address * @throws IOException if a remote or network exception occurs */ @@ -348,16 +350,16 @@ public class HTable implements HTableInterface { MetaScannerVisitor visitor = new MetaScannerVisitor() { public boolean processRow(Result rowResult) throws IOException { HRegionInfo info = Writables.getHRegionInfo( - rowResult.getValue(HConstants.CATALOG_FAMILY, - HConstants.REGIONINFO_QUALIFIER)); + rowResult.getValue(HConstants.CATALOG_FAMILY, + HConstants.REGIONINFO_QUALIFIER)); if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) { return false; } HServerAddress server = new HServerAddress(); - byte [] value = rowResult.getValue(HConstants.CATALOG_FAMILY, - HConstants.SERVER_QUALIFIER); + byte[] value = rowResult.getValue(HConstants.CATALOG_FAMILY, + HConstants.SERVER_QUALIFIER); if (value != null && value.length > 0) { String address = Bytes.toString(value); server = new HServerAddress(address); @@ -374,16 +376,16 @@ public class HTable implements HTableInterface { return regionMap; } - public Result getRowOrBefore(final byte[] row, final byte[] family) - throws IOException { - return connection.getRegionServerWithRetries( - new ServerCallable- * - * This will return true if the Get matches one or more keys, false if not.
+ * Test for the existence of columns in the table, as specified in the + * Get.
+ *
+ * This will return true if the Get matches one or more keys, false if + * not.+ *
+ * This is a server-side call so it prevents any data from being transfered to + * the client. * - * This is a server-side call so it prevents any data from being transfered - * to the client. * @param get param to check for * @return true if the specified Get matches one or more keys, false if not * @throws IOException */ public boolean exists(final Get get) throws IOException { return connection.getRegionServerWithRetries( - new ServerCallable+ *
* When enabled (default), {@link Put} operations don't get buffered/delayed * and are immediately executed. This is slower but safer. - *+ *
* Turning this off means that multiple {@link Put}s will be accepted before * any RPC is actually sent to do the write operations. If the application - * dies before pending writes get flushed to HBase, data will be lost. - * Other side effects may include the fact that the application thinks a - * {@link Put} was executed successfully whereas it was in fact only - * buffered and the operation may fail when attempting to flush all pending - * writes. In that case though, the code will retry the failed {@link Put} - * upon its next attempt to flush the buffer. + * dies before pending writes get flushed to HBase, data will be lost. Other + * side effects may include the fact that the application thinks a {@link Put} + * was executed successfully whereas it was in fact only buffered and the + * operation may fail when attempting to flush all pending writes. In that + * case though, the code will retry the failed {@link Put} upon its next + * attempt to flush the buffer. * * @param autoFlush Whether or not to enable 'auto-flush'. * @see #flushCommits @@ -622,9 +628,10 @@ public class HTable implements HTableInterface { /** * Returns the maximum size in bytes of the write buffer for this HTable. - *- * The default value comes from the configuration parameter - * {@code hbase.client.write.buffer}. + *
+ * The default value comes from the configuration parameter {@code + * hbase.client.write.buffer}. + * * @return The size of the write buffer in bytes. */ public long getWriteBufferSize() { @@ -633,21 +640,23 @@ public class HTable implements HTableInterface { /** * Sets the size of the buffer in bytes. - *- * If the new size is less than the current amount of data in the - * write buffer, the buffer gets flushed. + *
+ * If the new size is less than the current amount of data in the write + * buffer, the buffer gets flushed. + * * @param writeBufferSize The new write buffer size, in bytes. * @throws IOException if a remote or network exception occurs. */ public void setWriteBufferSize(long writeBufferSize) throws IOException { this.writeBufferSize = writeBufferSize; - if(currentWriteBufferSize > writeBufferSize) { + if (currentWriteBufferSize > writeBufferSize) { flushCommits(); } } /** * Returns the write buffer. + * * @return The current write buffer. */ public ArrayList* To scan everything for each row, instantiate a Scan object. *
- * To modify scanner caching for just this scan, use {@link #setCaching(int) setCaching}. + * To modify scanner buffer for just this scan, use {@link #setBufferSize(long)}}. *
* To further define the scope of what to get when scanning, perform additional
* methods as outlined below.
@@ -82,7 +82,7 @@ public class Scan implements Writable {
private byte [] stopRow = HConstants.EMPTY_END_ROW;
private int maxVersions = 1;
private int batch = -1;
- private int caching = -1;
+ private long bufferSize = -1;
private boolean cacheBlocks = true;
private Filter filter = null;
private TimeRange tr = new TimeRange();
@@ -131,7 +131,7 @@ public class Scan implements Writable {
stopRow = scan.getStopRow();
maxVersions = scan.getMaxVersions();
batch = scan.getBatch();
- caching = scan.getCaching();
+ bufferSize = scan.getBufferSize();
cacheBlocks = scan.getCacheBlocks();
filter = scan.getFilter(); // clone?
TimeRange ctr = scan.getTimeRange();
@@ -290,13 +290,13 @@ public class Scan implements Writable {
}
/**
- * Set the number of rows for caching that will be passed to scanners.
- * If not set, the default setting from {@link HTable#getScannerCaching()} will apply.
- * Higher caching values will enable faster scanners but will use more memory.
- * @param caching the number of rows for caching
+ * Set the number of bytes of data to buffer for each call to the region server.
+ * If not set, the default setting from {@link HTable#getScanBufferSize()} will apply.
+ * Higher values will enable faster scanners but will use more memory.
+ * @param bufferSize the number of bytes for the scan buffer
*/
- public void setCaching(int caching) {
- this.caching = caching;
+ public void setBufferSize(long bufferSize) {
+ this.bufferSize = bufferSize;
}
/**
@@ -383,10 +383,10 @@ public class Scan implements Writable {
}
/**
- * @return caching the number of rows fetched when calling next on a scanner
+ * @return the number of bytes of data to buffer for each call to the region server.
*/
- public int getCaching() {
- return this.caching;
+ public long getBufferSize() {
+ return this.bufferSize;
}
/**
@@ -447,8 +447,8 @@ public class Scan implements Writable {
sb.append(this.maxVersions);
sb.append(", batch=");
sb.append(this.batch);
- sb.append(", caching=");
- sb.append(this.caching);
+ sb.append(", bufferSize=");
+ sb.append(this.bufferSize);
sb.append(", cacheBlocks=");
sb.append(this.cacheBlocks);
sb.append(", timeRange=");
@@ -512,7 +512,7 @@ public class Scan implements Writable {
this.stopRow = Bytes.readByteArray(in);
this.maxVersions = in.readInt();
this.batch = in.readInt();
- this.caching = in.readInt();
+ this.bufferSize = in.readLong();
this.cacheBlocks = in.readBoolean();
if(in.readBoolean()) {
this.filter = (Filter)createForName(Bytes.toString(Bytes.readByteArray(in)));
@@ -542,7 +542,7 @@ public class Scan implements Writable {
Bytes.writeByteArray(out, this.stopRow);
out.writeInt(this.maxVersions);
out.writeInt(this.batch);
- out.writeInt(this.caching);
+ out.writeLong(this.bufferSize);
out.writeBoolean(this.cacheBlocks);
if(this.filter == null) {
out.writeBoolean(false);
diff --git a/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java b/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java
index 2fff71e..34715e4 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java
@@ -39,7 +39,7 @@ public class ScannerCallable extends ServerCallable