pvary commented on a change in pull request #1465:
URL: https://github.com/apache/iceberg/pull/1465#discussion_r490438056
##########
File path:
core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
##########
@@ -289,19 +311,28 @@ int readVersionHint() {
return Integer.parseInt(in.readLine().replace("\n", ""));
} catch (Exception e) {
- LOG.warn("Error reading version hint file {}", versionHintFile, e);
try {
- if (getMetadataFile(1) != null) {
- // We just assume corrupted metadata and start to read from the
first version file
- return 1;
+ if (fs.exists(metadataRoot())) {
+ LOG.warn("Error reading version hint file {}", versionHintFile, e);
+ }
+
+ // 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;
+ }
}
+
+ return maxVersion;
} catch (IOException io) {
// We log this error only on debug level since this is just a problem
in recovery path
LOG.debug("Error trying to recover version-hint.txt data for {}",
versionHintFile, e);
+ return 0;
Review comment:
I think it is more clear that the return value is only used when there
is an exception in the recovery path.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]