HDFS-14537. Journaled Edits Cache is not cleared when formatting the JN. Contributed by Ranith Sardar.

This commit is contained in:
Wei-Chiu Chuang 2019-06-18 22:28:21 -07:00 committed by Chen Liang
parent 2fe15053ab
commit 9599c91518
1 changed files with 16 additions and 8 deletions

View File

@ -137,12 +137,14 @@ public class Journal implements Closeable {
private final FileJournalManager fjm;
private final JournaledEditsCache cache;
private JournaledEditsCache cache;
private final JournalMetrics metrics;
private long lastJournalTimestamp = 0;
private Configuration conf = null;
/**
* Time threshold for sync calls, beyond which a warning should be logged to the console.
*/
@ -151,6 +153,7 @@ public class Journal implements Closeable {
Journal(Configuration conf, File logDir, String journalId,
StartupOption startOpt, StorageErrorReporter errorReporter)
throws IOException {
this.conf = conf;
storage = new JNStorage(conf, logDir, startOpt, errorReporter);
this.journalId = journalId;
@ -158,13 +161,8 @@ public class Journal implements Closeable {
this.fjm = storage.getJournalManager();
if (conf.getBoolean(DFSConfigKeys.DFS_HA_TAILEDITS_INPROGRESS_KEY,
DFSConfigKeys.DFS_HA_TAILEDITS_INPROGRESS_DEFAULT)) {
this.cache = new JournaledEditsCache(conf);
} else {
this.cache = null;
}
this.cache = createCache();
this.metrics = JournalMetrics.create(this);
EditLogFile latest = scanStorageForLatestEdits();
@ -173,6 +171,15 @@ public class Journal implements Closeable {
}
}
private JournaledEditsCache createCache() {
if (conf.getBoolean(DFSConfigKeys.DFS_HA_TAILEDITS_INPROGRESS_KEY,
DFSConfigKeys.DFS_HA_TAILEDITS_INPROGRESS_DEFAULT)) {
return new JournaledEditsCache(conf);
} else {
return null;
}
}
/**
* Reload any data that may have been cached. This is necessary
* when we first load the Journal, but also after any formatting
@ -234,6 +241,7 @@ public class Journal implements Closeable {
LOG.info("Formatting journal id : " + journalId + " with namespace info: " +
nsInfo);
storage.format(nsInfo);
this.cache = createCache();
refreshCachedData();
}