jad-grepr commented on code in PR #18356:
URL: https://github.com/apache/iceberg/pull/18356#discussion_r4185608039
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableUpdater.java:
##########
@@ -104,23 +105,39 @@ private void findOrCreateBranch(TableIdentifier
identifier, String branch) {
String fromCache = cache.branch(identifier, branch);
if (fromCache == null) {
Table table = catalog.loadTable(identifier);
- try {
- table.manageSnapshots().createBranch(branch).commit();
- LOG.info("Branch {} for {} created", branch, identifier);
- } catch (CommitFailedException e) {
- table.refresh();
- if (table.refs().containsKey(branch)) {
- LOG.debug("Branch {} concurrently created for {}.", branch,
identifier);
- } else {
- LOG.error("Failed to create branch {} for {}.", branch, identifier,
e);
- throw e;
- }
+ // Another writer may have created the branch since the cache loaded the
table.
+ if (hasBranch(table, branch)) {
+ LOG.debug("Branch {} for {} created by another writer.", branch,
identifier);
+ } else {
+ createBranch(identifier, table, branch);
}
cache.update(identifier, table);
}
}
+ private static void createBranch(TableIdentifier identifier, Table table,
String branch) {
+ try {
+ table.manageSnapshots().createBranch(branch).commit();
+ LOG.info("Branch {} for {} created", branch, identifier);
+ } catch (CommitFailedException | IllegalArgumentException e) {
Review Comment:
I already feel dirty catching this extra exception. Making it fully generic
may mask other exceptions where the branch was created but something else
broke. Actually let me see if I can instead change the exception thrown to be
more specific than IAE at the source to do that. Then I can be cleansed.
--
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]