-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDFS-16993. Datanode supports configure TopN DatanodeNetworkCounts #5597
Open
hfutatzhanghb
wants to merge
6
commits into
apache:trunk
Choose a base branch
from
hfutatzhanghb:trunk-dnmetrics
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7faf909
HDFS-16993. Datanode supports configure TopN DatanodeNetworkCounts
8588016
fix typo
hfutatzhanghb 2babcc2
add unit tests.
hfutatzhanghb 1001707
modify unit tests failures.
hfutatzhanghb 59b6ca6
add apache license.
hfutatzhanghb 3a9ad91
reset TestDataNodeMetrics
hfutatzhanghb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
110 changes: 110 additions & 0 deletions
110
...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,110 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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); | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...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,109 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we first determine the size of the map? If it is less than N, we can return it directly.