mxm commented on code in PR #18356:
URL: https://github.com/apache/iceberg/pull/18356#discussion_r4185506514
##########
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 wonder whether we should catch `Exception` here to avoid the
special-casing. We already have a check below to rethrow if the cause was not
already-created branch.
--
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]