You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2013/11/26 22:06:55 UTC

svn commit: r1545838 - /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Author: larsh
Date: Tue Nov 26 21:06:55 2013
New Revision: 1545838

URL: http://svn.apache.org/r1545838
Log:
HBASE-10015 Replace intrinsic locking with explicit locks in StoreScanner

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java?rev=1545838&r1=1545837&r2=1545838&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java Tue Nov 26 21:06:55 2013
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.NavigableSet;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -96,6 +97,7 @@ public class StoreScanner extends NonLaz
 
   // A flag whether use pread for scan
   private boolean scanUsePread = false;
+  private ReentrantLock lock = new ReentrantLock();
   
   private final long readPt;
 
@@ -354,11 +356,16 @@ public class StoreScanner extends NonLaz
   }
 
   @Override
-  public synchronized KeyValue peek() {
+  public KeyValue peek() {
+    lock.lock();
+    try {
     if (this.heap == null) {
       return this.lastTop;
     }
     return this.heap.peek();
+    } finally {
+      lock.unlock();
+    }
   }
 
   @Override
@@ -368,7 +375,9 @@ public class StoreScanner extends NonLaz
   }
 
   @Override
-  public synchronized void close() {
+  public void close() {
+    lock.lock();
+    try {
     if (this.closing) return;
     this.closing = true;
     // under test, we dont have a this.store
@@ -378,13 +387,21 @@ public class StoreScanner extends NonLaz
       this.heap.close();
     this.heap = null; // CLOSED!
     this.lastTop = null; // If both are null, we are closed.
+    } finally {
+      lock.unlock();
+    }
   }
 
   @Override
-  public synchronized boolean seek(KeyValue key) throws IOException {
+  public boolean seek(KeyValue key) throws IOException {
+    lock.lock();
+    try {
     // reset matcher state, in case that underlying store changed
     checkReseek();
     return this.heap.seek(key);
+    } finally {
+      lock.unlock();
+    }
   }
 
   /**
@@ -394,7 +411,9 @@ public class StoreScanner extends NonLaz
    * @return true if there are more rows, false if scanner is done
    */
   @Override
-  public synchronized boolean next(List<Cell> outResult, int limit) throws IOException {
+  public boolean next(List<Cell> outResult, int limit) throws IOException {
+    lock.lock();
+    try {
     if (checkReseek()) {
       return true;
     }
@@ -530,16 +549,21 @@ public class StoreScanner extends NonLaz
     // No more keys
     close();
     return false;
+    } finally {
+      lock.unlock();
+    }
   }
 
   @Override
-  public synchronized boolean next(List<Cell> outResult) throws IOException {
+  public boolean next(List<Cell> outResult) throws IOException {
     return next(outResult, -1);
   }
 
   // Implementation of ChangedReadersObserver
   @Override
-  public synchronized void updateReaders() throws IOException {
+  public void updateReaders() throws IOException {
+    lock.lock();
+    try {
     if (this.closing) return;
 
     // All public synchronized API calls will call 'checkReseek' which will cause
@@ -559,6 +583,9 @@ public class StoreScanner extends NonLaz
     this.heap = null; // the re-seeks could be slow (access HDFS) free up memory ASAP
 
     // Let the next() call handle re-creating and seeking
+    } finally {
+      lock.unlock();
+    }
   }
 
   /**
@@ -622,7 +649,9 @@ public class StoreScanner extends NonLaz
   }
 
   @Override
-  public synchronized boolean reseek(KeyValue kv) throws IOException {
+  public boolean reseek(KeyValue kv) throws IOException {
+    lock.lock();
+    try {
     //Heap will not be null, if this is called from next() which.
     //If called from RegionScanner.reseek(...) make sure the scanner
     //stack is reset if needed.
@@ -631,6 +660,9 @@ public class StoreScanner extends NonLaz
       return heap.requestSeek(kv, true, useRowColBloom);
     }
     return heap.reseek(kv);
+    } finally {
+      lock.unlock();
+    }
   }
 
   @Override