From 2da5aaab334d0d6a7dee244cac603aa35c9b0134 Mon Sep 17 00:00:00 2001 From: yliu Date: Wed, 19 Aug 2015 21:55:43 +0800 Subject: [PATCH] HDFS-8908. TestAppendSnapshotTruncate may fail with IOException: Failed to replace a bad datanode. (Tsz Wo Nicholas Sze via yliu) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/TestAppendSnapshotTruncate.java | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 038a6461457..f43f795599c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1174,6 +1174,9 @@ Release 2.8.0 - UNRELEASED HDFS-8891. HDFS concat should keep srcs order. (Yong Zhang via jing9) + HDFS-8908. TestAppendSnapshotTruncate may fail with IOException: Failed to + replace a bad datanode. (Tsz Wo Nicholas Sze via yliu) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java index d67ceb0f1f1..9a099870df3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java @@ -27,7 +27,6 @@ import java.io.RandomAccessFile; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.Random; import java.util.concurrent.Callable; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicBoolean; @@ -42,6 +41,7 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.BlockWrite.ReplaceDatanodeOnFailure; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.TestFileTruncate; import org.apache.hadoop.test.GenericTestUtils; @@ -64,10 +64,10 @@ public class TestAppendSnapshotTruncate { } private static final Log LOG = LogFactory.getLog(TestAppendSnapshotTruncate.class); private static final int BLOCK_SIZE = 1024; - private static final int DATANODE_NUM = 3; + private static final int DATANODE_NUM = 4; private static final short REPLICATION = 3; - private static final int FILE_WORKER_NUM = 3; - private static final long TEST_TIME_SECOND = 10; + private static final int FILE_WORKER_NUM = 10; + private static final long TEST_TIME_SECOND = 20; private static final long TEST_TIMEOUT_SECOND = TEST_TIME_SECOND + 60; static final int SHORT_HEARTBEAT = 1; @@ -85,6 +85,7 @@ public class TestAppendSnapshotTruncate { conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, SHORT_HEARTBEAT); conf.setLong( DFSConfigKeys.DFS_NAMENODE_REPLICATION_PENDING_TIMEOUT_SEC_KEY, 1); + conf.setBoolean(ReplaceDatanodeOnFailure.BEST_EFFORT_KEY, true); cluster = new MiniDFSCluster.Builder(conf) .format(true) .numDataNodes(DATANODE_NUM) @@ -476,7 +477,9 @@ public class TestAppendSnapshotTruncate { } void pause() { - Preconditions.checkState(state.compareAndSet(State.RUNNING, State.IDLE)); + checkErrorState(); + Preconditions.checkState(state.compareAndSet(State.RUNNING, State.IDLE), + "%s: state=%s != %s", name, state.get(), State.RUNNING); } void stop() throws InterruptedException {