Skip to content

Commit 084563f

Browse files
HDFS-5372. In FSNamesystem, hasReadLock() returns false if the current thread holds the write lock (Contributed by Vinay)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1542887 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7551ff2 commit 084563f

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ Release 2.2.1 - UNRELEASED
666666
HDFS-5519. COMMIT handler should update the commit status after sync
667667
(brandonli)
668668

669+
HDFS-5372. In FSNamesystem, hasReadLock() returns false if the current thread
670+
holds the write lock (VinayaKumar B via umamahesh)
671+
669672
Release 2.2.0 - 2013-10-13
670673

671674
INCOMPATIBLE CHANGES

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public LocatedBlocks createLocatedBlocks(final BlockInfo[] blocks,
817817
final boolean isFileUnderConstruction, final long offset,
818818
final long length, final boolean needBlockToken, final boolean inSnapshot)
819819
throws IOException {
820-
assert namesystem.hasReadOrWriteLock();
820+
assert namesystem.hasReadLock();
821821
if (blocks == null) {
822822
return null;
823823
} else if (blocks.length == 0) {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public boolean isActive() {
237237
}
238238

239239
public TreeMap<Long, PathBasedCacheEntry> getEntriesById() {
240-
assert namesystem.hasReadOrWriteLock();
240+
assert namesystem.hasReadLock();
241241
return entriesById;
242242
}
243243

244244
@VisibleForTesting
245245
public GSet<CachedBlock, CachedBlock> getCachedBlocks() {
246-
assert namesystem.hasReadOrWriteLock();
246+
assert namesystem.hasReadLock();
247247
return cachedBlocks;
248248
}
249249

@@ -450,7 +450,7 @@ public void removeDirective(long id, FSPermissionChecker pc)
450450
listPathBasedCacheDirectives(long prevId,
451451
PathBasedCacheDirective filter,
452452
FSPermissionChecker pc) throws IOException {
453-
assert namesystem.hasReadOrWriteLock();
453+
assert namesystem.hasReadLock();
454454
final int NUM_PRE_ALLOCATED_ENTRIES = 16;
455455
String filterPath = null;
456456
if (filter.getId() != null) {
@@ -607,7 +607,7 @@ public void removeCachePool(String poolName)
607607

608608
public BatchedListEntries<CachePoolInfo>
609609
listCachePools(FSPermissionChecker pc, String prevKey) {
610-
assert namesystem.hasReadOrWriteLock();
610+
assert namesystem.hasReadLock();
611611
final int NUM_PRE_ALLOCATED_ENTRIES = 16;
612612
ArrayList<CachePoolInfo> results =
613613
new ArrayList<CachePoolInfo>(NUM_PRE_ALLOCATED_ENTRIES);

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,11 +1295,7 @@ public boolean hasWriteLock() {
12951295
}
12961296
@Override
12971297
public boolean hasReadLock() {
1298-
return this.fsLock.getReadHoldCount() > 0;
1299-
}
1300-
@Override
1301-
public boolean hasReadOrWriteLock() {
1302-
return hasReadLock() || hasWriteLock();
1298+
return this.fsLock.getReadHoldCount() > 0 || hasWriteLock();
13031299
}
13041300

13051301
public int getReadHoldCount() {
@@ -2043,7 +2039,7 @@ long getPreferredBlockSize(String filename)
20432039
*/
20442040
private void verifyParentDir(String src) throws FileNotFoundException,
20452041
ParentNotDirectoryException, UnresolvedLinkException {
2046-
assert hasReadOrWriteLock();
2042+
assert hasReadLock();
20472043
Path parent = new Path(src).getParent();
20482044
if (parent != null) {
20492045
final INode parentNode = dir.getINode(parent.toString());
@@ -2651,7 +2647,7 @@ INodesInPath analyzeFileState(String src,
26512647
ExtendedBlock previous,
26522648
LocatedBlock[] onRetryBlock)
26532649
throws IOException {
2654-
assert hasReadOrWriteLock();
2650+
assert hasReadLock();
26552651

26562652
checkBlock(previous);
26572653
onRetryBlock[0] = null;
@@ -2848,7 +2844,7 @@ private INodeFileUnderConstruction checkLease(String src, String holder)
28482844
private INodeFileUnderConstruction checkLease(String src, long fileId,
28492845
String holder, INode inode) throws LeaseExpiredException,
28502846
FileNotFoundException {
2851-
assert hasReadOrWriteLock();
2847+
assert hasReadLock();
28522848
if (inode == null || !inode.isFile()) {
28532849
Lease lease = leaseManager.getLease(holder);
28542850
throw new LeaseExpiredException(
@@ -3807,7 +3803,7 @@ BlockInfo getStoredBlock(Block block) {
38073803

38083804
@Override
38093805
public boolean isInSnapshot(BlockInfoUnderConstruction blockUC) {
3810-
assert hasReadOrWriteLock();
3806+
assert hasReadLock();
38113807
final BlockCollection bc = blockUC.getBlockCollection();
38123808
if (bc == null || !(bc instanceof INodeFileUnderConstruction)) {
38133809
return false;

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/RwLock.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,4 @@ public interface RwLock {
3939

4040
/** Check if the current thread holds write lock. */
4141
public boolean hasWriteLock();
42-
43-
/** Check if the current thread holds read or write lock. */
44-
public boolean hasReadOrWriteLock();
4542
}

0 commit comments

Comments
 (0)