|
@@ -1743,26 +1743,29 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
* Create a new file entry in the namespace.
|
|
|
*
|
|
|
* For description of parameters and exceptions thrown see
|
|
|
- * {@link ClientProtocol#create()}
|
|
|
+ * {@link ClientProtocol#create()}, except it returns valid file status
|
|
|
+ * upon success
|
|
|
*/
|
|
|
- void startFile(String src, PermissionStatus permissions, String holder,
|
|
|
- String clientMachine, EnumSet<CreateFlag> flag, boolean createParent,
|
|
|
- short replication, long blockSize) throws AccessControlException,
|
|
|
- SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
+ HdfsFileStatus startFile(String src, PermissionStatus permissions,
|
|
|
+ String holder, String clientMachine, EnumSet<CreateFlag> flag,
|
|
|
+ boolean createParent, short replication, long blockSize)
|
|
|
+ throws AccessControlException, SafeModeException,
|
|
|
+ FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
|
try {
|
|
|
- startFileInt(src, permissions, holder, clientMachine, flag, createParent,
|
|
|
- replication, blockSize);
|
|
|
+ return startFileInt(src, permissions, holder, clientMachine, flag,
|
|
|
+ createParent, replication, blockSize);
|
|
|
} catch (AccessControlException e) {
|
|
|
logAuditEvent(false, "create", src);
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void startFileInt(String src, PermissionStatus permissions, String holder,
|
|
|
- String clientMachine, EnumSet<CreateFlag> flag, boolean createParent,
|
|
|
- short replication, long blockSize) throws AccessControlException,
|
|
|
- SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
+ private HdfsFileStatus startFileInt(String src, PermissionStatus permissions,
|
|
|
+ String holder, String clientMachine, EnumSet<CreateFlag> flag,
|
|
|
+ boolean createParent, short replication, long blockSize)
|
|
|
+ throws AccessControlException, SafeModeException,
|
|
|
+ FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
|
if (NameNode.stateChangeLog.isDebugEnabled()) {
|
|
|
NameNode.stateChangeLog.debug("DIR* NameSystem.startFile: src=" + src
|
|
@@ -1777,12 +1780,14 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
boolean skipSync = false;
|
|
|
+ final HdfsFileStatus stat;
|
|
|
FSPermissionChecker pc = getPermissionChecker();
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
writeLock();
|
|
|
try {
|
|
|
startFileInternal(pc, src, permissions, holder, clientMachine, flag,
|
|
|
createParent, replication, blockSize);
|
|
|
+ stat = dir.getFileInfo(src, false);
|
|
|
} catch (StandbyException se) {
|
|
|
skipSync = true;
|
|
|
throw se;
|
|
@@ -1794,8 +1799,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
getEditLog().logSync();
|
|
|
}
|
|
|
}
|
|
|
- final HdfsFileStatus stat = getAuditFileInfo(src, false);
|
|
|
logAuditEvent(true, "create", src, null, stat);
|
|
|
+ return stat;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2156,11 +2161,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
* are replicated. Will return an empty 2-elt array if we want the
|
|
|
* client to "try again later".
|
|
|
*/
|
|
|
- LocatedBlock getAdditionalBlock(String src,
|
|
|
- String clientName,
|
|
|
- ExtendedBlock previous,
|
|
|
- HashMap<Node, Node> excludedNodes
|
|
|
- )
|
|
|
+ LocatedBlock getAdditionalBlock(String src, long fileId, String clientName,
|
|
|
+ ExtendedBlock previous, HashMap<Node, Node> excludedNodes)
|
|
|
throws LeaseExpiredException, NotReplicatedYetException,
|
|
|
QuotaExceededException, SafeModeException, UnresolvedLinkException,
|
|
|
IOException {
|
|
@@ -2181,7 +2183,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
checkOperation(OperationCategory.READ);
|
|
|
LocatedBlock[] onRetryBlock = new LocatedBlock[1];
|
|
|
final INode[] inodes = analyzeFileState(
|
|
|
- src, clientName, previous, onRetryBlock).getINodes();
|
|
|
+ src, fileId, clientName, previous, onRetryBlock).getINodes();
|
|
|
final INodeFileUnderConstruction pendingFile =
|
|
|
(INodeFileUnderConstruction) inodes[inodes.length - 1];
|
|
|
|
|
@@ -2213,7 +2215,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
// while chooseTarget() was executing.
|
|
|
LocatedBlock[] onRetryBlock = new LocatedBlock[1];
|
|
|
INodesInPath inodesInPath =
|
|
|
- analyzeFileState(src, clientName, previous, onRetryBlock);
|
|
|
+ analyzeFileState(src, fileId, clientName, previous, onRetryBlock);
|
|
|
final INode[] inodes = inodesInPath.getINodes();
|
|
|
final INodeFileUnderConstruction pendingFile =
|
|
|
(INodeFileUnderConstruction) inodes[inodes.length - 1];
|
|
@@ -2245,6 +2247,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
INodesInPath analyzeFileState(String src,
|
|
|
+ long fileId,
|
|
|
String clientName,
|
|
|
ExtendedBlock previous,
|
|
|
LocatedBlock[] onRetryBlock)
|
|
@@ -2265,7 +2268,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
final INodesInPath inodesInPath = dir.rootDir.getExistingPathINodes(src, true);
|
|
|
final INode[] inodes = inodesInPath.getINodes();
|
|
|
final INodeFileUnderConstruction pendingFile
|
|
|
- = checkLease(src, clientName, inodes[inodes.length - 1]);
|
|
|
+ = checkLease(src, fileId, clientName, inodes[inodes.length - 1]);
|
|
|
BlockInfo lastBlockInFile = pendingFile.getLastBlock();
|
|
|
if (!Block.matchingIdAndGenStamp(previousBlock, lastBlockInFile)) {
|
|
|
// The block that the client claims is the current last block
|
|
@@ -2436,14 +2439,17 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
// make sure that we still have the lease on this file.
|
|
|
- private INodeFileUnderConstruction checkLease(String src, String holder)
|
|
|
- throws LeaseExpiredException, UnresolvedLinkException {
|
|
|
+ private INodeFileUnderConstruction checkLease(String src, String holder)
|
|
|
+ throws LeaseExpiredException, UnresolvedLinkException,
|
|
|
+ FileNotFoundException {
|
|
|
assert hasReadOrWriteLock();
|
|
|
- return checkLease(src, holder, dir.getINode(src));
|
|
|
+ return checkLease(src, INodeId.GRANDFATHER_INODE_ID, holder,
|
|
|
+ dir.getINode(src));
|
|
|
}
|
|
|
-
|
|
|
- private INodeFileUnderConstruction checkLease(String src, String holder,
|
|
|
- INode file) throws LeaseExpiredException {
|
|
|
+
|
|
|
+ private INodeFileUnderConstruction checkLease(String src, long fileId,
|
|
|
+ String holder, INode file) throws LeaseExpiredException,
|
|
|
+ FileNotFoundException {
|
|
|
assert hasReadOrWriteLock();
|
|
|
if (file == null || !(file instanceof INodeFile)) {
|
|
|
Lease lease = leaseManager.getLease(holder);
|
|
@@ -2464,6 +2470,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
throw new LeaseExpiredException("Lease mismatch on " + src + " owned by "
|
|
|
+ pendingFile.getClientName() + " but is accessed by " + holder);
|
|
|
}
|
|
|
+ INodeId.checkId(fileId, pendingFile);
|
|
|
return pendingFile;
|
|
|
}
|
|
|
|