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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4e35f5548d DRILL-8329: Close HTTP Caching Resources (#2669)
4e35f5548d is described below

commit 4e35f5548da5afacbb03b8afec2f399b68d9f0ba
Author: Charles S. Givre <cgi...@apache.org>
AuthorDate: Tue Oct 4 08:50:51 2022 -0400

    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 6f312b0e9b..cc17636bcc 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
@@ -165,9 +165,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 bb5d217e14..d5dc5b5fe0 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 05380d1e2e..2c8589649e 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
@@ -98,7 +98,7 @@ import java.util.stream.Collectors;
  * 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 int DEFAULT_TIMEOUT = 1;
   private static final Pattern URL_PARAM_REGEX = 
Pattern.compile("\\{(\\w+)(?:=(\\w*))?}");
@@ -971,6 +971,19 @@ public class SimpleHttp {
     return response.body();
   }
 
+  @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
    */

Reply via email to