|
@@ -30,6 +30,7 @@ import java.util.Collection;
|
|
import com.google.common.base.Supplier;
|
|
import com.google.common.base.Supplier;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileUtil;
|
|
import org.apache.hadoop.fs.FileUtil;
|
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
@@ -260,7 +261,10 @@ public class TestFSNamesystem {
|
|
*/
|
|
*/
|
|
@Test(timeout=45000)
|
|
@Test(timeout=45000)
|
|
public void testFSLockLongHoldingReport() throws Exception {
|
|
public void testFSLockLongHoldingReport() throws Exception {
|
|
|
|
+ final long writeLockReportingThreshold = 100L;
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
|
|
+ conf.setLong(DFSConfigKeys.DFS_NAMENODE_WRITE_LOCK_REPORTING_THRESHOLD_MS_KEY,
|
|
|
|
+ writeLockReportingThreshold);
|
|
FSImage fsImage = Mockito.mock(FSImage.class);
|
|
FSImage fsImage = Mockito.mock(FSImage.class);
|
|
FSEditLog fsEditLog = Mockito.mock(FSEditLog.class);
|
|
FSEditLog fsEditLog = Mockito.mock(FSEditLog.class);
|
|
Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
|
|
Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
|
|
@@ -271,32 +275,32 @@ public class TestFSNamesystem {
|
|
|
|
|
|
// Don't report if the write lock is held for a short time
|
|
// Don't report if the write lock is held for a short time
|
|
fsn.writeLock();
|
|
fsn.writeLock();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD / 2);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold / 2);
|
|
fsn.writeUnlock();
|
|
fsn.writeUnlock();
|
|
assertFalse(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
assertFalse(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
|
|
|
|
|
|
|
|
// Report if the write lock is held for a long time
|
|
// Report if the write lock is held for a long time
|
|
fsn.writeLock();
|
|
fsn.writeLock();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD + 100);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold + 10);
|
|
logs.clearOutput();
|
|
logs.clearOutput();
|
|
fsn.writeUnlock();
|
|
fsn.writeUnlock();
|
|
assertTrue(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
assertTrue(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
|
|
|
|
// Report if the write lock is held (interruptibly) for a long time
|
|
// Report if the write lock is held (interruptibly) for a long time
|
|
fsn.writeLockInterruptibly();
|
|
fsn.writeLockInterruptibly();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD + 100);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold + 10);
|
|
logs.clearOutput();
|
|
logs.clearOutput();
|
|
fsn.writeUnlock();
|
|
fsn.writeUnlock();
|
|
assertTrue(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
assertTrue(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
|
|
|
|
// Report if it's held for a long time when re-entering write lock
|
|
// Report if it's held for a long time when re-entering write lock
|
|
fsn.writeLock();
|
|
fsn.writeLock();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD / 2 + 1);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold/ 2 + 1);
|
|
fsn.writeLockInterruptibly();
|
|
fsn.writeLockInterruptibly();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD / 2 + 1);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold / 2 + 1);
|
|
fsn.writeLock();
|
|
fsn.writeLock();
|
|
- Thread.sleep(FSNamesystem.WRITELOCK_REPORTING_THRESHOLD / 2);
|
|
|
|
|
|
+ Thread.sleep(writeLockReportingThreshold / 2);
|
|
logs.clearOutput();
|
|
logs.clearOutput();
|
|
fsn.writeUnlock();
|
|
fsn.writeUnlock();
|
|
assertFalse(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|
|
assertFalse(logs.getOutput().contains(GenericTestUtils.getMethodName()));
|