You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by sz...@apache.org on 2013/03/07 23:34:51 UTC
svn commit: r1454138 - in
/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs: ./
src/main/java/org/apache/hadoop/hdfs/server/namenode/
src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/
Author: szetszwo
Date: Thu Mar 7 22:34:51 2013
New Revision: 1454138
URL: http://svn.apache.org/r1454138
Log:
HDFS-4557. Fix FSDirectory#delete when INode#cleanSubtree returns 0. Contributed by Jing Zhao
Modified:
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileUnderConstructionWithSnapshot.java
hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileWithSnapshot.java
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt Thu Mar 7 22:34:51 2013
@@ -185,3 +185,6 @@ Branch-2802 Snapshot (Unreleased)
HDFS-4545. With snapshots, FSDirectory.unprotectedSetReplication(..) always
changes file replication but it may or may not changes block replication.
(szetszwo)
+
+ HDFS-4557. Fix FSDirectory#delete when INode#cleanSubtree returns 0.
+ (Jing Zhao via szetszwo)
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java Thu Mar 7 22:34:51 2013
@@ -757,7 +757,7 @@ public class FSDirectory implements Clos
getFSNamesystem().unprotectedChangeLease(src, dst);
// Collect the blocks and remove the lease for previous dst
- int filesDeleted = 0;
+ int filesDeleted = -1;
if (removedDst != null) {
INode rmdst = removedDst;
removedDst = null;
@@ -772,7 +772,7 @@ public class FSDirectory implements Clos
// deleted. Need to update the SnapshotManager.
namesystem.removeSnapshottableDirs(snapshottableDirs);
}
- return filesDeleted >0;
+ return filesDeleted >= 0;
}
} finally {
if (removedSrc != null) {
@@ -1017,7 +1017,7 @@ public class FSDirectory implements Clos
final INodesInPath inodesInPath = rootDir.getINodesInPath4Write(
normalizePath(src), false);
if (!deleteAllowed(inodesInPath, src) ) {
- filesRemoved = 0;
+ filesRemoved = -1;
} else {
// Before removing the node, first check if the targetNode is for a
// snapshottable dir with snapshots, or its descendants have
@@ -1041,10 +1041,10 @@ public class FSDirectory implements Clos
} finally {
writeUnlock();
}
- fsImage.getEditLog().logDelete(src, now);
- if (filesRemoved <= 0) {
+ if (filesRemoved < 0) {
return false;
}
+ fsImage.getEditLog().logDelete(src, now);
incrDeletedFileCount(filesRemoved);
// Blocks will be deleted later by the caller of this method
getFSNamesystem().removePathAndBlocks(src, null);
@@ -1107,8 +1107,8 @@ public class FSDirectory implements Clos
final INodesInPath inodesInPath = rootDir.getINodesInPath4Write(
normalizePath(src), false);
final int filesRemoved = deleteAllowed(inodesInPath, src)?
- unprotectedDelete(inodesInPath, collectedBlocks, mtime): 0;
- if (filesRemoved > 0) {
+ unprotectedDelete(inodesInPath, collectedBlocks, mtime): -1;
+ if (filesRemoved >= 0) {
getFSNamesystem().removePathAndBlocks(src, collectedBlocks);
}
}
@@ -1128,7 +1128,7 @@ public class FSDirectory implements Clos
// check if target node exists
INode targetNode = iip.getLastINode();
if (targetNode == null) {
- return 0;
+ return -1;
}
// record modification
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Thu Mar 7 22:34:51 2013
@@ -5664,8 +5664,7 @@ public class FSNamesystem implements Nam
//TODO: need to update metrics in corresponding SnapshotManager method
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "allowSnapshot", path, null, null);
+ logAuditEvent(true, "allowSnapshot", path, null, null);
}
}
@@ -5692,8 +5691,7 @@ public class FSNamesystem implements Nam
//TODO: need to update metrics in corresponding SnapshotManager method
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "disallowSnapshot", path, null, null);
+ logAuditEvent(true, "disallowSnapshot", path, null, null);
}
}
@@ -5729,8 +5727,8 @@ public class FSNamesystem implements Nam
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
Path rootPath = new Path(snapshotRoot, HdfsConstants.DOT_SNAPSHOT_DIR
+ Path.SEPARATOR + snapshotName);
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "createSnapshot", snapshotRoot, rootPath.toString(), null);
+ logAuditEvent(true, "createSnapshot", snapshotRoot, rootPath.toString(),
+ null);
}
}
@@ -5768,8 +5766,7 @@ public class FSNamesystem implements Nam
+ "/" + snapshotOldName);
Path newSnapshotRoot = new Path(path, HdfsConstants.DOT_SNAPSHOT_DIR
+ "/" + snapshotNewName);
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "renameSnapshot", oldSnapshotRoot.toString(),
+ logAuditEvent(true, "renameSnapshot", oldSnapshotRoot.toString(),
newSnapshotRoot.toString(), null);
}
}
@@ -5795,8 +5792,7 @@ public class FSNamesystem implements Nam
readUnlock();
}
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "listSnapshottableDirectory", null, null, null);
+ logAuditEvent(true, "listSnapshottableDirectory", null, null, null);
}
return status;
}
@@ -5828,8 +5824,7 @@ public class FSNamesystem implements Nam
}
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "computeSnapshotDiff", null, null, null);
+ logAuditEvent(true, "computeSnapshotDiff", null, null, null);
}
return diffs != null ? diffs.generateReport() : new SnapshotDiffReport(
path, fromSnapshot, toSnapshot,
@@ -5874,8 +5869,7 @@ public class FSNamesystem implements Nam
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
Path rootPath = new Path(snapshotRoot, HdfsConstants.DOT_SNAPSHOT_DIR
+ Path.SEPARATOR + snapshotName);
- logAuditEvent(UserGroupInformation.getCurrentUser(), getRemoteIp(),
- "deleteSnapshot", rootPath.toString(), null, null);
+ logAuditEvent(true, "deleteSnapshot", rootPath.toString(), null, null);
}
}
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java Thu Mar 7 22:34:51 2013
@@ -303,6 +303,7 @@ public class INodeFile extends INode imp
@Override
public int destroyAndCollectBlocks(BlocksMapUpdateInfo collectedBlocks) {
+ int total = 1;
if (blocks != null && collectedBlocks != null) {
for (BlockInfo blk : blocks) {
collectedBlocks.addDeleteBlock(blk);
@@ -311,7 +312,11 @@ public class INodeFile extends INode imp
}
setBlocks(null);
clearReferences();
- return 1;
+
+ if (this instanceof FileWithSnapshot) {
+ total += ((FileWithSnapshot) this).getDiffs().clear();
+ }
+ return total;
}
@Override
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/AbstractINodeDiffList.java Thu Mar 7 22:34:51 2013
@@ -50,7 +50,7 @@ abstract class AbstractINodeDiffList<N e
}
/** Get the size of the list and then clear it. */
- int clear() {
+ public int clear() {
final int n = diffs.size();
diffs.clear();
return n;
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileUnderConstructionWithSnapshot.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileUnderConstructionWithSnapshot.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileUnderConstructionWithSnapshot.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileUnderConstructionWithSnapshot.java Thu Mar 7 22:34:51 2013
@@ -121,7 +121,7 @@ public class INodeFileUnderConstructionW
} else { // delete a snapshot
return diffs.deleteSnapshotDiff(snapshot, prior, this, collectedBlocks);
}
- return 1;
+ return prior == null ? 1 : 0;
}
@Override
Modified: hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileWithSnapshot.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileWithSnapshot.java?rev=1454138&r1=1454137&r2=1454138&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileWithSnapshot.java (original)
+++ hadoop/common/branches/HDFS-2802/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeFileWithSnapshot.java Thu Mar 7 22:34:51 2013
@@ -22,8 +22,6 @@ import org.apache.hadoop.hdfs.protocol.N
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
-import com.google.common.base.Preconditions;
-
/**
* Represent an {@link INodeFile} that is snapshotted.
* Note that snapshot files are represented by {@link INodeFileSnapshot}.
@@ -94,15 +92,7 @@ public class INodeFileWithSnapshot exten
} else { // delete a snapshot
return diffs.deleteSnapshotDiff(snapshot, prior, this, collectedBlocks);
}
- return 1;
- }
-
- @Override
- public int destroyAndCollectBlocks(
- final BlocksMapUpdateInfo collectedBlocks) {
- Preconditions.checkState(this.isCurrentFileDeleted);
- final int n = diffs.clear();
- return n + super.destroyAndCollectBlocks(collectedBlocks);
+ return prior == null ? 1 : 0;
}
@Override