This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 02204e7ac7 [minor] Fix RESTCatalog.close should close client and
refreshExecutor
02204e7ac7 is described below
commit 02204e7ac746fb1b6a97d74e3c490eec14e5305e
Author: Jingsong <[email protected]>
AuthorDate: Tue Dec 10 10:32:53 2024 +0800
[minor] Fix RESTCatalog.close should close client and refreshExecutor
---
.../org/apache/paimon/utils/ThreadPoolUtils.java | 5 +----
.../java/org/apache/paimon/rest/RESTCatalog.java | 26 ++++++++++++++--------
.../org/apache/paimon/rest/RESTCatalogOptions.java | 7 ++++++
.../java/org/apache/paimon/rest/ResourcePaths.java | 1 +
.../org/apache/paimon/rest/RESTCatalogTest.java | 3 ++-
5 files changed, 28 insertions(+), 14 deletions(-)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/utils/ThreadPoolUtils.java
b/paimon-common/src/main/java/org/apache/paimon/utils/ThreadPoolUtils.java
index c64b9e26ea..e4b3da8ca8 100644
--- a/paimon-common/src/main/java/org/apache/paimon/utils/ThreadPoolUtils.java
+++ b/paimon-common/src/main/java/org/apache/paimon/utils/ThreadPoolUtils.java
@@ -20,7 +20,6 @@ package org.apache.paimon.utils;
import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;
-import
org.apache.paimon.shade.guava30.com.google.common.util.concurrent.ThreadFactoryBuilder;
import javax.annotation.Nullable;
@@ -81,9 +80,7 @@ public class ThreadPoolUtils {
public static ScheduledExecutorService createScheduledThreadPool(
int threadNum, String namePrefix) {
- return new ScheduledThreadPoolExecutor(
- threadNum,
- new
ThreadFactoryBuilder().setDaemon(true).setNameFormat(namePrefix).build());
+ return new ScheduledThreadPoolExecutor(threadNum,
newDaemonThreadFactory(namePrefix));
}
/** This method aims to parallel process tasks with memory control and
sequentially. */
diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
index e18946b337..f3007bf4bf 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
@@ -47,15 +47,16 @@ import static
org.apache.paimon.utils.ThreadPoolUtils.createScheduledThreadPool;
/** A catalog implementation for REST. */
public class RESTCatalog implements Catalog {
- private RESTClient client;
- private ResourcePaths resourcePaths;
- private Map<String, String> options;
- private Map<String, String> baseHeader;
- // a lazy thread pool for token refresh
+
+ private static final ObjectMapper OBJECT_MAPPER =
RESTObjectMapper.create();
+
+ private final RESTClient client;
+ private final ResourcePaths resourcePaths;
+ private final Map<String, String> options;
+ private final Map<String, String> baseHeader;
private final AuthSession catalogAuth;
- private volatile ScheduledExecutorService refreshExecutor = null;
- private static final ObjectMapper objectMapper = RESTObjectMapper.create();
+ private volatile ScheduledExecutorService refreshExecutor = null;
public RESTCatalog(Options options) {
if (options.getOptional(CatalogOptions.WAREHOUSE).isPresent()) {
@@ -71,7 +72,7 @@ public class RESTCatalog implements Catalog {
uri,
connectTimeout,
readTimeout,
- objectMapper,
+ OBJECT_MAPPER,
threadPoolSize,
DefaultErrorHandler.getInstance());
this.client = new HttpClient(httpClientOptions);
@@ -194,7 +195,14 @@ public class RESTCatalog implements Catalog {
}
@Override
- public void close() throws Exception {}
+ public void close() throws Exception {
+ if (refreshExecutor != null) {
+ refreshExecutor.shutdownNow();
+ }
+ if (client != null) {
+ client.close();
+ }
+ }
@VisibleForTesting
Map<String, String> fetchOptionsFromServer(
diff --git
a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalogOptions.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalogOptions.java
index 8f7bea91dc..1af64def4f 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalogOptions.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalogOptions.java
@@ -25,31 +25,37 @@ import java.time.Duration;
/** Options for REST Catalog. */
public class RESTCatalogOptions {
+
public static final ConfigOption<String> URI =
ConfigOptions.key("uri")
.stringType()
.noDefaultValue()
.withDescription("REST Catalog server's uri.");
+
public static final ConfigOption<Duration> CONNECTION_TIMEOUT =
ConfigOptions.key("rest.client.connection-timeout")
.durationType()
.noDefaultValue()
.withDescription("REST Catalog http client connect
timeout.");
+
public static final ConfigOption<Duration> READ_TIMEOUT =
ConfigOptions.key("rest.client.read-timeout")
.durationType()
.noDefaultValue()
.withDescription("REST Catalog http client read timeout.");
+
public static final ConfigOption<Integer> THREAD_POOL_SIZE =
ConfigOptions.key("rest.client.num-threads")
.intType()
.defaultValue(1)
.withDescription("REST Catalog http client thread num.");
+
public static final ConfigOption<String> TOKEN =
ConfigOptions.key("token")
.stringType()
.noDefaultValue()
.withDescription("REST Catalog auth token.");
+
public static final ConfigOption<Duration> TOKEN_EXPIRATION_TIME =
ConfigOptions.key("token.expiration-time")
.durationType()
@@ -59,6 +65,7 @@ public class RESTCatalogOptions {
+ " the token expires time is t2, we need
to guarantee that t2 > t1,"
+ " the token validity time is [t2 - t1,
t2],"
+ " and the expires time defined here
needs to be less than (t2 - t1)");
+
public static final ConfigOption<String> TOKEN_PROVIDER_PATH =
ConfigOptions.key("token.provider.path")
.stringType()
diff --git
a/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
b/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
index 1fad87588a..aaca619380 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/ResourcePaths.java
@@ -20,6 +20,7 @@ package org.apache.paimon.rest;
/** Resource paths for REST catalog. */
public class ResourcePaths {
+
public static final String V1_CONFIG = "/api/v1/config";
public static ResourcePaths forCatalogProperties(String prefix) {
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
index 3ed8730862..f3f56e9721 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
@@ -36,9 +36,9 @@ import static org.junit.Assert.assertThrows;
/** Test for REST Catalog. */
public class RESTCatalogTest {
+
private MockWebServer mockWebServer;
private RESTCatalog restCatalog;
- private final String initToken = "init_token";
@Before
public void setUp() throws IOException {
@@ -47,6 +47,7 @@ public class RESTCatalogTest {
String baseUrl = mockWebServer.url("").toString();
Options options = new Options();
options.set(RESTCatalogOptions.URI, baseUrl);
+ String initToken = "init_token";
options.set(RESTCatalogOptions.TOKEN, initToken);
options.set(RESTCatalogOptions.THREAD_POOL_SIZE, 1);
mockOptions(RESTCatalogInternalOptions.PREFIX.key(), "prefix");