You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by dz...@apache.org on 2022/12/25 04:33:08 UTC

[drill] 02/08: DRILL-8329: Close HTTP Caching Resources (#2669)

This is an automated email from the ASF dual-hosted git repository.

dzamo pushed a commit to branch 1.20
in repository https://gitbox.apache.org/repos/asf/drill.git

commit 5851f86579a2f34464b9562cae43abeea5abc5e9
Author: Charles S. Givre <cg...@apache.org>
AuthorDate: Tue Oct 4 20:50:51 2022 +0800

    DRILL-8329: Close HTTP Caching Resources (#2669)
---
 .../org/apache/drill/exec/store/http/HttpBatchReader.java |  3 +++
 .../apache/drill/exec/store/http/HttpCSVBatchReader.java  |  2 ++
 .../apache/drill/exec/store/http/HttpXMLBatchReader.java  |  3 +++
 .../org/apache/drill/exec/store/http/util/SimpleHttp.java | 15 ++++++++++++++-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java
index 697b569f10..a2ce3ad8ae 100644
--- a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java
+++ b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpBatchReader.java
@@ -146,9 +146,12 @@ public class HttpBatchReader implements ManagedReader<SchemaNegotiator> {
       // Paranoia: ensure stream is closed if anything goes wrong.
       // After this, the JSON loader will close the stream.
       AutoCloseables.closeSilently(inStream);
+      AutoCloseables.closeSilently(http);
       throw t;
     }
 
+    // Close the http client
+    http.close();
     return true;
   }
 
diff --git a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpCSVBatchReader.java b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpCSVBatchReader.java
index 2341a876a4..df55433678 100644
--- a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpCSVBatchReader.java
+++ b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpCSVBatchReader.java
@@ -126,6 +126,8 @@ public class HttpCSVBatchReader extends HttpBatchReader {
     rowWriter = resultLoader.writer();
     populateWriterArray();
 
+    // Close cache resources
+    http.close();
     return true;
   }
 
diff --git a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpXMLBatchReader.java b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpXMLBatchReader.java
index c7a2857b74..ca04a534e1 100644
--- a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpXMLBatchReader.java
+++ b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpXMLBatchReader.java
@@ -115,6 +115,9 @@ public class HttpXMLBatchReader extends HttpBatchReader {
         .addContext(errorContext)
         .build(logger);
     }
+
+    // Close cache resources
+    http.close();
     return true;
   }
 
diff --git a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/util/SimpleHttp.java b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/util/SimpleHttp.java
index e5940de184..c1a18d889c 100644
--- a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/util/SimpleHttp.java
+++ b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/util/SimpleHttp.java
@@ -76,7 +76,7 @@ import java.util.regex.Pattern;
  * method is the getInputStream() method which accepts a url and opens an
  * InputStream with that URL's contents.
  */
-public class SimpleHttp {
+public class SimpleHttp implements AutoCloseable {
   private static final Logger logger = LoggerFactory.getLogger(SimpleHttp.class);
 
   private static final Pattern URL_PARAM_REGEX = Pattern.compile("\\{(\\w+)(?:=(\\w*))?\\}");
@@ -568,6 +568,19 @@ public class SimpleHttp {
     return tempUrl;
   }
 
+  @Override
+  public void close() {
+    Cache cache;
+    try {
+      cache = client.cache();
+      if (cache != null) {
+        cache.close();
+      }
+    } catch (IOException e) {
+      logger.warn("Error closing cache. {}", e.getMessage());
+    }
+  }
+
   /**
    * Intercepts requests and adds authentication headers to the request
    */