HDFS-6054. MiniQJMHACluster should not use static port to avoid binding failure in unit test. (Yongjun Zhang)
(cherry picked from commit 57d0a94305
)
Conflicts:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java
This commit is contained in:
parent
2cbb8bbd72
commit
a5ee4c09de
|
@ -1716,6 +1716,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
HDFS-9623. Update example configuration of block state change log in
|
HDFS-9623. Update example configuration of block state change log in
|
||||||
log4j.properties. (Masatake Iwasaki via aajisaka)
|
log4j.properties. (Masatake Iwasaki via aajisaka)
|
||||||
|
|
||||||
|
HDFS-6054. MiniQJMHACluster should not use static port to avoid binding
|
||||||
|
failure in unit test. (Yongjun Zhang)
|
||||||
|
|
||||||
Release 2.7.3 - UNRELEASED
|
Release 2.7.3 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class MiniQJMHACluster {
|
||||||
private static final String NN1 = "nn1";
|
private static final String NN1 = "nn1";
|
||||||
private static final String NN2 = "nn2";
|
private static final String NN2 = "nn2";
|
||||||
private static final Random RANDOM = new Random();
|
private static final Random RANDOM = new Random();
|
||||||
private int basePort = 10000;
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final Configuration conf;
|
private final Configuration conf;
|
||||||
|
@ -86,9 +85,12 @@ public class MiniQJMHACluster {
|
||||||
private MiniQJMHACluster(Builder builder) throws IOException {
|
private MiniQJMHACluster(Builder builder) throws IOException {
|
||||||
this.conf = builder.conf;
|
this.conf = builder.conf;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
|
int basePort = 10000;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
basePort = 10000 + RANDOM.nextInt(1000) * 4;
|
basePort = 10000 + RANDOM.nextInt(1000) * 4;
|
||||||
|
LOG.info("Set MiniQJMHACluster basePort to " + basePort);
|
||||||
// start 3 journal nodes
|
// start 3 journal nodes
|
||||||
journalCluster = new MiniJournalCluster.Builder(conf).format(true)
|
journalCluster = new MiniJournalCluster.Builder(conf).format(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -98,7 +100,7 @@ public class MiniQJMHACluster {
|
||||||
// start cluster with 2 NameNodes
|
// start cluster with 2 NameNodes
|
||||||
MiniDFSNNTopology topology = createDefaultTopology(basePort);
|
MiniDFSNNTopology topology = createDefaultTopology(basePort);
|
||||||
|
|
||||||
initHAConf(journalURI, builder.conf);
|
initHAConf(journalURI, builder.conf, basePort);
|
||||||
|
|
||||||
// First start up the NNs just to format the namespace. The MinIDFSCluster
|
// First start up the NNs just to format the namespace. The MinIDFSCluster
|
||||||
// has no way to just format the NameNodes without also starting them.
|
// has no way to just format the NameNodes without also starting them.
|
||||||
|
@ -116,16 +118,21 @@ public class MiniQJMHACluster {
|
||||||
|
|
||||||
// restart the cluster
|
// restart the cluster
|
||||||
cluster.restartNameNodes();
|
cluster.restartNameNodes();
|
||||||
++retryCount;
|
|
||||||
break;
|
break;
|
||||||
} catch (BindException e) {
|
} catch (BindException e) {
|
||||||
|
if (cluster != null) {
|
||||||
|
cluster.shutdown(true);
|
||||||
|
cluster = null;
|
||||||
|
}
|
||||||
|
++retryCount;
|
||||||
LOG.info("MiniQJMHACluster port conflicts, retried " +
|
LOG.info("MiniQJMHACluster port conflicts, retried " +
|
||||||
retryCount + " times");
|
retryCount + " times");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Configuration initHAConf(URI journalURI, Configuration conf) {
|
private Configuration initHAConf(URI journalURI, Configuration conf,
|
||||||
|
int basePort) {
|
||||||
conf.set(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY,
|
conf.set(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY,
|
||||||
journalURI.toString());
|
journalURI.toString());
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,14 @@ import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.BindException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
|
@ -62,11 +66,14 @@ import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class TestFailureToReadEdits {
|
public class TestFailureToReadEdits {
|
||||||
|
private static final Log LOG =
|
||||||
|
LogFactory.getLog(TestFailureToReadEdits.class);
|
||||||
|
|
||||||
private static final String TEST_DIR1 = "/test1";
|
private static final String TEST_DIR1 = "/test1";
|
||||||
private static final String TEST_DIR2 = "/test2";
|
private static final String TEST_DIR2 = "/test2";
|
||||||
private static final String TEST_DIR3 = "/test3";
|
private static final String TEST_DIR3 = "/test3";
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
private final TestType clusterType;
|
private final TestType clusterType;
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
private MiniDFSCluster cluster;
|
private MiniDFSCluster cluster;
|
||||||
|
@ -103,14 +110,32 @@ public class TestFailureToReadEdits {
|
||||||
conf.setInt(DFSConfigKeys.DFS_NAMENODE_NUM_CHECKPOINTS_RETAINED_KEY, 10);
|
conf.setInt(DFSConfigKeys.DFS_NAMENODE_NUM_CHECKPOINTS_RETAINED_KEY, 10);
|
||||||
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
|
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
|
||||||
HAUtil.setAllowStandbyReads(conf, true);
|
HAUtil.setAllowStandbyReads(conf, true);
|
||||||
|
|
||||||
if (clusterType == TestType.SHARED_DIR_HA) {
|
if (clusterType == TestType.SHARED_DIR_HA) {
|
||||||
MiniDFSNNTopology topology = MiniQJMHACluster.createDefaultTopology(10000);
|
int basePort = 10000;
|
||||||
cluster = new MiniDFSCluster.Builder(conf)
|
int retryCount = 0;
|
||||||
.nnTopology(topology)
|
while (true) {
|
||||||
.numDataNodes(0)
|
try {
|
||||||
.checkExitOnShutdown(false)
|
basePort = 10000 + RANDOM.nextInt(1000) * 4;
|
||||||
.build();
|
LOG.info("Set SHARED_DIR_HA cluster's basePort to " + basePort);
|
||||||
|
MiniDFSNNTopology topology =
|
||||||
|
MiniQJMHACluster.createDefaultTopology(basePort);
|
||||||
|
cluster = new MiniDFSCluster.Builder(conf)
|
||||||
|
.nnTopology(topology)
|
||||||
|
.numDataNodes(0)
|
||||||
|
.checkExitOnShutdown(false)
|
||||||
|
.build();
|
||||||
|
break;
|
||||||
|
} catch (BindException e) {
|
||||||
|
if (cluster != null) {
|
||||||
|
cluster.shutdown(true);
|
||||||
|
cluster = null;
|
||||||
|
}
|
||||||
|
++retryCount;
|
||||||
|
LOG.info("SHARED_DIR_HA: MiniQJMHACluster port conflicts, retried " +
|
||||||
|
retryCount + " times " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Builder builder = new MiniQJMHACluster.Builder(conf);
|
Builder builder = new MiniQJMHACluster.Builder(conf);
|
||||||
builder.getDfsBuilder().numDataNodes(0).checkExitOnShutdown(false);
|
builder.getDfsBuilder().numDataNodes(0).checkExitOnShutdown(false);
|
||||||
|
|
Loading…
Reference in New Issue