Skip to content

Commit 7970710

Browse files
mehakmeetsteveloughran
authored andcommitted
HADOOP-17229. No update of bytes received counter value after response failure occurs in ABFS (#2264)
Contributed by Mehakmeet Singh Change-Id: Ia9ad1b87a460b10d27486bd00ee67c3cedd2b5b5
1 parent 5710005 commit 7970710

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,12 @@ private boolean executeHttpOperation(final int retryCount) throws AzureBlobFileS
248248

249249
httpOperation.processResponse(buffer, bufferOffset, bufferLength);
250250
incrementCounter(AbfsStatistic.GET_RESPONSES, 1);
251-
incrementCounter(AbfsStatistic.BYTES_RECEIVED,
252-
httpOperation.getBytesReceived());
251+
//Only increment bytesReceived counter when the status code is 2XX.
252+
if (httpOperation.getStatusCode() >= HttpURLConnection.HTTP_OK
253+
&& httpOperation.getStatusCode() <= HttpURLConnection.HTTP_PARTIAL) {
254+
incrementCounter(AbfsStatistic.BYTES_RECEIVED,
255+
httpOperation.getBytesReceived());
256+
}
253257
} catch (IOException ex) {
254258
if (ex instanceof UnknownHostException) {
255259
LOG.warn(String.format("Unknown host name: %s. Retrying to resolve the host name...", httpOperation.getUrl().getHost()));

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsNetworkStatistics.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.hadoop.fs.FSDataInputStream;
2929
import org.apache.hadoop.fs.FSDataOutputStream;
30+
import org.apache.hadoop.fs.FileAlreadyExistsException;
3031
import org.apache.hadoop.io.IOUtils;
3132
import org.apache.hadoop.fs.Path;
3233
import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStream;
@@ -278,4 +279,31 @@ public void testAbfsHttpResponseStatistics() throws IOException {
278279
}
279280
}
280281

282+
/**
283+
* Testing bytes_received counter value when a response failure occurs.
284+
*/
285+
@Test
286+
public void testAbfsHttpResponseFailure() throws IOException {
287+
describe("Test to check the values of bytes received counter when a "
288+
+ "response is failed");
289+
290+
AzureBlobFileSystem fs = getFileSystem();
291+
Path responseFailurePath = path(getMethodName());
292+
Map<String, Long> metricMap;
293+
FSDataOutputStream out = null;
294+
295+
try {
296+
//create an empty file
297+
out = fs.create(responseFailurePath);
298+
//Re-creating the file again on same path with false overwrite, this
299+
// would cause a response failure with status code 409.
300+
out = fs.create(responseFailurePath, false);
301+
} catch (FileAlreadyExistsException faee) {
302+
metricMap = fs.getInstrumentationMap();
303+
// Assert after catching the 409 error to check the counter values.
304+
assertAbfsStatistics(AbfsStatistic.BYTES_RECEIVED, 0, metricMap);
305+
} finally {
306+
IOUtils.cleanupWithLogger(LOG, out);
307+
}
308+
}
281309
}

0 commit comments

Comments
 (0)