hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r957411 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java
Date Thu, 24 Jun 2010 04:35:22 GMT
Author: stack
Date: Thu Jun 24 04:35:22 2010
New Revision: 957411

URL: http://svn.apache.org/viewvc?rev=957411&view=rev
Log:
HBASE-2774 Spin in ReadWriteConsistencyControl eating CPU (load > 40) and no progress running
YCSB on clean cluster startup 

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=957411&r1=957410&r2=957411&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Thu Jun 24 04:35:22 2010
@@ -417,6 +417,8 @@ Release 0.21.0 - Unreleased
                average - slop; endless churn
    HBASE-2729  Interrupted or failed memstore flushes should not corrupt the
                region
+   HBASE-2774  Spin in ReadWriteConsistencyControl eating CPU (load > 40) and
+               no progress running YCSB on clean cluster startup                     
 
   IMPROVEMENTS
    HBASE-1760  Cleanup TODOs in HTable

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java?rev=957411&r1=957410&r2=957411&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/ReadWriteConsistencyControl.java
Thu Jun 24 04:35:22 2010
@@ -10,8 +10,11 @@ import java.util.concurrent.atomic.Atomi
  * the new writes for readers to read (thus forming atomic transactions).
  */
 public class ReadWriteConsistencyControl {
-  private final AtomicLong memstoreRead = new AtomicLong();
-  private final AtomicLong memstoreWrite = new AtomicLong();
+  private volatile long memstoreRead = 0;
+  private volatile long memstoreWrite = 0;
+
+  private final Object readWaiters = new Object();
+
   // This is the pending queue of writes.
   private final LinkedList<WriteEntry> writeQueue =
       new LinkedList<WriteEntry>();
@@ -34,12 +37,13 @@ public class ReadWriteConsistencyControl
 
   public WriteEntry beginMemstoreInsert() {
     synchronized (writeQueue) {
-      long nextWriteNumber = memstoreWrite.incrementAndGet();
+      long nextWriteNumber = ++memstoreWrite;
       WriteEntry e = new WriteEntry(nextWriteNumber);
       writeQueue.add(e);
       return e;
     }
   }
+
   public void completeMemstoreInsert(WriteEntry e) {
     synchronized (writeQueue) {
       e.markCompleted();
@@ -70,24 +74,32 @@ public class ReadWriteConsistencyControl
       }
 
       if (nextReadValue > 0) {
-        memstoreRead.set(nextReadValue);
+        memstoreRead = nextReadValue;
+
+        synchronized (readWaiters) {
+          readWaiters.notifyAll();
+        }
+
       }
     }
 
-    // Spin until any other concurrent puts have finished. This makes sure that
-    // if we move on to construct a scanner, we'll get read-your-own-writes
-    // consistency. We anticipate that since puts to the memstore are very fast,
-    // this will be on the order of microseconds - so spinning should be faster
-    // than a condition variable.
-    int spun = 0;
-    while (memstoreRead.get() < e.getWriteNumber()) {
-      spun++;
+    boolean interrupted = false;
+    while (memstoreRead < e.getWriteNumber()) {
+      synchronized (readWaiters) {
+        try {
+          readWaiters.wait(0);
+        } catch (InterruptedException e) {
+          // We were interrupted... finish the loop -- i.e. cleanup --and then
+          // on our way out, reset the interrupt flag.
+          interrupted = true;
+        }
+      }
     }
-    // Could potentially expose spun as a metric
+    if (interrupted) Thread.currentThread.interrupt();
   }
 
   public long memstoreReadPoint() {
-    return memstoreRead.get();
+    return memstoreRead;
   }
 
 



Mime
View raw message