From 5b781a254c5789572f97fdd352236f1b9122ce4f Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 24 Jan 2020 11:53:58 -0800 Subject: [PATCH 1/2] Fix additional release bug --- .../GetBlobOperation.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java b/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java index 4e537670f9..3c372a1bbf 100644 --- a/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java +++ b/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java @@ -386,8 +386,7 @@ public boolean isOpen() { @Override public void close() throws IOException { if (isOpen.compareAndSet(true, false)) { - chunkIndexToResponseInfo.values().forEach(ResponseInfo::release); - chunkIndexToResponseInfo.clear(); + releaseResourse(); if (numChunksWrittenOut.get() != numChunksTotal) { setOperationException(new RouterException( "The ReadableStreamChannel for blob data has been closed by the user before all chunks were written out.", @@ -449,16 +448,24 @@ void completeRead() { } else { routerMetrics.getBlobOperationTotalTimeMs.update(totalTime); } - for (Integer key : chunkIndexToResponseInfo.keySet()) { - ResponseInfo response = chunkIndexToResponseInfo.remove(key); - if (response != null) { - response.release(); - } - } + releaseResourse(); } operationCompleted = true; } + /** + * Release all the {@link ResponseInfo} in the map. Use {@link ConcurrentHashMap#remove(Object)} method to avoid + * conflict with the release call in the chunk async callback. + */ + private void releaseResourse() { + for (Integer key : chunkIndexToResponseInfo.keySet()) { + ResponseInfo response = chunkIndexToResponseInfo.remove(key); + if (response != null) { + response.release(); + } + } + } + /** * Update chunking and size related metrics - blob size, chunk count, and whether the blob is simple or composite. */ From 8a227a02794c53e080bf352c40ad62410bf0235a Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 24 Jan 2020 11:58:08 -0800 Subject: [PATCH 2/2] Typo --- .../main/java/com.github.ambry.router/GetBlobOperation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java b/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java index 3c372a1bbf..ca3e8e57eb 100644 --- a/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java +++ b/ambry-router/src/main/java/com.github.ambry.router/GetBlobOperation.java @@ -386,7 +386,7 @@ public boolean isOpen() { @Override public void close() throws IOException { if (isOpen.compareAndSet(true, false)) { - releaseResourse(); + releaseResource(); if (numChunksWrittenOut.get() != numChunksTotal) { setOperationException(new RouterException( "The ReadableStreamChannel for blob data has been closed by the user before all chunks were written out.", @@ -448,7 +448,7 @@ void completeRead() { } else { routerMetrics.getBlobOperationTotalTimeMs.update(totalTime); } - releaseResourse(); + releaseResource(); } operationCompleted = true; } @@ -457,7 +457,7 @@ void completeRead() { * Release all the {@link ResponseInfo} in the map. Use {@link ConcurrentHashMap#remove(Object)} method to avoid * conflict with the release call in the chunk async callback. */ - private void releaseResourse() { + private void releaseResource() { for (Integer key : chunkIndexToResponseInfo.keySet()) { ResponseInfo response = chunkIndexToResponseInfo.remove(key); if (response != null) {