Skip to content

Commit 36a6695

Browse files
committed
merge PR 3863
2 parents 68b4a87 + ab8c360 commit 36a6695

File tree

274 files changed

+30804
-2559
lines changed

Some content is hidden

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

274 files changed

+30804
-2559
lines changed

LICENSE-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ log4j:log4j:1.2.17
283283
net.java.dev.jna:jna:5.2.0
284284
net.minidev:accessors-smart:1.2
285285
net.minidev:json-smart:2.4.7
286-
org.apache.avro:avro:1.7.7
286+
org.apache.avro:avro:1.9.2
287287
org.apache.commons:commons-collections4:4.2
288288
org.apache.commons:commons-compress:1.21
289289
org.apache.commons:commons-configuration2:2.1.1

hadoop-client-modules/hadoop-client-api/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
<!-- Exclude snappy-java -->
162162
<exclude>org/xerial/snappy/*</exclude>
163163
<exclude>org/xerial/snappy/**/*</exclude>
164+
<!-- Exclude org.widlfly.openssl -->
165+
<exclude>org/wildfly/openssl/*</exclude>
166+
<exclude>org/wildfly/openssl/**/*</exclude>
164167
</excludes>
165168
</relocation>
166169
<relocation>

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.hadoop.classification.InterfaceAudience;
2121
import org.apache.hadoop.classification.InterfaceStability;
22+
import org.apache.hadoop.classification.VisibleForTesting;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425

