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 09e660c873 [core] fix refresh token to earlier refresh and log refresh
(#5504)
09e660c873 is described below
commit 09e660c8732aaa683e3bfe861b539aa6a8085cd8
Author: jerry <[email protected]>
AuthorDate: Tue Apr 22 13:14:04 2025 +0800
[core] fix refresh token to earlier refresh and log refresh (#5504)
---
.../main/java/org/apache/paimon/rest/RESTTokenFileIO.java | 12 +++++++++++-
.../test/java/org/apache/paimon/rest/RESTCatalogServer.java | 2 +-
.../test/java/org/apache/paimon/rest/RESTCatalogTest.java | 4 ++--
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/rest/RESTTokenFileIO.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTTokenFileIO.java
index e8ff504fe2..bcf7840dc5 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTTokenFileIO.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTTokenFileIO.java
@@ -37,6 +37,9 @@ import
org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cach
import
org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;
import
org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Scheduler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.concurrent.Executors;
@@ -68,6 +71,8 @@ public class RESTTokenFileIO implements FileIO {
"rest-token-file-io-scheduler"))))
.build();
+ private static final Logger LOG =
LoggerFactory.getLogger(RESTTokenFileIO.class);
+
private final RESTCatalogLoader catalogLoader;
private final Identifier identifier;
private final Path path;
@@ -186,10 +191,11 @@ public class RESTTokenFileIO implements FileIO {
}
private boolean shouldRefresh() {
- return token == null || System.currentTimeMillis() >
token.expireAtMillis();
+ return token == null || token.expireAtMillis() -
System.currentTimeMillis() < 3600_000L;
}
private void refreshToken() {
+ LOG.info("begin refresh token for identifier [{}]", identifier);
GetTableTokenResponse response;
if (catalogInstance != null) {
try {
@@ -204,6 +210,10 @@ public class RESTTokenFileIO implements FileIO {
throw new RuntimeException(e);
}
}
+ LOG.info(
+ "end refresh token for identifier [{}] expiresAtMillis [{}]",
+ identifier,
+ response.getExpiresAtMillis());
token = new RESTToken(response.getToken(),
response.getExpiresAtMillis());
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
index 129448f861..6173e43361 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
@@ -548,7 +548,7 @@ public class RESTCatalogServer {
private MockResponse getDataTokenHandle(Identifier tableIdentifier) throws
Exception {
RESTToken dataToken = getDataToken(tableIdentifier);
if (dataToken == null) {
- long currentTimeMillis = System.currentTimeMillis() + 60_000;
+ long currentTimeMillis = System.currentTimeMillis() + 4000_000L;
dataToken =
new RESTToken(
ImmutableMap.of(
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 920400c53a..08ba3d22f0 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
@@ -807,7 +807,7 @@ public abstract class RESTCatalogTest extends
CatalogTestBase {
RESTToken expiredDataToken =
new RESTToken(
ImmutableMap.of("akId", "akId", "akSecret",
UUID.randomUUID().toString()),
- System.currentTimeMillis());
+ System.currentTimeMillis() + 3600_000L);
setDataTokenToRestServerForMock(identifier, expiredDataToken);
createTable(identifier, Maps.newHashMap(), Lists.newArrayList("col1"));
FileStoreTable fileStoreTable = (FileStoreTable)
catalog.getTable(identifier);
@@ -817,7 +817,7 @@ public abstract class RESTCatalogTest extends
CatalogTestBase {
RESTToken newDataToken =
new RESTToken(
ImmutableMap.of("akId", "akId", "akSecret",
UUID.randomUUID().toString()),
- System.currentTimeMillis() + 100_000);
+ System.currentTimeMillis() + 4000_000L);
setDataTokenToRestServerForMock(identifier, newDataToken);
RESTToken nextFileDataToken = fileIO.validToken();
assertEquals(newDataToken, nextFileDataToken);