frostruan commented on code in PR #5247:
URL: https://github.com/apache/hbase/pull/5247#discussion_r1202793846


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreFlusher.java:
##########
@@ -495,41 +505,54 @@ public int getFlushQueueSize() {
    * Only interrupt once it's done with a run through the work loop.
    */
   void interruptIfNecessary() {
-    lock.writeLock().lock();
+    lock.readLock().lock();
     try {
-      for (FlushHandler flushHander : flushHandlers) {
-        if (flushHander != null) flushHander.interrupt();
+      for (FlushHandler flushHandler : flushHandlers) {
+        if (flushHandler != null) {
+          flushHandler.interrupt();
+        }
       }
     } finally {
-      lock.writeLock().unlock();
+      lock.readLock().unlock();
     }
   }
 
   synchronized void start(UncaughtExceptionHandler eh) {
-    ThreadFactory flusherThreadFactory = new ThreadFactoryBuilder()
+    this.flusherThreadFactory = new ThreadFactoryBuilder()
       .setNameFormat(server.getServerName().toShortString() + 
"-MemStoreFlusher-pool-%d")
       .setDaemon(true).setUncaughtExceptionHandler(eh).build();
-    for (int i = 0; i < flushHandlers.length; i++) {
-      flushHandlers[i] = new FlushHandler("MemStoreFlusher." + i);
-      flusherThreadFactory.newThread(flushHandlers[i]);
-      flushHandlers[i].start();
+    lock.readLock().lock();
+    try {
+      startFlushHandlerThreads(flushHandlers, 0, flushHandlers.length);
+    } finally {
+      lock.readLock().unlock();
     }
   }
 
   boolean isAlive() {
-    for (FlushHandler flushHander : flushHandlers) {
-      if (flushHander != null && flushHander.isAlive()) {
-        return true;
+    lock.readLock().lock();
+    try {
+      for (FlushHandler flushHandler : flushHandlers) {
+        if (flushHandler != null && flushHandler.isAlive()) {
+          return true;
+        }
       }
+      return false;
+    } finally {
+      lock.readLock().unlock();
     }
-    return false;
   }
 
   void join() {

Review Comment:
   I also feel a bit strange about the name of this method. Let me rename it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to