-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19645. [ABFS][ReadAheadV2] Improve Metrics for Read Calls to identify type of read done. #7837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HADOOP-19645. [ABFS][ReadAheadV2] Improve Metrics for Read Calls to identify type of read done. #7837
Changes from all commits
ea1572a
42ecdd0
224f712
9a87ad5
0d926b1
9bb6cdb
69ffec4
132893f
6345ec9
9059784
c787d3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * 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.azurebfs.constants; | ||
|
|
||
| /** | ||
| * Enumeration for different types of read operations triggered by AbfsInputStream. | ||
| */ | ||
| public enum ReadType { | ||
| /** | ||
| * Synchronous read from the storage service. No optimization is being applied. | ||
| */ | ||
| DIRECT_READ("DR"), | ||
| /** | ||
| * Synchronous read from the storage service where optimization were considered but found disabled. | ||
| */ | ||
| NORMAL_READ("NR"), | ||
| /** | ||
| * Asynchronous read from the storage service for filling up cache. | ||
| */ | ||
| PREFETCH_READ("PR"), | ||
| /** | ||
| * Synchronous read from the storage service when nothing was found in cache. | ||
| */ | ||
| MISSEDCACHE_READ("MR"), | ||
| /** | ||
| * Synchronous read from the storage service for reading the footer of a file. | ||
| * Only triggered when footer read optimization kicks in. | ||
| */ | ||
| FOOTER_READ("FR"), | ||
| /** | ||
| * Synchronous read from the storage service for reading a small file fully. | ||
| * Only triggered when small file read optimization kicks in. | ||
| */ | ||
| SMALLFILE_READ("SR"), | ||
| /** | ||
| * None of the above read types were applicable. | ||
| */ | ||
| UNKNOWN_READ("UR"); | ||
|
|
||
| private final String readType; | ||
|
|
||
| ReadType(String readType) { | ||
| this.readType = readType; | ||
| } | ||
|
|
||
| /** | ||
| * Get the read type as a string. | ||
| * | ||
| * @return the read type string | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return readType; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.hadoop.classification.VisibleForTesting; | ||
| import org.apache.hadoop.fs.PositionedReadable; | ||
| import org.apache.hadoop.fs.azurebfs.constants.ReadType; | ||
| import org.apache.hadoop.fs.impl.BackReference; | ||
| import org.apache.hadoop.util.Preconditions; | ||
|
|
||
|
|
@@ -165,6 +166,7 @@ public AbfsInputStream( | |
| this.tracingContext = new TracingContext(tracingContext); | ||
| this.tracingContext.setOperation(FSOperationType.READ); | ||
| this.tracingContext.setStreamID(inputStreamId); | ||
| this.tracingContext.setReadType(ReadType.UNKNOWN_READ); | ||
| this.context = abfsInputStreamContext; | ||
| readAheadBlockSize = abfsInputStreamContext.getReadAheadBlockSize(); | ||
| if (abfsReadFooterMetrics != null) { | ||
|
|
@@ -227,7 +229,9 @@ public int read(long position, byte[] buffer, int offset, int length) | |
| if (streamStatistics != null) { | ||
| streamStatistics.readOperationStarted(); | ||
| } | ||
| int bytesRead = readRemote(position, buffer, offset, length, tracingContext); | ||
| TracingContext tc = new TracingContext(tracingContext); | ||
| tc.setReadType(ReadType.DIRECT_READ); | ||
| int bytesRead = readRemote(position, buffer, offset, length, tc); | ||
| if (statistics != null) { | ||
| statistics.incrementBytesRead(bytesRead); | ||
| } | ||
|
|
@@ -345,6 +349,8 @@ private int readOneBlock(final byte[] b, final int off, final int len) throws IO | |
| buffer = new byte[bufferSize]; | ||
| } | ||
|
|
||
| // Reset Read Type back to normal and set again based on code flow. | ||
| tracingContext.setReadType(ReadType.NORMAL_READ); | ||
| if (alwaysReadBufferSize) { | ||
| bytesRead = readInternal(fCursor, buffer, 0, bufferSize, false); | ||
| } else { | ||
|
|
@@ -385,6 +391,7 @@ private int readFileCompletely(final byte[] b, final int off, final int len) | |
| // data need to be copied to user buffer from index bCursor, bCursor has | ||
| // to be the current fCusor | ||
| bCursor = (int) fCursor; | ||
| tracingContext.setReadType(ReadType.SMALLFILE_READ); | ||
| return optimisedRead(b, off, len, 0, contentLength); | ||
| } | ||
|
|
||
|
|
@@ -405,6 +412,7 @@ private int readLastBlock(final byte[] b, final int off, final int len) | |
| bCursor = (int) (fCursor - lastBlockStart); | ||
| // 0 if contentlength is < buffersize | ||
| long actualLenToRead = min(footerReadSize, contentLength); | ||
| tracingContext.setReadType(ReadType.FOOTER_READ); | ||
| return optimisedRead(b, off, len, lastBlockStart, actualLenToRead); | ||
| } | ||
|
|
||
|
|
@@ -520,6 +528,7 @@ private int readInternal(final long position, final byte[] b, final int offset, | |
| LOG.debug("read ahead enabled issuing readheads num = {}", numReadAheads); | ||
| TracingContext readAheadTracingContext = new TracingContext(tracingContext); | ||
| readAheadTracingContext.setPrimaryRequestID(); | ||
| readAheadTracingContext.setReadType(ReadType.PREFETCH_READ); | ||
| while (numReadAheads > 0 && nextOffset < contentLength) { | ||
| LOG.debug("issuing read ahead requestedOffset = {} requested size {}", | ||
| nextOffset, nextSize); | ||
|
|
@@ -544,7 +553,9 @@ private int readInternal(final long position, final byte[] b, final int offset, | |
| } | ||
|
|
||
| // got nothing from read-ahead, do our own read now | ||
| receivedBytes = readRemote(position, b, offset, length, new TracingContext(tracingContext)); | ||
| TracingContext tc = new TracingContext(tracingContext); | ||
| tc.setReadType(ReadType.MISSEDCACHE_READ); | ||
| receivedBytes = readRemote(position, b, offset, length, tc); | ||
| return receivedBytes; | ||
| } else { | ||
| LOG.debug("read ahead disabled, reading remote"); | ||
|
|
@@ -578,6 +589,7 @@ int readRemote(long position, byte[] b, int offset, int length, TracingContext t | |
| streamStatistics.remoteReadOperation(); | ||
| } | ||
| LOG.trace("Trigger client.read for path={} position={} offset={} length={}", path, position, offset, length); | ||
| tracingContext.setPosition(String.valueOf(position)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test to verify position is correctly added to tracing context? Position is a key identifier for read operations.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I updated the current test to assert on position as well. |
||
| op = client.read(path, position, b, offset, length, | ||
| tolerateOobAppends ? "*" : eTag, cachedSasToken.get(), | ||
| contextEncryptionAdapter, tracingContext); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.