-
Notifications
You must be signed in to change notification settings - Fork 3k
Hive: Refactor hive-table commit operation to be used for other operations like view #9461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
cc: @pvary |
|
|
||
| } finally { | ||
| cleanupMetadataAndUnlock(commitStatus, newMetadataLocation, lock); | ||
| if (!conf.getBoolean(ConfigProperties.KEEP_HIVE_STATS, false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the obsolete props are being merged together now. Earlier It was being managed by
removedProps
and hiveStatCheck
| } | ||
|
|
||
| @SuppressWarnings("checkstyle:CyclomaticComplexity") | ||
| default void commitWithLocking( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea here is to generalise doCommit from HiveTableOperations. It should be used by view too.
| * @return Commit Status of Success, Failure or Unknown | ||
| */ | ||
| protected CommitStatus checkCommitStatus(String newMetadataLocation, TableMetadata config) { | ||
| int maxAttempts = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needed to move to a common place so that other operations like View can also use it.
|
@szehon-ho With issue #9514 we are discussing what would be the best approach to handle this? We have not concluded on anything yet which is why this PR is still in progress state. |
szehon-ho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a first pass
| maxAttempts); | ||
| } | ||
| return status.get(); | ||
| return MetastoreOperationsUtil.checkCommitStatus( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question here is, does it have to be a Util?
Usually in Iceberg, I notice that we tend to do shared code using abstract classes. For example, a BaseMetastoreOperations that defines the common methods, and then have BaseMetastoreTableOperations and then BaseMetastoreViewOperations. That way, we can make those be 'protected'
| String tableName, | ||
| String newMetadataLocation, | ||
| Map<String, String> properties, | ||
| Function<String, Boolean> commitStatusSupplier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about, passing in a method to just get the current metadata location(s)? ie, Runnable<List> refreshMetadataLocations
Then the common logic can include the comparison with new metadata location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't understand this part very well. Could you please elaborate more?
The validation happens either with current metadata location or with previous files. How only current metadata location is going to help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant something like:
checkCommitStatus(String newMetadataLocation, TableMetadata config, Runnable<List<String>> loadMetadataLocations)
... // existing common code
Tasks.foreach(newMetadataLocation)
.retry(maxAttempts)
.suppressFailureWhenFinished()
.exponentialBackoff(minWaitMs, maxWaitMs, totalRetryMs, 2.0)
.onFailure(
(location, checkException) ->
LOG.error("Cannot check if commit to {} exists.", tableName(), checkException))
.run(
location -> {
List<String> allMetadataLocations = loadMetadataLocations();
boolean commitSuccess = allMetadataLocations.contains(newMetadataLocations);
if (commitSuccess) {
...
status.set(CommitStatus.SUCCESS);
} else {
...
}
});
... // rest of existing common code
That way, we can just have the different implementations like:
HiveTableOperations {
List<String> loadMetadataLocations() {
TableMetadata metadata = refresh();
return ImmutableList.Builder
.add(metadata.metadataFileLocation())
.addAll(metadata.previousFiles())
.build();
}
}
ViewTableOperations {
List<String> loadMetadataLocations() {
ViewMetadata metadata = refresh();
return ImmutableList.Builder
.add(metadata.metadataFileLocation())
.addAll(metadata.previousFiles())
.build();
}
}
and pass this::loadMetadataLocations() into checkCommitStatus() call. Is that clearer? This allows us to more code, if we dont go with the common interface for View and Table hierarchies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean runnable or supplier here for lazy loading ?
67077a8 to
d3e1555
Compare
szehon-ho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi , I am sorry for the late reply.
I left some more comments and explanations of preivous comments.
I am also now thinking, whether it makes sense to have a common interface for TableMetadata and ViewMetadata, as @pvary originally suggested. Something like HasLocations or HasProperties may help us already remove lots of duplicate code here. There is already precdent in Table => HasTableOperations, and many other interfaces in Iceberg code, and should not be very visible to the user.
| /** | ||
| * Attempt to load the table and see if any current or past metadata location matches the one we | ||
| * were attempting to set. This is used as a last resort when we are dealing with exceptions that | ||
| * may indicate the commit has failed but are not proof that this is the case. Past locations must |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 'are not proof' => 'don't have proof'
How about 'Past locations must ...' => 'Note that all previous locations must ...'
| COMMIT_STATUS_CHECKS_TOTAL_WAIT_MS_DEFAULT); | ||
|
|
||
| AtomicReference<BaseMetastoreTableOperations.CommitStatus> status = | ||
| new AtomicReference<>(BaseMetastoreTableOperations.CommitStatus.UNKNOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move CommitStatus to this class, and make it protected?
That way the BaseMetastoreTableOperations should not need to make it public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can. with the following options:
- Move
CommitStatusfromBaseMetastoreTableOperationstoBaseMetastoreOperationswhich will show changes to many files related to other catalogs. - Keep
CommitStatusfor bothBaseMetastoreTableOperationsandBaseMetastoreOperations
Please suggest .
| CommitStatus commitStatus = CommitStatus.FAILURE; | ||
| boolean updateHiveTable = false; | ||
|
|
||
| HiveLock lock = lockObject(metadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to put
try {
HiveLock lock = lockObject();
...
finally {
lock.unlock()
}
in the common method as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HiveLock is not exposed as public.
I though to keep lock and unlock operations with doCommit.
| String tableName, | ||
| String newMetadataLocation, | ||
| Map<String, String> properties, | ||
| Function<String, Boolean> commitStatusSupplier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant something like:
checkCommitStatus(String newMetadataLocation, TableMetadata config, Runnable<List<String>> loadMetadataLocations)
... // existing common code
Tasks.foreach(newMetadataLocation)
.retry(maxAttempts)
.suppressFailureWhenFinished()
.exponentialBackoff(minWaitMs, maxWaitMs, totalRetryMs, 2.0)
.onFailure(
(location, checkException) ->
LOG.error("Cannot check if commit to {} exists.", tableName(), checkException))
.run(
location -> {
List<String> allMetadataLocations = loadMetadataLocations();
boolean commitSuccess = allMetadataLocations.contains(newMetadataLocations);
if (commitSuccess) {
...
status.set(CommitStatus.SUCCESS);
} else {
...
}
});
... // rest of existing common code
That way, we can just have the different implementations like:
HiveTableOperations {
List<String> loadMetadataLocations() {
TableMetadata metadata = refresh();
return ImmutableList.Builder
.add(metadata.metadataFileLocation())
.addAll(metadata.previousFiles())
.build();
}
}
ViewTableOperations {
List<String> loadMetadataLocations() {
ViewMetadata metadata = refresh();
return ImmutableList.Builder
.add(metadata.metadataFileLocation())
.addAll(metadata.previousFiles())
.build();
}
}
and pass this::loadMetadataLocations() into checkCommitStatus() call. Is that clearer? This allows us to more code, if we dont go with the common interface for View and Table hierarchies.
We already have a thread for the same #9514. |
631d867 to
6788222
Compare
6788222 to
2fa945c
Compare
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
|
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Ref: #8907 (comment)