HBASE-14759 Avoid using Math.abs when selecting SyncRunner in FSHLog
This commit is contained in:
parent
c1a19dece0
commit
234f31bd4a
|
@ -1766,9 +1766,10 @@ public class FSHLog implements WAL {
|
||||||
if (this.exception == null) {
|
if (this.exception == null) {
|
||||||
// Below expects that the offer 'transfers' responsibility for the outstanding syncs to
|
// Below expects that the offer 'transfers' responsibility for the outstanding syncs to
|
||||||
// the syncRunner. We should never get an exception in here.
|
// 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 {
|
try {
|
||||||
this.syncRunners[index].offer(sequence, this.syncFutures, this.syncFuturesCount);
|
this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures,
|
||||||
|
this.syncFuturesCount);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Should NEVER get here.
|
// Should NEVER get here.
|
||||||
requestLogRoll();
|
requestLogRoll();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -419,4 +420,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