HBASE-14759 Avoid using Math.abs when selecting SyncRunner in FSHLog
This commit is contained in:
parent
263a0adf79
commit
9cce912de0
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue