HDFS-5514. FSNamesystem's fsLock should allow custom implementation (daryn)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1548161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daryn Sharp 2013-12-05 15:28:12 +00:00
parent aa4fba6d92
commit 6828337d85
3 changed files with 42 additions and 4 deletions

View File

@ -457,6 +457,8 @@ Release 2.4.0 - UNRELEASED
HDFS-5444. Choose default web UI based on browser capabilities. (Haohui Mai HDFS-5444. Choose default web UI based on browser capabilities. (Haohui Mai
via jing9) via jing9)
HDFS-5514. FSNamesystem's fsLock should allow custom implementation (daryn)
IMPROVEMENTS IMPROVEMENTS
HDFS-5267. Remove volatile from LightWeightHashSet. (Junping Du via llu) HDFS-5267. Remove volatile from LightWeightHashSet. (Junping Du via llu)

View File

@ -467,7 +467,7 @@ private void logAuditEvent(boolean succeeded,
private final long accessTimePrecision; private final long accessTimePrecision;
/** Lock to protect FSNamesystem. */ /** Lock to protect FSNamesystem. */
private ReentrantReadWriteLock fsLock; private FSNamesystemLock fsLock;
/** /**
* Used when this NN is in standby state to read from the shared edit log. * Used when this NN is in standby state to read from the shared edit log.
@ -650,7 +650,7 @@ public static FSNamesystem loadFromDisk(Configuration conf)
throws IOException { throws IOException {
boolean fair = conf.getBoolean("dfs.namenode.fslock.fair", true); boolean fair = conf.getBoolean("dfs.namenode.fslock.fair", true);
LOG.info("fsLock is fair:" + fair); LOG.info("fsLock is fair:" + fair);
fsLock = new ReentrantReadWriteLock(fair); fsLock = new FSNamesystemLock(fair);
try { try {
resourceRecheckInterval = conf.getLong( resourceRecheckInterval = conf.getLong(
DFS_NAMENODE_RESOURCE_CHECK_INTERVAL_KEY, DFS_NAMENODE_RESOURCE_CHECK_INTERVAL_KEY,
@ -6771,12 +6771,12 @@ public void setEditLogTailerForTests(EditLogTailer tailer) {
@VisibleForTesting @VisibleForTesting
void setFsLockForTests(ReentrantReadWriteLock lock) { void setFsLockForTests(ReentrantReadWriteLock lock) {
this.fsLock = lock; this.fsLock.coarseLock = lock;
} }
@VisibleForTesting @VisibleForTesting
ReentrantReadWriteLock getFsLockForTests() { ReentrantReadWriteLock getFsLockForTests() {
return fsLock; return fsLock.coarseLock;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -158,4 +158,40 @@ public void testFsLockFairness() throws IOException, InterruptedException{
fsNamesystem = new FSNamesystem(conf, fsImage); fsNamesystem = new FSNamesystem(conf, fsImage);
assertFalse(fsNamesystem.getFsLockForTests().isFair()); assertFalse(fsNamesystem.getFsLockForTests().isFair());
} }
@Test
public void testFSNamesystemLockCompatibility() {
FSNamesystemLock rwLock = new FSNamesystemLock(true);
assertEquals(0, rwLock.getReadHoldCount());
rwLock.readLock().lock();
assertEquals(1, rwLock.getReadHoldCount());
rwLock.readLock().lock();
assertEquals(2, rwLock.getReadHoldCount());
rwLock.readLock().unlock();
assertEquals(1, rwLock.getReadHoldCount());
rwLock.readLock().unlock();
assertEquals(0, rwLock.getReadHoldCount());
assertFalse(rwLock.isWriteLockedByCurrentThread());
assertEquals(0, rwLock.getWriteHoldCount());
rwLock.writeLock().lock();
assertTrue(rwLock.isWriteLockedByCurrentThread());
assertEquals(1, rwLock.getWriteHoldCount());
rwLock.writeLock().lock();
assertTrue(rwLock.isWriteLockedByCurrentThread());
assertEquals(2, rwLock.getWriteHoldCount());
rwLock.writeLock().unlock();
assertTrue(rwLock.isWriteLockedByCurrentThread());
assertEquals(1, rwLock.getWriteHoldCount());
rwLock.writeLock().unlock();
assertFalse(rwLock.isWriteLockedByCurrentThread());
assertEquals(0, rwLock.getWriteHoldCount());
}
} }