|
@@ -1704,16 +1704,25 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
short replication, long blockSize) throws AccessControlException,
|
|
|
SafeModeException, FileAlreadyExistsException, UnresolvedLinkException,
|
|
|
FileNotFoundException, ParentNotDirectoryException, IOException {
|
|
|
+ boolean skipSync = false;
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
|
|
|
|
startFileInternal(src, permissions, holder, clientMachine, flag,
|
|
|
createParent, replication, blockSize);
|
|
|
+ } catch (StandbyException se) {
|
|
|
+ skipSync = true;
|
|
|
+ throw se;
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
|
- }
|
|
|
- getEditLog().logSync();
|
|
|
+ // There might be transactions logged while trying to recover the lease.
|
|
|
+ // They need to be sync'ed even when an exception was thrown.
|
|
|
+ if (!skipSync) {
|
|
|
+ getEditLog().logSync();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (auditLog.isInfoEnabled() && isExternalInvocation()) {
|
|
|
final HdfsFileStatus stat = dir.getFileInfo(src, false);
|
|
|
logAuditEvent(UserGroupInformation.getCurrentUser(),
|
|
@@ -1894,6 +1903,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
*/
|
|
|
boolean recoverLease(String src, String holder, String clientMachine)
|
|
|
throws IOException {
|
|
|
+ boolean skipSync = false;
|
|
|
writeLock();
|
|
|
try {
|
|
|
checkOperation(OperationCategory.WRITE);
|
|
@@ -1915,8 +1925,16 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
}
|
|
|
|
|
|
recoverLeaseInternal(inode, src, holder, clientMachine, true);
|
|
|
+ } catch (StandbyException se) {
|
|
|
+ skipSync = true;
|
|
|
+ throw se;
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
|
+ // There might be transactions logged while trying to recover the lease.
|
|
|
+ // They need to be sync'ed even when an exception was thrown.
|
|
|
+ if (!skipSync) {
|
|
|
+ getEditLog().logSync();
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -2019,6 +2037,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
throws AccessControlException, SafeModeException,
|
|
|
FileAlreadyExistsException, FileNotFoundException,
|
|
|
ParentNotDirectoryException, IOException {
|
|
|
+ boolean skipSync = false;
|
|
|
if (!supportAppends) {
|
|
|
throw new UnsupportedOperationException(
|
|
|
"Append is not enabled on this NameNode. Use the " +
|
|
@@ -2032,10 +2051,17 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
lb = startFileInternal(src, null, holder, clientMachine,
|
|
|
EnumSet.of(CreateFlag.APPEND),
|
|
|
false, blockManager.maxReplication, 0);
|
|
|
+ } catch (StandbyException se) {
|
|
|
+ skipSync = true;
|
|
|
+ throw se;
|
|
|
} finally {
|
|
|
writeUnlock();
|
|
|
+ // There might be transactions logged while trying to recover the lease.
|
|
|
+ // They need to be sync'ed even when an exception was thrown.
|
|
|
+ if (!skipSync) {
|
|
|
+ getEditLog().logSync();
|
|
|
+ }
|
|
|
}
|
|
|
- getEditLog().logSync();
|
|
|
if (lb != null) {
|
|
|
if (NameNode.stateChangeLog.isDebugEnabled()) {
|
|
|
NameNode.stateChangeLog.debug("DIR* NameSystem.appendFile: file "
|
|
@@ -2959,7 +2985,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
* RecoveryInProgressException if lease recovery is in progress.<br>
|
|
|
* IOException in case of an error.
|
|
|
* @return true if file has been successfully finalized and closed or
|
|
|
- * false if block recovery has been initiated
|
|
|
+ * false if block recovery has been initiated. Since the lease owner
|
|
|
+ * has been changed and logged, caller should call logSync().
|
|
|
*/
|
|
|
boolean internalReleaseLease(Lease lease, String src,
|
|
|
String recoveryLeaseHolder) throws AlreadyBeingCreatedException,
|
|
@@ -3080,6 +3107,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
assert hasWriteLock();
|
|
|
if(newHolder == null)
|
|
|
return lease;
|
|
|
+ // The following transaction is not synced. Make sure it's sync'ed later.
|
|
|
logReassignLease(lease.getHolder(), src, newHolder);
|
|
|
return reassignLeaseInternal(lease, src, newHolder, pendingFile);
|
|
|
}
|
|
@@ -5179,13 +5207,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
|
|
|
private void logReassignLease(String leaseHolder, String src,
|
|
|
String newHolder) {
|
|
|
- writeLock();
|
|
|
- try {
|
|
|
- getEditLog().logReassignLease(leaseHolder, src, newHolder);
|
|
|
- } finally {
|
|
|
- writeUnlock();
|
|
|
- }
|
|
|
- getEditLog().logSync();
|
|
|
+ assert hasWriteLock();
|
|
|
+ getEditLog().logReassignLease(leaseHolder, src, newHolder);
|
|
|
}
|
|
|
|
|
|
/**
|