majian1998 commented on code in PR #17013:
URL: https://github.com/apache/iceberg/pull/17013#discussion_r3504264140


##########
core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java:
##########
@@ -313,43 +315,172 @@ private void writeVersionToPath(FileSystem fs, Path 
path, int versionToWrite) th
   int findVersion() {
     Path versionHintFile = versionHintFile();
     FileSystem fs = getFileSystem(versionHintFile, conf);
+    VersionHintRetryState retryState = new VersionHintRetryState();
 
-    try (InputStreamReader fsr =
-            new InputStreamReader(fs.open(versionHintFile), 
StandardCharsets.UTF_8);
-        BufferedReader in = new BufferedReader(fsr)) {
-      return Integer.parseInt(in.readLine().replace("\n", ""));
-
-    } catch (Exception e) {
-      try {
-        if (fs.exists(metadataRoot())) {
-          LOG.warn("Error reading version hint file {}", versionHintFile, e);
-        } else {
-          LOG.debug("Metadata for table not found in directory {}", 
metadataRoot(), e);
-          return 0;
-        }
+    try {
+      return retryReadVersionHint(fs, versionHintFile, retryState);
 
-        // List the metadata directory to find the version files, and try to 
recover the max
-        // available version
-        FileStatus[] files =
-            fs.listStatus(
-                metadataRoot(), name -> 
VERSION_PATTERN.matcher(name.getName()).matches());
-        int maxVersion = 0;
-
-        for (FileStatus file : files) {
-          int currentVersion = version(file.getPath().getName());
-          if (currentVersion > maxVersion && getMetadataFile(currentVersion) 
!= null) {
-            maxVersion = currentVersion;
-          }
-        }
+    } catch (RuntimeException e) {
+      if (e.getCause() instanceof InterruptedException) {
+        throw e;
+      }
 
-        return maxVersion;
-      } catch (IOException io) {
-        LOG.warn("Error trying to recover the latest version number for {}", 
versionHintFile, io);
+      return findVersionFromMetadataDirectory(fs, versionHintFile, e, 
retryState);
+    } catch (IOException e) {
+      return findVersionFromMetadataDirectory(fs, versionHintFile, e, 
retryState);
+    }
+  }
+
+  private int findVersionFromMetadataDirectory(
+      FileSystem fs,
+      Path versionHintFile,
+      Exception versionHintFailure,
+      VersionHintRetryState retryState) {
+    if (retryState.metadataRootCheckFailure != null) {

Review Comment:
   Thanks, already simplified~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to