|
@@ -592,6 +592,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
private boolean resourceLowSafeMode = false;
|
|
private boolean resourceLowSafeMode = false;
|
|
private String nameNodeHostName = null;
|
|
private String nameNodeHostName = null;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * HDFS-14497: Concurrency control when many metaSave request to write
|
|
|
|
+ * meta to same out stream after switch to read lock.
|
|
|
|
+ */
|
|
|
|
+ private Object metaSaveLock = new Object();
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Notify that loading of this FSDirectory is complete, and
|
|
* Notify that loading of this FSDirectory is complete, and
|
|
* it is imageLoaded for use
|
|
* it is imageLoaded for use
|
|
@@ -1769,24 +1775,26 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
String operationName = "metaSave";
|
|
String operationName = "metaSave";
|
|
checkSuperuserPrivilege(operationName);
|
|
checkSuperuserPrivilege(operationName);
|
|
checkOperation(OperationCategory.READ);
|
|
checkOperation(OperationCategory.READ);
|
|
- writeLock();
|
|
|
|
|
|
+ readLock();
|
|
try {
|
|
try {
|
|
checkOperation(OperationCategory.READ);
|
|
checkOperation(OperationCategory.READ);
|
|
- File file = new File(System.getProperty("hadoop.log.dir"), filename);
|
|
|
|
- PrintWriter out = new PrintWriter(new BufferedWriter(
|
|
|
|
- new OutputStreamWriter(Files.newOutputStream(file.toPath()),
|
|
|
|
- Charsets.UTF_8)));
|
|
|
|
- metaSave(out);
|
|
|
|
- out.flush();
|
|
|
|
- out.close();
|
|
|
|
|
|
+ synchronized(metaSaveLock) {
|
|
|
|
+ File file = new File(System.getProperty("hadoop.log.dir"), filename);
|
|
|
|
+ PrintWriter out = new PrintWriter(new BufferedWriter(
|
|
|
|
+ new OutputStreamWriter(Files.newOutputStream(file.toPath()),
|
|
|
|
+ Charsets.UTF_8)));
|
|
|
|
+ metaSave(out);
|
|
|
|
+ out.flush();
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
} finally {
|
|
} finally {
|
|
- writeUnlock(operationName);
|
|
|
|
|
|
+ readUnlock(operationName);
|
|
}
|
|
}
|
|
logAuditEvent(true, operationName, null);
|
|
logAuditEvent(true, operationName, null);
|
|
}
|
|
}
|
|
|
|
|
|
private void metaSave(PrintWriter out) {
|
|
private void metaSave(PrintWriter out) {
|
|
- assert hasWriteLock();
|
|
|
|
|
|
+ assert hasReadLock();
|
|
long totalInodes = this.dir.totalInodes();
|
|
long totalInodes = this.dir.totalInodes();
|
|
long totalBlocks = this.getBlocksTotal();
|
|
long totalBlocks = this.getBlocksTotal();
|
|
out.println(totalInodes + " files and directories, " + totalBlocks
|
|
out.println(totalInodes + " files and directories, " + totalBlocks
|