This is an automated email from the ASF dual-hosted git repository.
stevel pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new f1a14df HADOOP-17774. S3A bytesRead FS statistic showing twice the
correct value (#3144)
f1a14df is described below
commit f1a14df9e6ee1312f15830346b57f14415cc435c
Author: Mehakmeet Singh <[email protected]>
AuthorDate: Fri Jul 2 18:33:16 2021 +0530
HADOOP-17774. S3A bytesRead FS statistic showing twice the correct value
(#3144)
Contributed by: Mehakmeet Singh
Change-Id: I3302654ca36474a5f399aa848f88bce4587022d8
---
.../org/apache/hadoop/fs/s3a/S3AFileSystem.java | 10 +++
.../apache/hadoop/fs/s3a/S3AInstrumentation.java | 2 +-
.../statistics/ITestS3AFileSystemStatistic.java | 75 ++++++++++++++++++++++
3 files changed, 86 insertions(+), 1 deletion(-)
diff --git
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
index 74b19f3..5a53235 100644
---
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
+++
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
@@ -713,6 +713,16 @@ public class S3AFileSystem extends FileSystem implements
StreamCapabilities,
}
/**
+ * Get FS Statistic for this S3AFS instance.
+ *
+ * @return FS statistic instance.
+ */
+ @VisibleForTesting
+ public FileSystem.Statistics getFsStatistics() {
+ return statistics;
+ }
+
+ /**
* Get current listing instance.
* @return this instance's listing.
*/
diff --git
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInstrumentation.java
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInstrumentation.java
index a185bac..cb4e6ac 100644
---
a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInstrumentation.java
+++
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInstrumentation.java
@@ -988,6 +988,7 @@ public class S3AInstrumentation implements Closeable,
MetricsSource,
closed.incrementAndGet();
bytesDiscardedInClose.addAndGet(remainingInCurrentRequest);
totalBytesRead.addAndGet(remainingInCurrentRequest);
+ filesystemStatistics.incrementBytesRead(remainingInCurrentRequest);
}
}
@@ -1144,7 +1145,6 @@ public class S3AInstrumentation implements Closeable,
MetricsSource,
// increment the filesystem statistics for this thread.
if (filesystemStatistics != null) {
long t = getTotalBytesRead();
- filesystemStatistics.incrementBytesRead(t);
filesystemStatistics.incrementBytesReadByDistance(DISTANCE, t);
}
}
diff --git
a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/statistics/ITestS3AFileSystemStatistic.java
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/statistics/ITestS3AFileSystemStatistic.java
new file mode 100644
index 0000000..0d5d2a7
--- /dev/null
+++
b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/statistics/ITestS3AFileSystemStatistic.java
@@ -0,0 +1,75 @@
+/*
+ * 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.fs.s3a.statistics;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.s3a.AbstractS3ATestBase;
+import org.apache.hadoop.fs.s3a.S3AFileSystem;
+import org.apache.hadoop.fs.statistics.IOStatisticAssertions;
+import org.apache.hadoop.fs.statistics.StreamStatisticNames;
+
+public class ITestS3AFileSystemStatistic extends AbstractS3ATestBase {
+
+ private static final int ONE_KB = 1024;
+ private static final int TWO_KB = 2 * ONE_KB;
+
+ /**
+ * Verify the fs statistic bytesRead after reading from 2 different
+ * InputStreams for the same filesystem instance.
+ */
+ @Test
+ public void testBytesReadWithStream() throws IOException {
+ S3AFileSystem fs = getFileSystem();
+ Path filePath = path(getMethodName());
+ byte[] oneKbBuf = new byte[ONE_KB];
+
+ // Writing 1KB in a file.
+ try (FSDataOutputStream out = fs.create(filePath)) {
+ out.write(oneKbBuf);
+ // Verify if correct number of bytes were written.
+ IOStatisticAssertions.assertThatStatisticCounter(out.getIOStatistics(),
+ StreamStatisticNames.STREAM_WRITE_BYTES)
+ .describedAs("Bytes written by OutputStream "
+ + "should match the actual bytes")
+ .isEqualTo(ONE_KB);
+ }
+
+ // Reading 1KB from first InputStream.
+ try (FSDataInputStream in = fs.open(filePath, ONE_KB)) {
+ in.readFully(0, oneKbBuf);
+ }
+
+ // Reading 1KB from second InputStream.
+ try (FSDataInputStream in2 = fs.open(filePath, ONE_KB)) {
+ in2.readFully(0, oneKbBuf);
+ }
+
+ FileSystem.Statistics fsStats = fs.getFsStatistics();
+ // Verifying that total bytes read by FS is equal to 2KB.
+ assertEquals("Mismatch in number of FS bytes read by InputStreams", TWO_KB,
+ fsStats.getBytesRead());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]