HBASE-14759 Avoid using Math.abs when selecting SyncRunner in FSHLog

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

Branch: refs/heads/hbase-12439
Commit: 9cce912de01b7f2c6e968b0c9fdaccd93e44bebf
Parents: 263a0ad
Author: zhangduo <zhang...@apache.org>
Authored: Wed Nov 4 19:08:26 2015 +0800
Committer: zhangduo <zhang...@wandoujia.com>
Committed: Sat Nov 7 08:44:25 2015 +0800

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/wal/FSHLog.java   |  5 ++--
 .../hbase/regionserver/wal/TestFSHLog.java      | 29 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/9cce912d/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
index 928f4b6..17e3a94 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
@@ -1767,9 +1767,10 @@ public class FSHLog implements WAL {
         if (this.exception == null) {
           // Below expects that the offer 'transfers' responsibility for the 
outstanding syncs to
           // the syncRunner. We should never get an exception in here.
-          int index = Math.abs(this.syncRunnerIndex++) % 
this.syncRunners.length;
+          this.syncRunnerIndex = (this.syncRunnerIndex + 1) % 
this.syncRunners.length;
           try {
-            this.syncRunners[index].offer(sequence, this.syncFutures, 
this.syncFuturesCount);
+            this.syncRunners[this.syncRunnerIndex].offer(sequence, 
this.syncFutures,
+              this.syncFuturesCount);
           } catch (Exception e) {
             // Should NEVER get here.
             requestLogRoll();

http://git-wip-us.apache.org/repos/asf/hbase/blob/9cce912d/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestFSHLog.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestFSHLog.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestFSHLog.java
index f86bdd5..af47465 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestFSHLog.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestFSHLog.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -420,4 +421,32 @@ public class TestFSHLog {
     }
   }
 
+  @Test
+  public void testSyncRunnerIndexOverflow() throws IOException, 
NoSuchFieldException,
+      SecurityException, IllegalArgumentException, IllegalAccessException {
+    final String name = "testSyncRunnerIndexOverflow";
+    FSHLog log =
+        new FSHLog(fs, FSUtils.getRootDir(conf), name, 
HConstants.HREGION_OLDLOGDIR_NAME, conf,
+            null, true, null, null);
+    try {
+      Field ringBufferEventHandlerField = 
FSHLog.class.getDeclaredField("ringBufferEventHandler");
+      ringBufferEventHandlerField.setAccessible(true);
+      FSHLog.RingBufferEventHandler ringBufferEventHandler =
+          (FSHLog.RingBufferEventHandler) ringBufferEventHandlerField.get(log);
+      Field syncRunnerIndexField =
+          
FSHLog.RingBufferEventHandler.class.getDeclaredField("syncRunnerIndex");
+      syncRunnerIndexField.setAccessible(true);
+      syncRunnerIndexField.set(ringBufferEventHandler, Integer.MAX_VALUE - 1);
+      HTableDescriptor htd =
+          new HTableDescriptor(TableName.valueOf("t1")).addFamily(new 
HColumnDescriptor("row"));
+      HRegionInfo hri =
+          new HRegionInfo(htd.getTableName(), HConstants.EMPTY_START_ROW, 
HConstants.EMPTY_END_ROW);
+      MultiVersionConcurrencyControl mvcc = new 
MultiVersionConcurrencyControl();
+      for (int i = 0; i < 10; i++) {
+        addEdits(log, hri, htd, 1, mvcc);
+      }
+    } finally {
+      log.close();
+    }
+  }
 }

Reply via email to