HDFS-5999. Do not create rollback fsimage when it already exists. Contributed by Jing Zhao.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1571096 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jing Zhao 2014-02-23 21:35:07 +00:00
parent e804c924fe
commit 8e7a2b8d5d
4 changed files with 25 additions and 11 deletions

View File

@ -73,3 +73,5 @@ HDFS-5535 subtasks:
TestOfflineEditsViewer. (szetszwo)
HDFS-5994. Fix TestDataNodeRollingUpgrade. (Arpit Agarwal via szetszwo)
HDFS-5999. Do not create rollback fsimage when it already exists. (jing9)

View File

@ -727,12 +727,10 @@ private long applyEditLogOp(FSEditLogOp op, FSDirectory fsDir,
break;
}
}
// save namespace if this is not the second edit transaction
// (the first must be OP_START_LOG_SEGMENT)
final boolean saveNamespace = totalEdits > 1;
// save namespace if there is no rollback image existing
final long startTime = ((RollingUpgradeOp) op).getTime();
fsNamesys.startRollingUpgradeInternal(startTime, saveNamespace);
fsNamesys.startRollingUpgradeInternal(startTime, op.txid - 2);
break;
}
case OP_ROLLING_UPGRADE_FINALIZE: {

View File

@ -327,6 +327,21 @@ void checkUpgrade(FSNamesystem target) throws IOException {
}
}
/**
* @return true if there is rollback fsimage (for rolling upgrade) for the
* given txid in storage.
*/
boolean hasRollbackFSImage(long txid) {
for (StorageDirectory sd : storage.dirIterable(NameNodeDirType.IMAGE)) {
final File rollbackImageFile = NNStorage.getStorageFile(sd,
NameNodeFile.IMAGE_ROLLBACK, txid);
if (rollbackImageFile.exists()) {
return true;
}
}
return false;
}
void doUpgrade(FSNamesystem target) throws IOException {
checkUpgrade(target);
@ -1071,7 +1086,7 @@ void purgeCheckpoints(NameNodeFile nnf) {
}
/**
* Renames new image
* Rename FSImage
*/
private void renameCheckpoint(long txid, NameNodeFile fromNnf,
NameNodeFile toNnf, boolean renameMD5) throws IOException {

View File

@ -7147,7 +7147,7 @@ RollingUpgradeInfo startRollingUpgrade() throws IOException {
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Failed to start rolling upgrade");
startRollingUpgradeInternal(now(), true);
startRollingUpgradeInternal(now(), -1);
getEditLog().logStartRollingUpgrade(rollingUpgradeInfo.getStartTime());
} finally {
writeUnlock();
@ -7165,15 +7165,14 @@ RollingUpgradeInfo startRollingUpgrade() throws IOException {
* Update internal state to indicate that a rolling upgrade is in progress.
* Ootionally create a checkpoint before starting the RU.
* @param startTime
* @param saveNamespace If true then a checkpoint is created before initiating
* the rolling upgrade.
*/
void startRollingUpgradeInternal(long startTime, boolean saveNamespace)
void startRollingUpgradeInternal(long startTime, long txid)
throws IOException {
checkRollingUpgrade("start rolling upgrade");
getFSImage().checkUpgrade(this);
if (saveNamespace) {
// if we have not made a rollback image, do it
if (txid < 0 || !getFSImage().hasRollbackFSImage(txid)) {
getFSImage().saveNamespace(this, NameNodeFile.IMAGE_ROLLBACK, null);
LOG.info("Successfully saved namespace for preparing rolling upgrade.");
}