|
@@ -38,6 +38,7 @@ import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_FSLOCK_FAIR_KEY;
|
|
@@ -347,7 +348,7 @@ public class TestFSNamesystemLock {
|
|
|
|
|
|
fsLock.writeLock();
|
|
|
timer.advance(1);
|
|
|
- fsLock.writeUnlock("baz");
|
|
|
+ fsLock.writeUnlock("baz", false);
|
|
|
|
|
|
MetricsRecordBuilder rb = MetricsAsserts.mockMetricsRecordBuilder();
|
|
|
rates.snapshot(rb, true);
|
|
@@ -360,4 +361,48 @@ public class TestFSNamesystemLock {
|
|
|
assertCounter("FSNWriteLockBazNanosNumOps", 1L, rb);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test to suppress FSNameSystem write lock report when it is held for long
|
|
|
+ * time.
|
|
|
+ */
|
|
|
+ @Test(timeout = 45000)
|
|
|
+ public void testFSWriteLockReportSuppressed() throws Exception {
|
|
|
+ final long writeLockReportingThreshold = 1L;
|
|
|
+ final long writeLockSuppressWarningInterval = 10L;
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.setLong(
|
|
|
+ DFSConfigKeys.DFS_NAMENODE_WRITE_LOCK_REPORTING_THRESHOLD_MS_KEY,
|
|
|
+ writeLockReportingThreshold);
|
|
|
+ conf.setTimeDuration(DFSConfigKeys.DFS_LOCK_SUPPRESS_WARNING_INTERVAL_KEY,
|
|
|
+ writeLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ final FakeTimer timer = new FakeTimer();
|
|
|
+ final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
|
|
|
+ timer.advance(writeLockSuppressWarningInterval);
|
|
|
+
|
|
|
+ LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
|
|
|
+ GenericTestUtils
|
|
|
+ .setLogLevel(LoggerFactory.getLogger(FSNamesystem.class.getName()),
|
|
|
+ org.slf4j.event.Level.INFO);
|
|
|
+
|
|
|
+ // Should trigger the write lock report
|
|
|
+ fsnLock.writeLock();
|
|
|
+ timer.advance(writeLockReportingThreshold + 100);
|
|
|
+ fsnLock.writeUnlock();
|
|
|
+ assertTrue(logs.getOutput().contains(
|
|
|
+ "FSNamesystem write lock held for"));
|
|
|
+
|
|
|
+ logs.clearOutput();
|
|
|
+
|
|
|
+ // Suppress report if the write lock is held for a long time
|
|
|
+ fsnLock.writeLock();
|
|
|
+ timer.advance(writeLockReportingThreshold + 100);
|
|
|
+ fsnLock.writeUnlock("testFSWriteLockReportSuppressed", true);
|
|
|
+ assertFalse(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
|
+ assertFalse(logs.getOutput().contains(
|
|
|
+ "Number of suppressed write-lock reports:"));
|
|
|
+ assertFalse(logs.getOutput().contains(
|
|
|
+ "FSNamesystem write lock held for"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|