Skip to content

Commit 5e2c4d4

Browse files
authored
Merge pull request #2 from zhangzqs/trunk
Qiniu test use xml file & Sync project
2 parents 6416533 + ad6f2cb commit 5e2c4d4

File tree

121 files changed

+4132
-503
lines changed

Some content is hidden

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

121 files changed

+4132
-503
lines changed

LICENSE-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ commons-collections:commons-collections:3.2.2
253253
commons-daemon:commons-daemon:1.0.13
254254
commons-io:commons-io:2.8.0
255255
commons-logging:commons-logging:1.1.3
256-
commons-net:commons-net:3.8.0
256+
commons-net:commons-net:3.9.0
257257
de.ruedigermoeller:fst:2.50
258258
io.grpc:grpc-api:1.26.0
259259
io.grpc:grpc-context:1.26.0

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/util/PlatformName.java

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.hadoop.util;
2020

21+
import java.security.AccessController;
22+
import java.security.PrivilegedAction;
23+
import java.util.Arrays;
24+
2125
import org.apache.hadoop.classification.InterfaceAudience;
2226
import org.apache.hadoop.classification.InterfaceStability;
2327

@@ -33,21 +37,71 @@ public class PlatformName {
3337
* per the java-vm.
3438
*/
3539
public static final String PLATFORM_NAME =
36-
(System.getProperty("os.name").startsWith("Windows")
37-
? System.getenv("os") : System.getProperty("os.name"))
38-
+ "-" + System.getProperty("os.arch")
39-
+ "-" + System.getProperty("sun.arch.data.model");
40+
(System.getProperty("os.name").startsWith("Windows") ?
41+
System.getenv("os") : System.getProperty("os.name"))
42+
+ "-" + System.getProperty("os.arch") + "-"
43+
+ System.getProperty("sun.arch.data.model");
4044

4145
/**
4246
* The java vendor name used in this platform.
4347
*/
4448
public static final String JAVA_VENDOR_NAME = System.getProperty("java.vendor");
4549

50+
/**
51+
* Define a system class accessor that is open to changes in underlying implementations
52+
* of the system class loader modules.
53+
*/
54+
private static final class SystemClassAccessor extends ClassLoader {
55+
public Class<?> getSystemClass(String className) throws ClassNotFoundException {
56+
return findSystemClass(className);
57+
}
58+
}
59+
4660
/**
4761
* A public static variable to indicate the current java vendor is
48-
* IBM java or not.
62+
* IBM and the type is Java Technology Edition which provides its
63+
* own implementations of many security packages and Cipher suites.
64+
* Note that these are not provided in Semeru runtimes:
65+
* See https://developer.ibm.com/languages/java/semeru-runtimes for details.
4966
*/
50-
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");
67+
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM") &&
68+
hasIbmTechnologyEditionModules();
69+
70+
private static boolean hasIbmTechnologyEditionModules() {
71+
return Arrays.asList(
72+
"com.ibm.security.auth.module.JAASLoginModule",
73+
"com.ibm.security.auth.module.Win64LoginModule",
74+
"com.ibm.security.auth.module.NTLoginModule",
75+
"com.ibm.security.auth.module.AIX64LoginModule",
76+
"com.ibm.security.auth.module.LinuxLoginModule",
77+
"com.ibm.security.auth.module.Krb5LoginModule"
78+
).stream().anyMatch((module) -> isSystemClassAvailable(module));
79+
}
80+
81+
/**
82+
* In rare cases where different behaviour is performed based on the JVM vendor
83+
* this method should be used to test for a unique JVM class provided by the
84+
* vendor rather than using the vendor method. For example if on JVM provides a
85+
* different Kerberos login module testing for that login module being loadable
86+
* before configuring to use it is preferable to using the vendor data.
87+
*
88+
* @param className the name of a class in the JVM to test for
89+
* @return true if the class is available, false otherwise.
90+
*/
91+
private static boolean isSystemClassAvailable(String className) {
92+
return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
93+
try {
94+
// Using ClassLoader.findSystemClass() instead of
95+
// Class.forName(className, false, null) because Class.forName with a null
96+
// ClassLoader only looks at the boot ClassLoader with Java 9 and above
97+
// which doesn't look at all the modules available to the findSystemClass.
98+
new SystemClassAccessor().getSystemClass(className);
99+
return true;
100+
} catch (Exception ignored) {
101+
return false;
102+
}
103+
});
104+
}
51105

