HDFS-3884. Journal format() should reset cached values. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-3077@1380979 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2012-09-05 04:27:49 +00:00
parent 72485f3112
commit f6b7f067c3
3 changed files with 34 additions and 2 deletions

View File

@ -40,3 +40,5 @@ HDFS-3877. QJM: Provide defaults for dfs.journalnode.*address (eli)
HDFS-3863. Track last "committed" txid in QJM (todd)
HDFS-3869. Expose non-file journal manager details in web UI (todd)
HDFS-3884. Journal format() should reset cached values (todd)

View File

@ -105,6 +105,19 @@ class Journal implements Closeable {
Journal(File logDir, StorageErrorReporter errorReporter) throws IOException {
storage = new JNStorage(logDir, errorReporter);
refreshCachedData();
this.fjm = storage.getJournalManager();
}
/**
* Reload any data that may have been cached. This is necessary
* when we first load the Journal, but also after any formatting
* operation, since the cached data is no longer relevant.
*/
private synchronized void refreshCachedData() {
IOUtils.closeStream(committedTxnId);
File currentDir = storage.getSingularStorageDir().getCurrentDir();
this.lastPromisedEpoch = new PersistentLongFile(
new File(currentDir, LAST_PROMISED_FILENAME), 0);
@ -113,8 +126,6 @@ class Journal implements Closeable {
this.committedTxnId = new BestEffortLongFile(
new File(currentDir, COMMITTED_TXID_FILENAME),
HdfsConstants.INVALID_TXID);
this.fjm = storage.getJournalManager();
}
/**
@ -156,6 +167,7 @@ class Journal implements Closeable {
LOG.info("Formatting " + this + " with namespace info: " +
nsInfo);
storage.format(nsInfo);
refreshCachedData();
}
/**
@ -180,6 +192,11 @@ class Journal implements Closeable {
checkFormatted();
return lastPromisedEpoch.get();
}
synchronized public long getLastWriterEpoch() throws IOException {
checkFormatted();
return lastWriterEpoch.get();
}
synchronized long getCommittedTxnIdForTests() throws IOException {
return committedTxnId.get();

View File

@ -148,6 +148,19 @@ public class TestJournal {
assertEquals(1, newEpoch.getLastSegmentTxId());
}
@Test
public void testFormatResetsCachedValues() throws Exception {
journal.newEpoch(FAKE_NSINFO, 12345L);
journal.startLogSegment(new RequestInfo(JID, 12345L, 1L, 0L), 1L);
assertEquals(12345L, journal.getLastPromisedEpoch());
assertEquals(12345L, journal.getLastWriterEpoch());
journal.format(FAKE_NSINFO_2);
assertEquals(0, journal.getLastPromisedEpoch());
assertEquals(0, journal.getLastWriterEpoch());
}
/**
* Test that, if the writer crashes at the very beginning of a segment,
* before any transactions are written, that the next newEpoch() call