HDFS-14751. Synchronize on diffs in DirectoryScanner. Contributed by Lisheng Sun.
This commit is contained in:
parent
313b76f8e9
commit
ecd461f940
@ -349,7 +349,9 @@ public class DirectoryScanner implements Runnable {
|
|||||||
* Clear the current cache of diffs and statistics.
|
* Clear the current cache of diffs and statistics.
|
||||||
*/
|
*/
|
||||||
private void clear() {
|
private void clear() {
|
||||||
|
synchronized (diffs) {
|
||||||
diffs.clear();
|
diffs.clear();
|
||||||
|
}
|
||||||
stats.clear();
|
stats.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,6 +432,7 @@ public class DirectoryScanner implements Runnable {
|
|||||||
// HDFS-14476: run checkAndUpadte with batch to avoid holding the lock too
|
// HDFS-14476: run checkAndUpadte with batch to avoid holding the lock too
|
||||||
// long
|
// long
|
||||||
int loopCount = 0;
|
int loopCount = 0;
|
||||||
|
synchronized (diffs) {
|
||||||
for (final Map.Entry<String, ScanInfo> entry : diffs.getEntries()) {
|
for (final Map.Entry<String, ScanInfo> entry : diffs.getEntries()) {
|
||||||
dataset.checkAndUpdate(entry.getKey(), entry.getValue());
|
dataset.checkAndUpdate(entry.getKey(), entry.getValue());
|
||||||
|
|
||||||
@ -442,6 +445,7 @@ public class DirectoryScanner implements Runnable {
|
|||||||
}
|
}
|
||||||
loopCount++;
|
loopCount++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!retainDiffs) {
|
if (!retainDiffs) {
|
||||||
clear();
|
clear();
|
||||||
@ -545,7 +549,9 @@ public class DirectoryScanner implements Runnable {
|
|||||||
}
|
}
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
|
synchronized (diffs) {
|
||||||
diffs.addAll(bpid, diffRecord);
|
diffs.addAll(bpid, diffRecord);
|
||||||
|
}
|
||||||
LOG.info("Scan Results: {}", statsRecord);
|
LOG.info("Scan Results: {}", statsRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user