hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-12632 ThrottledInputStream/ExportSnapshot does not throttle
Date Fri, 05 Dec 2014 14:52:11 GMT
Repository: hbase
Updated Branches:
  refs/heads/master c8362a7bb -> 155a644b1


HBASE-12632 ThrottledInputStream/ExportSnapshot does not throttle


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/155a644b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/155a644b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/155a644b

Branch: refs/heads/master
Commit: 155a644b1cce68b5ef7dcf20eca8ed29bf39c771
Parents: c8362a7
Author: tedyu <yuzhihong@gmail.com>
Authored: Fri Dec 5 06:52:04 2014 -0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Fri Dec 5 06:52:04 2014 -0800

----------------------------------------------------------------------
 .../io/hadoopbackport/ThrottledInputStream.java | 27 +++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/155a644b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hadoopbackport/ThrottledInputStream.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hadoopbackport/ThrottledInputStream.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hadoopbackport/ThrottledInputStream.java
index dd6df0c..e1da695 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hadoopbackport/ThrottledInputStream.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hadoopbackport/ThrottledInputStream.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.io.hadoopbackport;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.hadoop.fs.PositionedReadable;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 
 /**
@@ -93,8 +94,32 @@ public class ThrottledInputStream extends InputStream {
     return readLen;
   }
 
+  /**
+   * Read bytes starting from the specified position. This requires rawStream is
+   * an instance of {@link PositionedReadable}.
+   * @param position
+   * @param buffer
+   * @param offset
+   * @param length
+   * @return the number of bytes read
+   */
+  public int read(long position, byte[] buffer, int offset, int length)
+      throws IOException {
+    if (!(rawStream instanceof PositionedReadable)) {
+      throw new UnsupportedOperationException(
+        "positioned read is not supported by the internal stream");
+    }
+    throttle();
+    int readLen = ((PositionedReadable) rawStream).read(position, buffer,
+      offset, length);
+    if (readLen != -1) {
+      bytesRead += readLen;
+    }
+    return readLen;
+  }
+
   private void throttle() throws IOException {
-    if (getBytesPerSec() > maxBytesPerSec) {
+    while (getBytesPerSec() > maxBytesPerSec) {
       try {
         Thread.sleep(SLEEP_DURATION_MS);
         totalSleepTime += SLEEP_DURATION_MS;


Mime
View raw message