HDFS-5239. Allow FSNamesystem lock fairness to be configurable (daryn)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1525624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3175cf17c7
commit
3dfadca6f5
|
@ -288,6 +288,8 @@ Release 2.3.0 - UNRELEASED
|
|||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HDFS-5239. Allow FSNamesystem lock fairness to be configurable (daryn)
|
||||
|
||||
BUG FIXES
|
||||
HDFS-5034. Remove debug prints from GetFileLinkInfo (Andrew Wang via Colin
|
||||
Patrick McCabe)
|
||||
|
|
|
@ -435,7 +435,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|||
private final long accessTimePrecision;
|
||||
|
||||
/** Lock to protect FSNamesystem. */
|
||||
private ReentrantReadWriteLock fsLock = new ReentrantReadWriteLock(true);
|
||||
private ReentrantReadWriteLock fsLock;
|
||||
|
||||
/**
|
||||
* Used when this NN is in standby state to read from the shared edit log.
|
||||
|
@ -610,6 +610,9 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|||
*/
|
||||
FSNamesystem(Configuration conf, FSImage fsImage, boolean ignoreRetryCache)
|
||||
throws IOException {
|
||||
boolean fair = conf.getBoolean("dfs.namenode.fslock.fair", true);
|
||||
LOG.info("fsLock is fair:" + fair);
|
||||
fsLock = new ReentrantReadWriteLock(fair);
|
||||
try {
|
||||
resourceRecheckInterval = conf.getLong(
|
||||
DFS_NAMENODE_RESOURCE_CHECK_INTERVAL_KEY,
|
||||
|
|
|
@ -20,8 +20,7 @@ package org.apache.hadoop.hdfs.server.namenode;
|
|||
|
||||
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY;
|
||||
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -142,4 +141,21 @@ public class TestFSNamesystem {
|
|||
assertTrue("Replication queues weren't being populated after entering "
|
||||
+ "safemode 2nd time", fsn.isPopulatingReplQueues());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFsLockFairness() throws IOException, InterruptedException{
|
||||
Configuration conf = new Configuration();
|
||||
|
||||
FSEditLog fsEditLog = Mockito.mock(FSEditLog.class);
|
||||
FSImage fsImage = Mockito.mock(FSImage.class);
|
||||
Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
|
||||
|
||||
conf.setBoolean("dfs.namenode.fslock.fair", true);
|
||||
FSNamesystem fsNamesystem = new FSNamesystem(conf, fsImage);
|
||||
assertTrue(fsNamesystem.getFsLockForTests().isFair());
|
||||
|
||||
conf.setBoolean("dfs.namenode.fslock.fair", false);
|
||||
fsNamesystem = new FSNamesystem(conf, fsImage);
|
||||
assertFalse(fsNamesystem.getFsLockForTests().isFair());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue