Skip to content

Commit 8612062

Browse files
committed
HDFS-16689. Modify code based on comment
1 parent 8cd18a1 commit 8612062

File tree

7 files changed

+16
-51
lines changed

7 files changed

+16
-51
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,17 +1654,25 @@ synchronized void logEdit(final int length, final byte[] data) {
16541654
endTransaction(start);
16551655
}
16561656

1657+
void recoverUnclosedStreams() throws IOException {
1658+
recoverUnclosedStreams(false);
1659+
}
1660+
16571661
/**
16581662
* Run recovery on all journals to recover any unclosed segments
16591663
*/
1660-
synchronized void recoverUnclosedStreams() throws IOException {
1664+
synchronized void recoverUnclosedStreams(boolean terminateOnFailure) throws IOException {
16611665
Preconditions.checkState(
16621666
state == State.BETWEEN_LOG_SEGMENTS,
16631667
"May not recover segments - wrong state: %s", state);
16641668
try {
16651669
journalSet.recoverUnfinalizedSegments();
16661670
} catch (IOException ex) {
1667-
throw new UnrecoverEditsException("Failed recover unclosed segments", ex);
1671+
// All journals have failed, it is handled in logSync.
1672+
// TODO: are we sure this is OK?
1673+
if (terminateOnFailure) {
1674+
throw ex;
1675+
}
16681676
}
16691677
}
16701678

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ protected FSImage(Configuration conf,
175175
archivalManager = new NNStorageRetentionManager(conf, storage, editLog);
176176
FSImageFormatProtobuf.initParallelLoad(conf);
177177
}
178-
179-
@VisibleForTesting
180-
void setEditLog(FSEditLog editLog) {
181-
this.editLog = editLog;
182-
}
183178

184179
void format(FSNamesystem fsn, String clusterId, boolean force)
185180
throws IOException {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
import org.apache.hadoop.util.StringUtils;
137137
import org.apache.hadoop.util.VersionInfo;
138138

139-
import static org.apache.hadoop.util.ExitUtil.terminate;
140139
import static org.apache.hadoop.util.Time.now;
141140
import static org.apache.hadoop.util.Time.monotonicNow;
142141
import static org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics.TOPMETRICS_METRICS_SOURCE_NAME;
@@ -1287,8 +1286,6 @@ void loadFSImage(StartupOption startOpt) throws IOException {
12871286
fsImage.openEditLogForWrite(getEffectiveLayoutVersion());
12881287
}
12891288
success = true;
1290-
} catch (UnrecoverEditsException e) {
1291-
terminate(1, e.getLocalizedMessage());
12921289
} finally {
12931290
if (!success) {
12941291
fsImage.close();
@@ -1392,7 +1389,7 @@ void startActiveServices() throws IOException {
13921389
// During startup, we're already open for write during initialization.
13931390
editLog.initJournalsForWrite();
13941391
// May need to recover
1395-
editLog.recoverUnclosedStreams();
1392+
editLog.recoverUnclosedStreams(true);
13961393

13971394
LOG.info("Catching up to latest edits from old active before " +
13981395
"taking over writer role in edits logs");

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/UnrecoverEditsException.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/EditLogTailer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public void stop() throws IOException {
283283
}
284284

285285
@VisibleForTesting
286-
public FSEditLog getEditLog() {
286+
FSEditLog getEditLog() {
287287
return editLog;
288288
}
289289

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestNNWithQJM.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ public void testMismatchedNNIsRejected() throws Exception {
198198
.build();
199199
fail("New NN with different namespace should have been rejected");
200200
} catch (ExitException ee) {
201-
GenericTestUtils.assertExceptionContains("Failed recover unclosed segments", ee);
201+
GenericTestUtils.assertExceptionContains(
202+
"Unable to start log segment 1: too few journals", ee);
202203
assertTrue("Didn't terminate properly ", ExitUtil.terminateCalled());
203204
}
204205
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestHAWithInProgressTail.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.fs.permission.FsPermission;
2222
import org.apache.hadoop.hdfs.DFSConfigKeys;
23+
import org.apache.hadoop.hdfs.DFSTestUtil;
2324
import org.apache.hadoop.hdfs.HAUtil;
2425
import org.apache.hadoop.hdfs.MiniDFSCluster;
2526
import org.apache.hadoop.hdfs.qjournal.MiniJournalCluster;
@@ -99,7 +100,7 @@ private void spyFSEditLog() throws IOException {
99100
}
100101
).when(spyEditLog).recoverUnclosedStreams();
101102

102-
nn1.getNamesystem().getFSImage().setEditLog(spyEditLog);
103+
DFSTestUtil.setEditLogForTesting(nn1.getNamesystem(), spyEditLog);
103104
nn1.getNamesystem().getEditLogTailer().setEditLog(spyEditLog);
104105
}
105106

0 commit comments

Comments
 (0)