[ 
https://issues.apache.org/jira/browse/HBASE-14759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14989229#comment-14989229
 ] 

Duo Zhang commented on HBASE-14759:
-----------------------------------

Add a simple testcase in TestFSHLog

{code}

  @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);
    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);
    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();
    addEdits(log, hri, htd, 1, mvcc);
    addEdits(log, hri, htd, 1, mvcc);
  }
{code}

It will fail with
{noformat}
org.apache.hadoop.hbase.regionserver.wal.DamagedWALException: On sync
        at 
org.apache.hadoop.hbase.regionserver.wal.FSHLog$RingBufferEventHandler.onEvent(FSHLog.java:1782)
        at 
org.apache.hadoop.hbase.regionserver.wal.FSHLog$RingBufferEventHandler.onEvent(FSHLog.java:1)
        at 
com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.hadoop.hbase.regionserver.wal.DamagedWALException: Failed 
offering sync
        at 
org.apache.hadoop.hbase.regionserver.wal.FSHLog$RingBufferEventHandler.onEvent(FSHLog.java:1776)
        ... 5 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -3
        at 
org.apache.hadoop.hbase.regionserver.wal.FSHLog$RingBufferEventHandler.onEvent(FSHLog.java:1772)
        ... 5 more
{noformat}

> Avoid using Math.abs when selecting SyncRunner in FSHLog
> --------------------------------------------------------
>
>                 Key: HBASE-14759
>                 URL: https://issues.apache.org/jira/browse/HBASE-14759
>             Project: HBase
>          Issue Type: Bug
>          Components: wal
>            Reporter: Duo Zhang
>
> {code:title=FSHLog.java}
> int index = Math.abs(this.syncRunnerIndex++) % this.syncRunners.length;
>           try {
>             this.syncRunners[index].offer(sequence, this.syncFutures, 
> this.syncFuturesCount);
>           } catch (Exception e) {
>             // Should NEVER get here.
>             requestLogRoll();
>             this.exception = new DamagedWALException("Failed offering sync", 
> e);
>           }
> {code}
> Math.abs will return Integer.MIN_VALUE if you pass Integer.MIN_VALUE in since 
> the actual absolute value of Integer.MIN_VALUE is out of range.
> I think {{this.syncRunnerIndex++}} will overflow eventually if we keep the 
> regionserver running for enough time.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to