-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16143. Add Timer in EditLogTailer and de-flake TestEditLogTailer#testStandbyTriggersLogRollsWhenTailInProgressEdits #3235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b5554b6
d5d2db7
f21efea
3720dec
c18b3d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| import org.apache.hadoop.hdfs.server.namenode.NameNode; | ||
| import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; | ||
| import org.apache.hadoop.test.GenericTestUtils; | ||
| import org.apache.hadoop.util.FakeTimer; | ||
| import org.slf4j.event.Level; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
@@ -394,13 +395,15 @@ public void testStandbyTriggersLogRollsWhenTailInProgressEdits() | |
| // Time in seconds to wait before checking if edit logs are rolled while | ||
| // expecting no edit log roll | ||
| final int noLogRollWaitTime = 2; | ||
|
|
||
| // Time in seconds to wait before checking if edit logs are rolled while | ||
| // expecting edit log roll | ||
| // expecting edit log roll. | ||
| final int logRollWaitTime = 3; | ||
|
|
||
| final int logRollPeriod = standbyCatchupWaitTime + noLogRollWaitTime + 1; | ||
| final long logRollPeriodMs = TimeUnit.SECONDS.toMillis(logRollPeriod); | ||
| Configuration conf = getConf(); | ||
| conf.setInt(DFSConfigKeys.DFS_HA_LOGROLL_PERIOD_KEY, | ||
| standbyCatchupWaitTime + noLogRollWaitTime + 1); | ||
| conf.setInt(DFSConfigKeys.DFS_HA_LOGROLL_PERIOD_KEY, logRollPeriod); | ||
| conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); | ||
| conf.setBoolean(DFSConfigKeys.DFS_HA_TAILEDITS_INPROGRESS_KEY, true); | ||
|
|
||
|
|
@@ -429,19 +432,29 @@ public void testStandbyTriggersLogRollsWhenTailInProgressEdits() | |
| waitForStandbyToCatchUpWithInProgressEdits(standby, activeTxId, | ||
| standbyCatchupWaitTime); | ||
|
|
||
| long curTime = standby.getNamesystem().getEditLogTailer().getTimer() | ||
| .monotonicNow(); | ||
| long inSufficientTimeForLogRoll = logRollPeriodMs / 3; | ||
| final FakeTimer testTimer = | ||
| new FakeTimer(curTime + inSufficientTimeForLogRoll); | ||
| standby.getNamesystem().getEditLogTailer().setTimerForTest(testTimer); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a thought. it would be great if we can refactor the MiniDfsCluster, the NameNode, FSNamesystem and EditLogTailer such that they take a FakeTimer as a parameter during initialization. If all the tests adopt the way of FakeTimer we wouldn't have so many flaky tests. But I reckon it's out of scope of this change.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice idea, I think we can target this as follow up work. Similar to EditLogTailer, we should introduce |
||
| Thread.sleep(2000); | ||
|
|
||
| for (int i = DIRS_TO_MAKE / 2; i < DIRS_TO_MAKE; i++) { | ||
| NameNodeAdapter.mkdirs(active, getDirPath(i), | ||
| new PermissionStatus("test", "test", | ||
| new FsPermission((short)00755)), true); | ||
| } | ||
|
|
||
| boolean exceptionThrown = false; | ||
| try { | ||
| checkForLogRoll(active, origTxId, noLogRollWaitTime); | ||
| fail("Expected to timeout"); | ||
| } catch (TimeoutException e) { | ||
| exceptionThrown = true; | ||
| // expected | ||
| } | ||
| assertTrue(exceptionThrown); | ||
|
|
||
| long sufficientTimeForLogRoll = logRollPeriodMs * 3; | ||
tasanuma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| testTimer.advance(sufficientTimeForLogRoll); | ||
|
|
||
| checkForLogRoll(active, origTxId, logRollWaitTime); | ||
| } finally { | ||
|
|
@@ -452,26 +465,20 @@ public void testStandbyTriggersLogRollsWhenTailInProgressEdits() | |
| private static void waitForStandbyToCatchUpWithInProgressEdits( | ||
| final NameNode standby, final long activeTxId, | ||
| int maxWaitSec) throws Exception { | ||
| GenericTestUtils.waitFor(new Supplier<Boolean>() { | ||
| @Override | ||
| public Boolean get() { | ||
| long standbyTxId = standby.getNamesystem().getFSImage() | ||
| .getLastAppliedTxId(); | ||
| return (standbyTxId >= activeTxId); | ||
| } | ||
| }, 100, maxWaitSec * 1000); | ||
| GenericTestUtils.waitFor(() -> { | ||
| long standbyTxId = standby.getNamesystem().getFSImage() | ||
| .getLastAppliedTxId(); | ||
| return (standbyTxId >= activeTxId); | ||
| }, 100, TimeUnit.SECONDS.toMillis(maxWaitSec)); | ||
| } | ||
|
|
||
| private static void checkForLogRoll(final NameNode active, | ||
| final long origTxId, int maxWaitSec) throws Exception { | ||
| GenericTestUtils.waitFor(new Supplier<Boolean>() { | ||
| @Override | ||
| public Boolean get() { | ||
| long curSegmentTxId = active.getNamesystem().getFSImage().getEditLog() | ||
| .getCurSegmentTxId(); | ||
| return (origTxId != curSegmentTxId); | ||
| } | ||
| }, 100, maxWaitSec * 1000); | ||
| GenericTestUtils.waitFor(() -> { | ||
| long curSegmentTxId = active.getNamesystem().getFSImage().getEditLog() | ||
| .getCurSegmentTxId(); | ||
| return (origTxId != curSegmentTxId); | ||
| }, 100, TimeUnit.SECONDS.toMillis(maxWaitSec)); | ||
| } | ||
|
|
||
| private static MiniDFSCluster createMiniDFSCluster(Configuration conf, | ||
|
|
@@ -488,4 +495,5 @@ private static MiniDFSCluster createMiniDFSCluster(Configuration conf, | |
| .build(); | ||
| return cluster; | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.