dbtsai commented on code in PR #17236:
URL: https://github.com/apache/iceberg/pull/17236#discussion_r3599488590
##########
aws/src/main/java/org/apache/iceberg/aws/s3/AnalyticsAcceleratorInputStreamWrapper.java:
##########
@@ -19,31 +19,49 @@
package org.apache.iceberg.aws.s3;
import java.io.IOException;
+import org.apache.iceberg.io.FileIOMetricsContext;
import org.apache.iceberg.io.SeekableInputStream;
+import org.apache.iceberg.metrics.Counter;
+import org.apache.iceberg.metrics.MetricsContext;
+import org.apache.iceberg.metrics.MetricsContext.Unit;
import software.amazon.s3.analyticsaccelerator.S3SeekableInputStream;
/** A wrapper to convert {@link S3SeekableInputStream} to Iceberg {@link
SeekableInputStream} */
class AnalyticsAcceleratorInputStreamWrapper extends SeekableInputStream {
private final S3SeekableInputStream delegate;
+ private final Counter readBytes;
+ private final Counter readOperations;
- AnalyticsAcceleratorInputStreamWrapper(S3SeekableInputStream stream) {
+ AnalyticsAcceleratorInputStreamWrapper(S3SeekableInputStream stream,
MetricsContext metrics) {
this.delegate = stream;
+ this.readBytes = metrics.counter(FileIOMetricsContext.READ_BYTES,
Unit.BYTES);
+ this.readOperations =
metrics.counter(FileIOMetricsContext.READ_OPERATIONS);
}
@Override
public int read() throws IOException {
- return this.delegate.read();
+ int bytesRead = this.delegate.read();
+ if (bytesRead != -1) {
+ readBytes.increment();
+ readOperations.increment();
+ }
+ return bytesRead;
}
@Override
public int read(byte[] b) throws IOException {
- return this.delegate.read(b, 0, b.length);
+ return read(b, 0, b.length);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
- return this.delegate.read(b, off, len);
+ int bytesRead = this.delegate.read(b, off, len);
+ if (bytesRead > 0) {
+ readBytes.increment(bytesRead);
+ }
+ readOperations.increment();
Review Comment:
Good catch. Fixed. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]