52106
public static void main(String[] args) {
53107
System.out.println(PLATFORM_NAME);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ public void setSymlink(final Path p) {
402402
}
403403

404404
/**
405-
* Compare this FileStatus to another FileStatus
405+
* Compare this FileStatus to another FileStatus based on lexicographical
406+
* order of path.
406407
* @param o the FileStatus to be compared.
407408
* @return a negative integer, zero, or a positive integer as this object
408409
* is less than, equal to, or greater than the specified object.
@@ -412,7 +413,8 @@ public int compareTo(FileStatus o) {
412413
}
413414

414415
/**
415-
* Compare this FileStatus to another FileStatus.
416+
* Compare this FileStatus to another FileStatus based on lexicographical
417+
* order of path.
416418
* This method was added back by HADOOP-14683 to keep binary compatibility.
417419
*
418420
* @param o the FileStatus to be compared.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ private AuditConstants() {
9090
*/
9191
public static final String PARAM_PROCESS = "ps";
9292

93+
/**
94+
* Header: Range for GET request data: {@value}.
95+
*/
96+
public static final String PARAM_RANGE = "rg";
97+
9398
/**
9499
* Task Attempt ID query header: {@value}.
95100
*/
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
19+
package org.apache.hadoop.fs.impl;
20+
21+
import java.lang.ref.WeakReference;
22+
23+
import org.apache.hadoop.classification.InterfaceAudience;
24+
import org.apache.hadoop.metrics2.MetricsCollector;
25+
import org.apache.hadoop.metrics2.MetricsSource;
26+
27+
import static java.util.Objects.requireNonNull;
28+
29+
/**
30+
* A weak referenced metrics source which avoids hanging on to large objects
31+
* if somehow they don't get fully closed/cleaned up.
32+
* The JVM may clean up all objects which are only weakly referenced whenever
33+
* it does a GC, <i>even if there is no memory pressure</i>.
34+
* To avoid these refs being removed, always keep a strong reference around
35+
* somewhere.
36+
*/
37+
@InterfaceAudience.Private
38+
public class WeakRefMetricsSource implements MetricsSource {
39+
40+
/**
41+
* Name to know when unregistering.
42+
*/
43+
private final String name;
44+
45+
/**
46+
* Underlying metrics source.
47+
*/
48+
private final WeakReference<MetricsSource> sourceWeakReference;
49+
50+
/**
51+
* Constructor.
52+
* @param name Name to know when unregistering.
53+
* @param source metrics source
54+
*/
55+
public WeakRefMetricsSource(final String name, final MetricsSource source) {
56+
this.name = name;
57+
this.sourceWeakReference = new WeakReference<>(requireNonNull(source));
58+
}
59+
60+
/**
61+
* If the weak reference is non null, update the metrics.
62+
* @param collector to contain the resulting metrics snapshot
63+
* @param all if true, return all metrics even if unchanged.
64+
*/
65+
@Override
66+
public void getMetrics(final MetricsCollector collector, final boolean all) {
67+
MetricsSource metricsSource = sourceWeakReference.get();
68+
if (metricsSource != null) {
69+
metricsSource.getMetrics(collector, all);
70+
}
71+
}
72+
73+
/**
74+
* Name to know when unregistering.
75+
* @return the name passed in during construction.
76+
*/
77+
public String getName() {
78+
return name;
79+
}
80+
81+
/**
82+
* Get the source, will be null if the reference has been GC'd
83+
* @return the source reference
84+
*/
85+
public MetricsSource getSource() {
86+
return sourceWeakReference.get();
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return "WeakRefMetricsSource{" +
92+
"name='" + name + '\'' +
93+
", sourceWeakReference is " +
94+
(sourceWeakReference.get() == null ? "unset" : "set") +
95+
'}';
96+
}
97+
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/statistics/impl/IOStatisticsStoreImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public long incrementCounter(final String key, final long value) {
190190
return counter.get();
191191
} else {
192192
long l = incAtomicLong(counter, value);
193-
LOG.debug("Incrementing counter {} by {} with final value {}",
193+
LOG.trace("Incrementing counter {} by {} with final value {}",
194194
key, value, l);
195195
return l;
196196
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,15 @@ public LogAction record(String recorderName, long currentTimeMs,
262262
if (primaryRecorderName.equals(recorderName) &&
263263
currentTimeMs - minLogPeriodMs >= lastLogTimestampMs) {
264264
lastLogTimestampMs = currentTimeMs;
265-
for (LoggingAction log : currentLogs.values()) {
266-
log.setShouldLog();
267-
}
265+
currentLogs.replaceAll((key, log) -> {
266+
LoggingAction newLog = log;
267+
if (log.hasLogged()) {
268+
// create a fresh log since the old one has already been logged
269+
newLog = new LoggingAction(log.getValueCount());
270+
}
271+
newLog.setShouldLog();
272+
return newLog;
273+
});
268274
}
269275
if (currentLog.shouldLog()) {
270276
currentLog.setHasLogged();
@@ -357,6 +363,10 @@ private void setHasLogged() {
357363
hasLogged = true;
358364
}
359365

366+
private int getValueCount() {
367+
return stats.length;
368+
}
369+
360370
private void recordValues(double... values) {
361371
if (values.length != stats.length) {
362372
throw new IllegalArgumentException("received " + values.length +

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedIdMapping.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
4040

41+
import static org.apache.hadoop.util.Shell.bashQuote;
42+
4143
/**
4244
* A simple shell-based implementation of {@link IdMappingServiceProvider}
4345
* Map id to user name or group name. It does update every 15 minutes. Only a
@@ -472,26 +474,27 @@ synchronized private void updateMapIncr(final String name,
472474

473475
boolean updated = false;
474476
updateStaticMapping();
477+
String name2 = bashQuote(name);
475478

476479
if (OS.startsWith("Linux") || OS.equals("SunOS") || OS.contains("BSD")) {
477480
if (isGrp) {
478481
updated = updateMapInternal(gidNameMap, "group",
479-
getName2IdCmdNIX(name, true), ":",
482+
getName2IdCmdNIX(name2, true), ":",
480483
staticMapping.gidMapping);
481484
} else {
482485
updated = updateMapInternal(uidNameMap, "user",
483-
getName2IdCmdNIX(name, false), ":",
486+
getName2IdCmdNIX(name2, false), ":",
484487
staticMapping.uidMapping);
485488
}
486489
} else {
487490
// Mac
488491
if (isGrp) {
489492
updated = updateMapInternal(gidNameMap, "group",
490-
getName2IdCmdMac(name, true), "\\s+",
493+
getName2IdCmdMac(name2, true), "\\s+",
491494
staticMapping.gidMapping);
492495
} else {
493496
updated = updateMapInternal(uidNameMap, "user",
494-
getName2IdCmdMac(name, false), "\\s+",
497+
getName2IdCmdMac(name2, false), "\\s+",
495498
staticMapping.uidMapping);
496499
}
497500
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ssl/SSLFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.hadoop.util.StringUtils;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
28-
import static org.apache.hadoop.util.PlatformName.JAVA_VENDOR_NAME;
28+
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
2929

3030
import javax.net.ssl.HostnameVerifier;
3131
import javax.net.ssl.HttpsURLConnection;
@@ -102,11 +102,11 @@ public enum Mode { CLIENT, SERVER }
102102
"ssl.server.exclude.cipher.list";
103103

104104
public static final String KEY_MANAGER_SSLCERTIFICATE =
105-
JAVA_VENDOR_NAME.contains("IBM") ? "ibmX509" :
105+
IBM_JAVA ? "ibmX509" :
106106
KeyManagerFactory.getDefaultAlgorithm();
107107

108108
public static final String TRUST_MANAGER_SSLCERTIFICATE =
109-
JAVA_VENDOR_NAME.contains("IBM") ? "ibmX509" :
109+
IBM_JAVA ? "ibmX509" :
110110
TrustManagerFactory.getDefaultAlgorithm();
111111

112112
public static final String KEYSTORES_FACTORY_CLASS_KEY =

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public static void checkWindowsCommandLineLength(String...commands)
146146
* @param arg the argument to quote
147147
* @return the quoted string
148148
*/
149-
static String bashQuote(String arg) {
149+
@InterfaceAudience.Private
150+
public static String bashQuote(String arg) {
150151
StringBuilder buffer = new StringBuilder(arg.length() + 2);
151152
buffer.append('\'')
152153
.append(arg.replace("'", "'\\''"))

0 commit comments

Comments
 (0)