Skip to content

Commit 16a2050

Browse files
committed
HDFS-15569. Speed up the Storage#doRecover during datanode rolling upgrade. Contributed by Hemanth Boyina.
1 parent 4ae561b commit 16a2050

File tree

1 file changed

+28
-8
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common

1 file changed

+28
-8
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ public void doRecover(StorageState curState) throws IOException {
801801
case RECOVER_UPGRADE: // mv previous.tmp -> current
802802
LOG.info("Recovering storage directory {} from previous upgrade",
803803
rootPath);
804-
if (curDir.exists())
805-
deleteDir(curDir);
804+
deleteAsync(curDir);
806805
rename(getPreviousTmp(), curDir);
807806
return;
808807
case COMPLETE_ROLLBACK: // rm removed.tmp
@@ -818,29 +817,50 @@ public void doRecover(StorageState curState) throws IOException {
818817
case COMPLETE_FINALIZE: // rm finalized.tmp
819818
LOG.info("Completing previous finalize for storage directory {}",
820819
rootPath);
821-
deleteDir(getFinalizedTmp());
820+
deleteAsync(getFinalizedTmp());
822821
return;
823822
case COMPLETE_CHECKPOINT: // mv lastcheckpoint.tmp -> previous.checkpoint
824823
LOG.info("Completing previous checkpoint for storage directory {}",
825824
rootPath);
826825
File prevCkptDir = getPreviousCheckpoint();
827-
if (prevCkptDir.exists())
828-
deleteDir(prevCkptDir);
826+
deleteAsync(prevCkptDir);
829827
rename(getLastCheckpointTmp(), prevCkptDir);
830828
return;
831829
case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current
832830
LOG.info("Recovering storage directory {} from failed checkpoint",
833831
rootPath);
834-
if (curDir.exists())
835-
deleteDir(curDir);
832+
deleteAsync(curDir);
836833
rename(getLastCheckpointTmp(), curDir);
837834
return;
838835
default:
839836
throw new IOException("Unexpected FS state: " + curState
840837
+ " for storage directory: " + rootPath);
841838
}
842839
}
843-
840+
841+
/**
842+
* Rename the curDir to curDir.tmp and delete the curDir.tmp parallely.
843+
* @throws IOException
844+
*/
845+
private void deleteAsync(File curDir) throws IOException {
846+
if (curDir.exists()) {
847+
File curTmp = new File(curDir.getParent(), curDir.getName() + ".tmp");
848+
if (curTmp.exists()) {
849+
deleteDir(curTmp);
850+
}
851+
rename(curDir, curTmp);
852+
new Thread("Async Delete Current.tmp") {
853+
public void run() {
854+
try {
855+
deleteDir(curTmp);
856+
} catch (IOException e) {
857+
LOG.warn("Deleting storage directory {} failed", curTmp);
858+
}
859+
}
860+
}.start();
861+
}
862+
}
863+
844864
/**
845865
* @return true if the storage directory should prompt the user prior
846866
* to formatting (i.e if the directory appears to contain some data)

0 commit comments

Comments
 (0)