-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9008daf
commit ee10d45
Showing
3 changed files
with
183 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeNetworkErrorsWithDefaultConf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.apache.hadoop.hdfs.server.datanode; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hdfs.HdfsConfiguration; | ||
import org.apache.hadoop.hdfs.MiniDFSCluster; | ||
import org.apache.hadoop.io.IOUtils; | ||
import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||
import org.apache.hadoop.test.GenericTestUtils; | ||
import org.apache.hadoop.util.Lists; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; | ||
import static org.apache.hadoop.test.MetricsAsserts.getMetrics; | ||
|
||
public class TestDataNodeNetworkErrorsWithDefaultConf { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(TestDataNodeNetworkErrorsWithDefaultConf.class); | ||
|
||
@Test(timeout = 60000) | ||
public void testDatanodeNetworkErrorsMetricDefaultConf() throws Exception { | ||
final Configuration conf = new HdfsConfiguration(); | ||
final MiniDFSCluster cluster = | ||
new MiniDFSCluster.Builder(conf).numDataNodes(6).build(); | ||
cluster.waitActive(); | ||
final List<FSDataOutputStream> streams = Lists.newArrayList(); | ||
DataNodeFaultInjector oldInjector = DataNodeFaultInjector.get(); | ||
DataNodeFaultInjector newInjector = new DataNodeFaultInjector() { | ||
public void incrementDatanodeNetworkErrors(DataXceiver dataXceiver) { | ||
dataXceiver.incrDatanodeNetworkErrorsWithPort(); | ||
} | ||
}; | ||
DataNodeFaultInjector.set(newInjector); | ||
try { | ||
GenericTestUtils.waitFor(new Supplier<Boolean>() { | ||
@Override | ||
public Boolean get() { | ||
try { | ||
for (int i = 0; i < 100; i++) { | ||
final Path path = new Path("/test" + i); | ||
final FSDataOutputStream out = | ||
cluster.getFileSystem().create(path, (short) 3); | ||
streams.add(out); | ||
out.writeBytes("old gs data\n"); | ||
out.hflush(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
final MetricsRecordBuilder dnMetrics = | ||
getMetrics(cluster.getDataNodes().get(0).getMetrics().name()); | ||
long datanodeNetworkErrors = getLongCounter("DatanodeNetworkErrors", dnMetrics); | ||
return datanodeNetworkErrors > 10; | ||
} | ||
}, 1000, 60000); | ||
|
||
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
final ObjectName mxbeanName = | ||
new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo"); | ||
final Object dnc = | ||
mbs.getAttribute(mxbeanName, "DatanodeNetworkCounts"); | ||
// Compute number of DatanodeNetworkCounts. | ||
final String allDnc = dnc.toString(); | ||
int oldStringLength = allDnc.length(); | ||
String keyword = "key=networkErrors, value"; | ||
int newStringLength = allDnc.replace(keyword, "").length(); | ||
int networkErrorsCount = (oldStringLength - newStringLength) / keyword.length(); | ||
final MetricsRecordBuilder dnMetrics = | ||
getMetrics(cluster.getDataNodes().get(0).getMetrics().name()); | ||
long datanodeNetworkErrors = getLongCounter("DatanodeNetworkErrors", dnMetrics); | ||
Assert.assertEquals(datanodeNetworkErrors, networkErrorsCount); | ||
} finally { | ||
IOUtils.cleanupWithLogger(LOG, streams.toArray(new Closeable[0])); | ||
if (cluster != null) { | ||
cluster.shutdown(); | ||
} | ||
DataNodeFaultInjector.set(oldInjector); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...st/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeNetworkErrorsWithTopNConf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.apache.hadoop.hdfs.server.datanode; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hdfs.DFSConfigKeys; | ||
import org.apache.hadoop.hdfs.HdfsConfiguration; | ||
import org.apache.hadoop.hdfs.MiniDFSCluster; | ||
import org.apache.hadoop.io.IOUtils; | ||
import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||
import org.apache.hadoop.test.GenericTestUtils; | ||
import org.apache.hadoop.util.Lists; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; | ||
import static org.apache.hadoop.test.MetricsAsserts.getMetrics; | ||
|
||
public class TestDataNodeNetworkErrorsWithTopNConf { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(TestDataNodeNetworkErrorsWithTopNConf.class); | ||
|
||
@Test(timeout=60000) | ||
public void testDatanodeNetworkErrorsMetricTopN() throws Exception { | ||
final Configuration conf = new HdfsConfiguration(); | ||
conf.setInt(DFSConfigKeys.DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT, 2); | ||
final MiniDFSCluster cluster = | ||
new MiniDFSCluster.Builder(conf).numDataNodes(6).build(); | ||
cluster.waitActive(); | ||
final List<FSDataOutputStream> streams = Lists.newArrayList(); | ||
DataNodeFaultInjector oldInjector = DataNodeFaultInjector.get(); | ||
DataNodeFaultInjector newInjector = new DataNodeFaultInjector() { | ||
public void incrementDatanodeNetworkErrors(DataXceiver dataXceiver) { | ||
dataXceiver.incrDatanodeNetworkErrorsWithPort(); | ||
} | ||
}; | ||
DataNodeFaultInjector.set(newInjector); | ||
try { | ||
GenericTestUtils.waitFor(new Supplier<Boolean>() { | ||
@Override | ||
public Boolean get() { | ||
try { | ||
for (int i = 0; i < 100; i++) { | ||
final Path path = new Path("/test" + i); | ||
final FSDataOutputStream out = | ||
cluster.getFileSystem().create(path, (short) 3); | ||
streams.add(out); | ||
out.writeBytes("old gs data\n"); | ||
out.hflush(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
final MetricsRecordBuilder dnMetrics = | ||
getMetrics(cluster.getDataNodes().get(0).getMetrics().name()); | ||
long datanodeNetworkErrors = getLongCounter("DatanodeNetworkErrors", dnMetrics); | ||
return datanodeNetworkErrors > 10; | ||
} | ||
}, 1000, 60000); | ||
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
final ObjectName mxbeanName = | ||
new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo"); | ||
final Object dnc = | ||
mbs.getAttribute(mxbeanName, "DatanodeNetworkCounts"); | ||
// Compute number of DatanodeNetworkCounts. | ||
final String allDnc = dnc.toString(); | ||
int oldStringLength = allDnc.length(); | ||
String keyword = "key=networkErrors, value"; | ||
int newStringLength = allDnc.replace(keyword, "").length(); | ||
int networkErrorsCount = (oldStringLength - newStringLength) / keyword.length(); | ||
Assert.assertEquals(2, networkErrorsCount); | ||
} finally { | ||
IOUtils.cleanupWithLogger(LOG, streams.toArray(new Closeable[0])); | ||
if (cluster != null) { | ||
cluster.shutdown(); | ||
} | ||
DataNodeFaultInjector.set(oldInjector); | ||
} | ||
} | ||
} |