@@ -801,8 +801,7 @@ public void doRecover(StorageState curState) throws IOException {
801
801
case RECOVER_UPGRADE : // mv previous.tmp -> current
802
802
LOG .info ("Recovering storage directory {} from previous upgrade" ,
803
803
rootPath );
804
- if (curDir .exists ())
805
- deleteDir (curDir );
804
+ deleteAsync (curDir );
806
805
rename (getPreviousTmp (), curDir );
807
806
return ;
808
807
case COMPLETE_ROLLBACK : // rm removed.tmp
@@ -818,29 +817,50 @@ public void doRecover(StorageState curState) throws IOException {
818
817
case COMPLETE_FINALIZE : // rm finalized.tmp
819
818
LOG .info ("Completing previous finalize for storage directory {}" ,
820
819
rootPath );
821
- deleteDir (getFinalizedTmp ());
820
+ deleteAsync (getFinalizedTmp ());
822
821
return ;
823
822
case COMPLETE_CHECKPOINT : // mv lastcheckpoint.tmp -> previous.checkpoint
824
823
LOG .info ("Completing previous checkpoint for storage directory {}" ,
825
824
rootPath );
826
825
File prevCkptDir = getPreviousCheckpoint ();
827
- if (prevCkptDir .exists ())
828
- deleteDir (prevCkptDir );
826
+ deleteAsync (prevCkptDir );
829
827
rename (getLastCheckpointTmp (), prevCkptDir );
830
828
return ;
831
829
case RECOVER_CHECKPOINT : // mv lastcheckpoint.tmp -> current
832
830
LOG .info ("Recovering storage directory {} from failed checkpoint" ,
833
831
rootPath );
834
- if (curDir .exists ())
835
- deleteDir (curDir );
832
+ deleteAsync (curDir );
836
833
rename (getLastCheckpointTmp (), curDir );
837
834
return ;
838
835
default :
839
836
throw new IOException ("Unexpected FS state: " + curState
840
837
+ " for storage directory: " + rootPath );
841
838
}
842
839
}
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
+
844
864
/**
845
865
* @return true if the storage directory should prompt the user prior
846
866
* to formatting (i.e if the directory appears to contain some data)
0 commit comments