Skip to content

Commit 5b43db4

Browse files
committed
HDFS-8676. Delayed rolling upgrade finalization can cause heartbeat expiration. Contributed by Walter Su.
1 parent 39581e3 commit 5b43db4

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,9 @@ Release 2.7.2 - UNRELEASED
20902090
HDFS-9178. Slow datanode I/O can cause a wrong node to be marked bad
20912091
(kihwal)
20922092

2093+
HDFS-8676. Delayed rolling upgrade finalization can cause heartbeat
2094+
expiration. (Walter Su via kihwal)
2095+
20932096
Release 2.7.1 - 2015-07-06
20942097

20952098
INCOMPATIBLE CHANGES

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.io.File;
3838
import java.io.IOException;
39+
import java.util.ArrayList;
3940
import java.util.Collection;
4041
import java.util.Iterator;
4142
import java.util.List;
@@ -92,6 +93,7 @@ public class BlockPoolSliceStorage extends Storage {
9293
"^(.*)(" + BLOCK_POOL_ID_PATTERN_BASE + ")(" + TRASH_ROOT_DIR + ")(.*)$");
9394

9495
private String blockpoolID = ""; // id of the blockpool
96+
private Daemon trashCleaner;
9597

9698
public BlockPoolSliceStorage(StorageInfo storageInfo, String bpid) {
9799
super(storageInfo);
@@ -738,11 +740,39 @@ String getRestoreDirectory(File blockFile) {
738740
* Delete all files and directories in the trash directories.
739741
*/
740742
public void clearTrash() {
743+
final List<File> trashRoots = new ArrayList<>();
741744
for (StorageDirectory sd : storageDirs) {
742745
File trashRoot = getTrashRootDir(sd);
743-
Preconditions.checkState(!(trashRoot.exists() && sd.getPreviousDir().exists()));
744-
FileUtil.fullyDelete(trashRoot);
745-
LOG.info("Cleared trash for storage directory " + sd);
746+
if (trashRoot.exists() && sd.getPreviousDir().exists()) {
747+
LOG.error("Trash and PreviousDir shouldn't both exist for storage "
748+
+ "directory " + sd);
749+
assert false;
750+
} else {
751+
trashRoots.add(trashRoot);
752+
}
753+
}
754+
755+
stopTrashCleaner();
756+
trashCleaner = new Daemon(new Runnable() {
757+
@Override
758+
public void run() {
759+
for(File trashRoot : trashRoots){
760+
FileUtil.fullyDelete(trashRoot);
761+
LOG.info("Cleared trash for storage directory " + trashRoot);
762+
}
763+
}
764+
765+
@Override
766+
public String toString() {
767+
return "clearTrash() for " + blockpoolID;
768+
}
769+
});
770+
trashCleaner.start();
771+
}
772+
773+
public void stopTrashCleaner() {
774+
if (trashCleaner != null) {
775+
trashCleaner.interrupt();
746776
}
747777
}
748778

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public synchronized boolean createStorageID(
160160
*/
161161
public void enableTrash(String bpid) {
162162
if (trashEnabledBpids.add(bpid)) {
163+
getBPStorage(bpid).stopTrashCleaner();
163164
LOG.info("Enabled trash for bpid " + bpid);
164165
}
165166
}

0 commit comments

Comments
 (0)