@@ -154,10 +155,20 @@ boolean running() {
154155
/**
155156
* How long in between runs of the background refresh.
156157
*/
157-
long getRefreshInterval() {
158+
@VisibleForTesting
159+
public long getRefreshInterval() {
158160
return refreshInterval;
159161
}
160162

163+
/**
164+
* Randomize the refresh interval timing by this amount, the actual interval will be chosen
165+
* uniformly between {@code interval-jitter} and {@code interval+jitter}.
166+
*/
167+
@VisibleForTesting
168+
public long getJitter() {
169+
return jitter;
170+
}
171+
161172
/**
162173
* Reset the current used data amount. This should be called
163174
* when the cached value is re-computed.

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

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@
3636
import java.nio.charset.CharsetEncoder;
3737
import java.nio.charset.StandardCharsets;
3838
import java.nio.file.AccessDeniedException;
39+
import java.nio.file.attribute.PosixFilePermission;
3940
import java.nio.file.FileSystems;
4041
import java.nio.file.Files;
4142
import java.nio.file.LinkOption;
4243
import java.nio.file.Paths;
4344
import java.util.ArrayList;
4445
import java.util.Enumeration;
46+
import java.util.EnumSet;
4547
import java.util.List;
4648
import java.util.Map;
4749
import java.util.Objects;
50+
import java.util.Set;
4851
import java.util.concurrent.ExecutionException;
4952
import java.util.concurrent.ExecutorService;
5053
import java.util.concurrent.Executors;
@@ -53,13 +56,13 @@
5356
import java.util.jar.JarOutputStream;
5457
import java.util.jar.Manifest;
5558
import java.util.zip.GZIPInputStream;
56-
import java.util.zip.ZipEntry;
57-
import java.util.zip.ZipFile;
58-
import java.util.zip.ZipInputStream;
5959

6060
import org.apache.commons.collections.map.CaseInsensitiveMap;
6161
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
6262
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
63+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
64+
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
65+
import org.apache.commons.compress.archivers.zip.ZipFile;
6366
import org.apache.commons.io.FileUtils;
6467
import org.apache.hadoop.classification.InterfaceAudience;
6568
import org.apache.hadoop.classification.InterfaceStability;
@@ -644,12 +647,12 @@ public static long getDU(File dir) {
644647
*/
645648
public static void unZip(InputStream inputStream, File toDir)
646649
throws IOException {
647-
try (ZipInputStream zip = new ZipInputStream(inputStream)) {
650+
try (ZipArchiveInputStream zip = new ZipArchiveInputStream(inputStream)) {
648651
int numOfFailedLastModifiedSet = 0;
649652
String targetDirPath = toDir.getCanonicalPath() + File.separator;
650-
for(ZipEntry entry = zip.getNextEntry();
653+
for(ZipArchiveEntry entry = zip.getNextZipEntry();
651654
entry != null;
652-
entry = zip.getNextEntry()) {
655+
entry = zip.getNextZipEntry()) {
653656
if (!entry.isDirectory()) {
654657
File file = new File(toDir, entry.getName());
655658
if (!file.getCanonicalPath().startsWith(targetDirPath)) {
@@ -668,6 +671,9 @@ public static void unZip(InputStream inputStream, File toDir)
668671
if (!file.setLastModified(entry.getTime())) {
669672
numOfFailedLastModifiedSet++;
670673
}
674+
if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
675+
Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));
676+
}
671677
}
672678
}
673679
if (numOfFailedLastModifiedSet > 0) {
@@ -677,6 +683,49 @@ public static void unZip(InputStream inputStream, File toDir)
677683
}
678684
}
679685

686+
/**
687+
* The permission operation of this method only involves users, user groups, and others.
688+
* If SUID is set, only executable permissions are reserved.
689+
* @param mode Permissions are represented by numerical values
690+
* @return The original permissions for files are stored in collections
691+
*/
692+
private static Set<PosixFilePermission> permissionsFromMode(int mode) {
693+
EnumSet<PosixFilePermission> permissions =
694+
EnumSet.noneOf(PosixFilePermission.class);
695+
addPermissions(permissions, mode, PosixFilePermission.OTHERS_READ,
696+
PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_EXECUTE);
697+
addPermissions(permissions, mode >> 3, PosixFilePermission.GROUP_READ,
698+
PosixFilePermission.GROUP_WRITE, PosixFilePermission.GROUP_EXECUTE);
699+
addPermissions(permissions, mode >> 6, PosixFilePermission.OWNER_READ,
700+
PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE);
701+
return permissions;
702+
}
703+
704+
/**
705+
* Assign the original permissions to the file
706+
* @param permissions The original permissions for files are stored in collections
707+
* @param mode Use a value of type int to indicate permissions
708+
* @param r Read permission
709+
* @param w Write permission
710+
* @param x Execute permission
711+
*/
712+
private static void addPermissions(
713+
Set<PosixFilePermission> permissions,
714+
int mode,
715+
PosixFilePermission r,
716+
PosixFilePermission w,
717+
PosixFilePermission x) {
718+
if ((mode & 1L) == 1L) {
719+
permissions.add(x);
720+
}
721+
if ((mode & 2L) == 2L) {
722+
permissions.add(w);
723+
}
724+
if ((mode & 4L) == 4L) {
725+
permissions.add(r);
726+
}
727+
}
728+
680729
/**
681730
* Given a File input it will unzip it in the unzip directory.
682731
* passed as the second parameter
@@ -685,14 +734,14 @@ public static void unZip(InputStream inputStream, File toDir)
685734
* @throws IOException An I/O exception has occurred
686735
*/
687736
public static void unZip(File inFile, File unzipDir) throws IOException {
688-
Enumeration<? extends ZipEntry> entries;
737+
Enumeration<? extends ZipArchiveEntry> entries;
689738
ZipFile zipFile = new ZipFile(inFile);
690739

691740
try {
692-
entries = zipFile.entries();
741+
entries = zipFile.getEntries();
693742
String targetDirPath = unzipDir.getCanonicalPath() + File.separator;
694743
while (entries.hasMoreElements()) {
695-
ZipEntry entry = entries.nextElement();
744+
ZipArchiveEntry entry = entries.nextElement();
696745
if (!entry.isDirectory()) {
697746
InputStream in = zipFile.getInputStream(entry);
698747
try {
@@ -717,6 +766,9 @@ public static void unZip(File inFile, File unzipDir) throws IOException {
717766
} finally {
718767
out.close();
719768
}
769+
if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
770+
Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));
771+
}
720772
} finally {
721773
in.close();
722774
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public final class StoreStatisticNames {
112112
/** {@value}. */
113113
public static final String OP_MODIFY_ACL_ENTRIES = "op_modify_acl_entries";
114114

115+
/** {@value}. */
116+
public static final String OP_MSYNC = "op_msync";
117+
115118
/** {@value}. */
116119
public static final String OP_OPEN = "op_open";
117120

@@ -172,6 +175,9 @@ public final class StoreStatisticNames {
172175
public static final String STORE_IO_THROTTLED
173176
= "store_io_throttled";
174177

178+
/** Rate limiting was reported {@value}. */
179+
public static final String STORE_IO_RATE_LIMITED = "store_io_rate_limited";
180+
175181
/** Requests made of a store: {@value}. */
176182
public static final String STORE_IO_REQUEST
177183
= "store_io_request";

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.annotation.Nullable;
2222
import java.io.IOException;
2323
import java.io.Serializable;
24+
import java.time.Duration;
2425
import java.util.Iterator;
2526
import java.util.Map;
2627
import java.util.concurrent.Callable;
@@ -450,12 +451,37 @@ public static <B> B trackDuration(
450451
* @param factory factory of duration trackers
451452
* @param statistic statistic key
452453
* @param input input callable.
454+
* @throws IOException IO failure.
453455
*/
454456
public static void trackDurationOfInvocation(
455457
DurationTrackerFactory factory,
456458
String statistic,
457459
InvocationRaisingIOE input) throws IOException {
458460

461+
measureDurationOfInvocation(factory, statistic, input);
462+
}
463+
464+
/**
465+
* Given an IOException raising callable/lambda expression,
466+
* execute it and update the relevant statistic,
467+
* returning the measured duration.
468+
*
469+
* {@link #trackDurationOfInvocation(DurationTrackerFactory, String, InvocationRaisingIOE)}
470+
* with the duration returned for logging etc.; added as a new
471+
* method to avoid linking problems with any code calling the existing
472+
* method.
473+
*
474+
* @param factory factory of duration trackers
475+
* @param statistic statistic key
476+
* @param input input callable.
477+
* @return the duration of the operation, as measured by the duration tracker.
478+
* @throws IOException IO failure.
479+
*/
480+
public static Duration measureDurationOfInvocation(
481+
DurationTrackerFactory factory,
482+
String statistic,
483+
InvocationRaisingIOE input) throws IOException {
484+
459485
// create the tracker outside try-with-resources so
460486
// that failures can be set in the catcher.
461487
DurationTracker tracker = createTracker(factory, statistic);
@@ -473,6 +499,7 @@ public static void trackDurationOfInvocation(
473499
// set the failed flag.
474500
tracker.close();
475501
}
502+
return tracker.asDuration();
476503
}
477504

478505
/**
@@ -622,7 +649,7 @@ public static <B> B trackDurationOfSupplier(
622649
* @param statistic statistic to track
623650
* @return a duration tracker.
624651
*/
625-
private static DurationTracker createTracker(
652+
public static DurationTracker createTracker(
626653
@Nullable final DurationTrackerFactory factory,
627654
final String statistic) {
628655
return factory != null

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,15 @@ default long incrementCounter(String key) {
255255
*/
256256
void addTimedOperation(String prefix, Duration duration);
257257

258+
/**
259+
* Add a statistics sample as a min, max and mean and count.
260+
* @param key key to add.
261+
* @param count count.
262+
*/
263+
default void addSample(String key, long count) {
264+
incrementCounter(key, count);
265+
addMeanStatisticSample(key, count);
266+
addMaximumSample(key, count);
267+
addMinimumSample(key, count);
268+
}
258269
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public void close() {
8888
public Duration asDuration() {
8989
return firstDuration.asDuration();
9090
}
91+
92+
@Override
93+
public String toString() {
94+
return firstDuration.toString();
95+
}
9196
}
9297

9398
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ public void close() {
103103
}
104104
iostats.addTimedOperation(name, asDuration());
105105
}
106+
107+
@Override
108+
public String toString() {
109+
return " Duration of " +
110+
(failed? (key + StoreStatisticNames.SUFFIX_FAILURES) : key)
111+
+ ": " + super.toString();
112+
}
106113
}

0 commit comments

Comments
 (0)