Skip to content

Commit d994df0

Browse files
committed
Merge branch 'trunk' into HADOOP-17576
2 parents 1122d78 + da4ceba commit d994df0

File tree

218 files changed

+5196
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+5196
-984
lines changed

hadoop-cloud-storage-project/hadoop-huaweicloud/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<dependency>
117117
<groupId>junit</groupId>
118118
<artifactId>junit</artifactId>
119-
<version>4.12</version>
119+
<version>${junit.version}</version>
120120
<scope>test</scope>
121121
</dependency>
122122
<dependency>

hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ function hadoop_daemon_handler
22062206
hadoop_verify_logdir
22072207
hadoop_status_daemon "${daemon_pidfile}"
22082208
if [[ $? == 0 ]]; then
2209-
hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first."
2209+
hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first and ensure ${daemon_pidfile} file is empty before retry."
22102210
exit 1
22112211
else
22122212
# stale pid file, so just remove it and continue on
@@ -2267,7 +2267,7 @@ function hadoop_secure_daemon_handler
22672267
hadoop_verify_logdir
22682268
hadoop_status_daemon "${daemon_pidfile}"
22692269
if [[ $? == 0 ]]; then
2270-
hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first."
2270+
hadoop_error "${daemonname} is running as process $(cat "${daemon_pidfile}"). Stop it first and ensure ${daemon_pidfile} file is empty before retry."
22712271
exit 1
22722272
else
22732273
# stale pid file, so just remove it and continue on

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ public int hashCode() {
13531353

13541354
@Override //Object
13551355
public boolean equals(Object other) {
1356-
if (other == null || !(other instanceof AbstractFileSystem)) {
1356+
if (!(other instanceof AbstractFileSystem)) {
13571357
return false;
13581358
}
13591359
return myUri.equals(((AbstractFileSystem) other).myUri);

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeysPublic.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,15 @@ public class CommonConfigurationKeysPublic {
949949
/** Defalt value for HADOOP_HTTP_LOGS_ENABLED */
950950
public static final boolean HADOOP_HTTP_LOGS_ENABLED_DEFAULT = true;
951951

952+
/**
953+
* @see
954+
* <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml">
955+
* core-default.xml</a>
956+
*/
957+
public static final String HADOOP_HTTP_METRICS_ENABLED =
958+
"hadoop.http.metrics.enabled";
959+
public static final boolean HADOOP_HTTP_METRICS_ENABLED_DEFAULT = true;
960+
952961
/**
953962
* @see
954963
* <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml">

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public int hashCode() {
9797
public boolean equals(final Object that) {
9898
if (this == that) {
9999
return true;
100-
} else if (that == null || !(that instanceof RenewAction)) {
100+
} else if (!(that instanceof RenewAction)) {
101101
return false;
102102
}
103103
return token.equals(((RenewAction<?>)that).token);

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileChecksum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public boolean equals(Object other) {
4747
if (other == this) {
4848
return true;
4949
}
50-
if (other == null || !(other instanceof FileChecksum)) {
50+
if (!(other instanceof FileChecksum)) {
5151
return false;
5252
}
5353

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.servlet.http.HttpServletRequestWrapper;
5151
import javax.servlet.http.HttpServletResponse;
5252

53+
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
5354
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
5455
import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
5556
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
@@ -93,6 +94,7 @@
9394
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
9495
import org.eclipse.jetty.server.handler.HandlerCollection;
9596
import org.eclipse.jetty.server.handler.RequestLogHandler;
97+
import org.eclipse.jetty.server.handler.StatisticsHandler;
9698
import org.eclipse.jetty.server.session.SessionHandler;
9799
import org.eclipse.jetty.servlet.FilterHolder;
98100
import org.eclipse.jetty.servlet.FilterMapping;
@@ -201,6 +203,9 @@ public final class HttpServer2 implements FilterContainer {
201203
protected static final String PROMETHEUS_SINK = "PROMETHEUS_SINK";
202204
private PrometheusMetricsSink prometheusMetricsSink;
203205

206+
private StatisticsHandler statsHandler;
207+
private HttpServer2Metrics metrics;
208+
204209
/**
205210
* Class to construct instances of HTTP server with specific options.
206211
*/
@@ -669,6 +674,27 @@ private void initializeWebServer(String name, String hostName,
669674
addDefaultApps(contexts, appDir, conf);
670675
webServer.setHandler(handlers);
671676

677+
if (conf.getBoolean(
678+
CommonConfigurationKeysPublic.HADOOP_HTTP_METRICS_ENABLED,
679+
CommonConfigurationKeysPublic.HADOOP_HTTP_METRICS_ENABLED_DEFAULT)) {
680+
// Jetty StatisticsHandler must be inserted as the first handler.
681+
// The tree might look like this:
682+
//
683+
// - StatisticsHandler (for all requests)
684+
// - HandlerList
685+
// - ContextHandlerCollection
686+
// - RequestLogHandler (if enabled)
687+
// - WebAppContext
688+
// - SessionHandler
689+
// - Servlets
690+
// - Filters
691+
// - etc..
692+
//
693+
// Reference: https://www.eclipse.org/lists/jetty-users/msg06273.html
694+
statsHandler = new StatisticsHandler();
695+
webServer.insertHandler(statsHandler);
696+
}
697+
672698
Map<String, String> xFrameParams = setHeaders(conf);
673699
addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
674700
final FilterInitializer[] initializers = getFilterInitializers(conf);
@@ -1227,6 +1253,16 @@ public void start() throws IOException {
12271253
.register("prometheus", "Hadoop metrics prometheus exporter",
12281254
prometheusMetricsSink);
12291255
}
1256+
if (statsHandler != null) {
1257+
// Create metrics source for each HttpServer2 instance.
1258+
// Use port number to make the metrics source name unique.
1259+
int port = -1;
1260+
for (ServerConnector connector : listeners) {
1261+
port = connector.getLocalPort();
1262+
break;
1263+
}
1264+
metrics = HttpServer2Metrics.create(statsHandler, port);
1265+
}
12301266
} catch (IOException ex) {
12311267
LOG.info("HttpServer.start() threw a non Bind IOException", ex);
12321268
throw ex;
@@ -1409,6 +1445,9 @@ public void stop() throws Exception {
14091445

14101446
try {
14111447
webServer.stop();
1448+
if (metrics != null) {
1449+
metrics.remove();
1450+
}
14121451
} catch (Exception e) {
14131452
LOG.error("Error while stopping web server for webapp "
14141453
+ webAppContext.getDisplayName(), e);
@@ -1789,4 +1828,10 @@ private Map<String, String> getDefaultHeaders() {
17891828
splitVal[1]);
17901829
return headers;
17911830
}
1831+
1832+
@VisibleForTesting
1833+
HttpServer2Metrics getMetrics() {
1834+
return metrics;
1835+
}
1836+
17921837
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.http;
19+
20+
import org.eclipse.jetty.server.handler.StatisticsHandler;
21+
22+
import org.apache.hadoop.classification.InterfaceAudience;
23+
import org.apache.hadoop.classification.InterfaceStability;
24+
import org.apache.hadoop.metrics2.MetricsSystem;
25+
import org.apache.hadoop.metrics2.annotation.Metric;
26+
import org.apache.hadoop.metrics2.annotation.Metrics;
27+
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
28+
29+
/**
30+
* This class collects all the metrics of Jetty's StatisticsHandler
31+
* and expose them as Hadoop Metrics.
32+
*/
33+
@InterfaceAudience.Private
34+
@InterfaceStability.Unstable
35+
@Metrics(name="HttpServer2", about="HttpServer2 metrics", context="http")
36+
public class HttpServer2Metrics {
37+
38+
private final StatisticsHandler handler;
39+
private final int port;
40+
41+
@Metric("number of requested that have been asynchronously dispatched")
42+
public int asyncDispatches() {
43+
return handler.getAsyncDispatches();
44+
}
45+
@Metric("total number of async requests")
46+
public int asyncRequests() {
47+
return handler.getAsyncRequests();
48+
}
49+
@Metric("currently waiting async requests")
50+
public int asyncRequestsWaiting() {
51+
return handler.getAsyncRequestsWaiting();
52+
}
53+
@Metric("maximum number of waiting async requests")
54+
public int asyncRequestsWaitingMax() {
55+
return handler.getAsyncRequestsWaitingMax();
56+
}
57+
@Metric("number of dispatches")
58+
public int dispatched() {
59+
return handler.getDispatched();
60+
}
61+
@Metric("number of dispatches currently active")
62+
public int dispatchedActive() {
63+
return handler.getDispatchedActive();
64+
}
65+
@Metric("maximum number of active dispatches being handled")
66+
public int dispatchedActiveMax() {
67+
return handler.getDispatchedActiveMax();
68+
}
69+
@Metric("maximum time spend in dispatch handling (in ms)")
70+
public long dispatchedTimeMax() {
71+
return handler.getDispatchedTimeMax();
72+
}
73+
@Metric("mean time spent in dispatch handling (in ms)")
74+
public double dispatchedTimeMean() {
75+
return handler.getDispatchedTimeMean();
76+
}
77+
@Metric("standard deviation for dispatch handling (in ms)")
78+
public double dispatchedTimeStdDev() {
79+
return handler.getDispatchedTimeStdDev();
80+
}
81+
@Metric("total time spent in dispatch handling (in ms)")
82+
public long dispatchedTimeTotal() {
83+
return handler.getDispatchedTimeTotal();
84+
}
85+
@Metric("number of async requests requests that have expired")
86+
public int expires() {
87+
return handler.getExpires();
88+
}
89+
@Metric("number of requests")
90+
public int requests() {
91+
return handler.getRequests();
92+
}
93+
@Metric("number of requests currently active")
94+
public int requestsActive() {
95+
return handler.getRequestsActive();
96+
}
97+
@Metric("maximum number of active requests")
98+
public int requestsActiveMax() {
99+
return handler.getRequestsActiveMax();
100+
}
101+
@Metric("maximum time spend handling requests (in ms)")
102+
public long requestTimeMax() {
103+
return handler.getRequestTimeMax();
104+
}
105+
@Metric("mean time spent handling requests (in ms)")
106+
public double requestTimeMean() {
107+
return handler.getRequestTimeMean();
108+
}
109+
@Metric("standard deviation for request handling (in ms)")
110+
public double requestTimeStdDev() {
111+
return handler.getRequestTimeStdDev();
112+
}
113+
@Metric("total time spend in all request handling (in ms)")
114+
public long requestTimeTotal() {
115+
return handler.getRequestTimeTotal();
116+
}
117+
@Metric("number of requests with 1xx response status")
118+
public int responses1xx() {
119+
return handler.getResponses1xx();
120+
}
121+
@Metric("number of requests with 2xx response status")
122+
public int responses2xx() {
123+
return handler.getResponses2xx();
124+
}
125+
@Metric("number of requests with 3xx response status")
126+
public int responses3xx() {
127+
return handler.getResponses3xx();
128+
}
129+
@Metric("number of requests with 4xx response status")
130+
public int responses4xx() {
131+
return handler.getResponses4xx();
132+
}
133+
@Metric("number of requests with 5xx response status")
134+
public int responses5xx() {
135+
return handler.getResponses5xx();
136+
}
137+
@Metric("total number of bytes across all responses")
138+
public long responsesBytesTotal() {
139+
return handler.getResponsesBytesTotal();
140+
}
141+
@Metric("time in milliseconds stats have been collected for")
142+
public long statsOnMs() {
143+
return handler.getStatsOnMs();
144+
}
145+
146+
HttpServer2Metrics(StatisticsHandler handler, int port) {
147+
this.handler = handler;
148+
this.port = port;
149+
}
150+
151+
static HttpServer2Metrics create(StatisticsHandler handler, int port) {
152+
final MetricsSystem ms = DefaultMetricsSystem.instance();
153+
final HttpServer2Metrics metrics = new HttpServer2Metrics(handler, port);
154+
// Remove the old metrics from metrics system to avoid duplicate error
155+
// when HttpServer2 is started twice.
156+
metrics.remove();
157+
// Add port number to the suffix to allow multiple instances in a host.
158+
return ms.register("HttpServer2-" + port, "HttpServer2 metrics", metrics);
159+
}
160+
161+
void remove() {
162+
DefaultMetricsSystem.removeSourceName("HttpServer2-" + port);
163+
}
164+
}

0 commit comments

Comments
 (0)