You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2023/01/04 08:33:23 UTC

[flink-table-store] 02/02: [FLINK-30389] Add retry to read hints

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

lzljs3620320 pushed a commit to branch release-0.3
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git

commit 9cc9956c5bcdae3980b15b5d12bd4a5e2fcba377
Author: WencongLiu <10...@users.noreply.github.com>
AuthorDate: Wed Jan 4 16:31:51 2023 +0800

    [FLINK-30389] Add retry to read hints
    
    This closes #453
---
 .../flink/table/store/file/utils/SnapshotManager.java    | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/SnapshotManager.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/SnapshotManager.java
index a7004afe..9b0f9ef3 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/SnapshotManager.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/SnapshotManager.java
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.Optional;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 import java.util.function.BinaryOperator;
 
 import static org.apache.flink.table.store.file.utils.FileUtils.listVersionedFiles;
@@ -44,6 +45,8 @@ public class SnapshotManager {
     private static final String SNAPSHOT_PREFIX = "snapshot-";
     public static final String EARLIEST = "EARLIEST";
     public static final String LATEST = "LATEST";
+    private static final int READ_HINT_RETRY_NUM = 3;
+    private static final int READ_HINT_RETRY_INTERVAL = 1;
 
     private final Path tablePath;
 
@@ -214,13 +217,16 @@ public class SnapshotManager {
     public Long readHint(String fileName) {
         Path snapshotDir = snapshotDirectory();
         Path path = new Path(snapshotDir, fileName);
-        try {
-            if (path.getFileSystem().exists(path)) {
+        int retryNumber = 0;
+        while (retryNumber++ < READ_HINT_RETRY_NUM) {
+            try {
                 return Long.parseLong(FileUtils.readFileUtf8(path));
+            } catch (Exception ignored) {
+            }
+            try {
+                TimeUnit.MILLISECONDS.sleep(READ_HINT_RETRY_INTERVAL);
+            } catch (InterruptedException ignored) {
             }
-        } catch (Exception e) {
-            LOG.info(
-                    "Failed to read hint file " + fileName + ". Falling back to listing files.", e);
         }
         return null;
     }