|
@@ -42,7 +42,6 @@ import org.apache.hadoop.hdfs.HAUtil;
|
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
|
import org.apache.hadoop.hdfs.protocol.LayoutVersion;
|
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
|
|
|
-import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.RollingUpgradeStartupOption;
|
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
|
|
import org.apache.hadoop.hdfs.server.common.InconsistentFSStateException;
|
|
|
import org.apache.hadoop.hdfs.server.common.Storage;
|
|
@@ -549,9 +548,8 @@ public class FSImage implements Closeable {
|
|
|
private boolean loadFSImage(FSNamesystem target, StartupOption startOpt,
|
|
|
MetaRecoveryContext recovery)
|
|
|
throws IOException {
|
|
|
- final boolean rollingRollback = startOpt == StartupOption.ROLLINGUPGRADE
|
|
|
- && startOpt.getRollingUpgradeStartupOption() ==
|
|
|
- RollingUpgradeStartupOption.ROLLBACK;
|
|
|
+ final boolean rollingRollback = StartupOption
|
|
|
+ .isRollingUpgradeRollback(startOpt);
|
|
|
final NameNodeFile nnf = rollingRollback ? NameNodeFile.IMAGE_ROLLBACK
|
|
|
: NameNodeFile.IMAGE;
|
|
|
final FSImageStorageInspector inspector = storage.readAndInspectDirs(nnf);
|
|
@@ -647,9 +645,17 @@ public class FSImage implements Closeable {
|
|
|
// discard discard unnecessary editlog segments starting from the given id
|
|
|
this.editLog.discardSegments(discardSegmentTxId);
|
|
|
// rename the special checkpoint
|
|
|
- renameCheckpoint(ckptId, NameNodeFile.IMAGE_ROLLBACK, NameNodeFile.IMAGE);
|
|
|
+ renameCheckpoint(ckptId, NameNodeFile.IMAGE_ROLLBACK, NameNodeFile.IMAGE,
|
|
|
+ true);
|
|
|
// purge all the checkpoints after the marker
|
|
|
archivalManager.purgeCheckpoinsAfter(NameNodeFile.IMAGE, ckptId);
|
|
|
+ String nameserviceId = DFSUtil.getNamenodeNameServiceId(conf);
|
|
|
+ if (HAUtil.isHAEnabled(conf, nameserviceId)) {
|
|
|
+ // close the editlog since it is currently open for write
|
|
|
+ this.editLog.close();
|
|
|
+ // reopen the editlog for read
|
|
|
+ this.editLog.initSharedJournalsForRead();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void loadFSImageFile(FSNamesystem target, MetaRecoveryContext recovery,
|
|
@@ -689,18 +695,21 @@ public class FSImage implements Closeable {
|
|
|
// If this NN is not HA
|
|
|
editLog.initJournalsForWrite();
|
|
|
editLog.recoverUnclosedStreams();
|
|
|
- } else if (HAUtil.isHAEnabled(conf, nameserviceId) &&
|
|
|
- startOpt == StartupOption.UPGRADE) {
|
|
|
- // This NN is HA, but we're doing an upgrade so init the edit log for
|
|
|
- // write.
|
|
|
+ } else if (HAUtil.isHAEnabled(conf, nameserviceId)
|
|
|
+ && (startOpt == StartupOption.UPGRADE || StartupOption
|
|
|
+ .isRollingUpgradeRollback(startOpt))) {
|
|
|
+ // This NN is HA, but we're doing an upgrade or a rollback of rolling
|
|
|
+ // upgrade so init the edit log for write.
|
|
|
editLog.initJournalsForWrite();
|
|
|
- long sharedLogCTime = editLog.getSharedLogCTime();
|
|
|
- if (this.storage.getCTime() < sharedLogCTime) {
|
|
|
- throw new IOException("It looks like the shared log is already " +
|
|
|
- "being upgraded but this NN has not been upgraded yet. You " +
|
|
|
- "should restart this NameNode with the '" +
|
|
|
- StartupOption.BOOTSTRAPSTANDBY.getName() + "' option to bring " +
|
|
|
- "this NN in sync with the other.");
|
|
|
+ if (startOpt == StartupOption.UPGRADE) {
|
|
|
+ long sharedLogCTime = editLog.getSharedLogCTime();
|
|
|
+ if (this.storage.getCTime() < sharedLogCTime) {
|
|
|
+ throw new IOException("It looks like the shared log is already " +
|
|
|
+ "being upgraded but this NN has not been upgraded yet. You " +
|
|
|
+ "should restart this NameNode with the '" +
|
|
|
+ StartupOption.BOOTSTRAPSTANDBY.getName() + "' option to bring " +
|
|
|
+ "this NN in sync with the other.");
|
|
|
+ }
|
|
|
}
|
|
|
editLog.recoverUnclosedStreams();
|
|
|
} else {
|
|
@@ -759,9 +768,8 @@ public class FSImage implements Closeable {
|
|
|
// have been successfully applied before the error.
|
|
|
lastAppliedTxId = loader.getLastAppliedTxId();
|
|
|
}
|
|
|
- boolean rollingRollback = startOpt == StartupOption.ROLLINGUPGRADE &&
|
|
|
- startOpt.getRollingUpgradeStartupOption() ==
|
|
|
- RollingUpgradeStartupOption.ROLLBACK;
|
|
|
+ boolean rollingRollback = StartupOption
|
|
|
+ .isRollingUpgradeRollback(startOpt);
|
|
|
// If we are in recovery mode, we may have skipped over some txids.
|
|
|
if (editIn.getLastTxId() != HdfsConstants.INVALID_TXID
|
|
|
&& !rollingRollback) {
|
|
@@ -1029,7 +1037,7 @@ public class FSImage implements Closeable {
|
|
|
assert false : "should have thrown above!";
|
|
|
}
|
|
|
|
|
|
- renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, nnf);
|
|
|
+ renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, nnf, false);
|
|
|
|
|
|
// Since we now have a new checkpoint, we can clean up some
|
|
|
// old edit logs and checkpoints.
|
|
@@ -1070,12 +1078,12 @@ public class FSImage implements Closeable {
|
|
|
* Renames new image
|
|
|
*/
|
|
|
private void renameCheckpoint(long txid, NameNodeFile fromNnf,
|
|
|
- NameNodeFile toNnf) throws IOException {
|
|
|
+ NameNodeFile toNnf, boolean renameMD5) throws IOException {
|
|
|
ArrayList<StorageDirectory> al = null;
|
|
|
|
|
|
for (StorageDirectory sd : storage.dirIterable(NameNodeDirType.IMAGE)) {
|
|
|
try {
|
|
|
- renameImageFileInDir(sd, fromNnf, toNnf, txid);
|
|
|
+ renameImageFileInDir(sd, fromNnf, toNnf, txid, renameMD5);
|
|
|
} catch (IOException ioe) {
|
|
|
LOG.warn("Unable to rename checkpoint in " + sd, ioe);
|
|
|
if (al == null) {
|
|
@@ -1104,8 +1112,8 @@ public class FSImage implements Closeable {
|
|
|
storage.reportErrorsOnDirectories(al);
|
|
|
}
|
|
|
|
|
|
- private void renameImageFileInDir(StorageDirectory sd,
|
|
|
- NameNodeFile fromNnf, NameNodeFile toNnf, long txid) throws IOException {
|
|
|
+ private void renameImageFileInDir(StorageDirectory sd, NameNodeFile fromNnf,
|
|
|
+ NameNodeFile toNnf, long txid, boolean renameMD5) throws IOException {
|
|
|
final File fromFile = NNStorage.getStorageFile(sd, fromNnf, txid);
|
|
|
final File toFile = NNStorage.getStorageFile(sd, toNnf, txid);
|
|
|
// renameTo fails on Windows if the destination file
|
|
@@ -1119,7 +1127,10 @@ public class FSImage implements Closeable {
|
|
|
throw new IOException("renaming " + fromFile.getAbsolutePath() + " to " +
|
|
|
toFile.getAbsolutePath() + " FAILED");
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (renameMD5) {
|
|
|
+ MD5FileUtils.renameMD5File(fromFile, toFile);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
CheckpointSignature rollEditLog() throws IOException {
|
|
@@ -1218,7 +1229,7 @@ public class FSImage implements Closeable {
|
|
|
CheckpointFaultInjector.getInstance().afterMD5Rename();
|
|
|
|
|
|
// Rename image from tmp file
|
|
|
- renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, NameNodeFile.IMAGE);
|
|
|
+ renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, NameNodeFile.IMAGE, false);
|
|
|
// So long as this is the newest image available,
|
|
|
// advertise it as such to other checkpointers
|
|
|
// from now on
|