From e4f5c7933dbceab9082f8f1730344fca2e6663ca Mon Sep 17 00:00:00 2001 From: Dmitri Bourlatchkov Date: Mon, 15 Sep 2025 18:50:53 -0400 Subject: [PATCH] Avoid exceptions on ETag matches Exceptions have runtime overhead, which is avoidable in this case. --- .../iceberg/IcebergCatalogAdapter.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java index 7ed3e2d298..0560c6497a 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java @@ -30,7 +30,6 @@ import jakarta.enterprise.inject.Any; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; -import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.SecurityContext; @@ -440,24 +439,24 @@ public Response loadTable( securityContext, prefix, catalog -> { - LoadTableResponse response; + Optional response; if (delegationModes.isEmpty()) { - response = - catalog - .loadTableIfStale(tableIdentifier, ifNoneMatch, snapshots) - .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_MODIFIED)); + response = catalog.loadTableIfStale(tableIdentifier, ifNoneMatch, snapshots); } else { Optional refreshCredentialsEndpoint = getRefreshCredentialsEndpoint(delegationModes, prefix, tableIdentifier); response = - catalog - .loadTableWithAccessDelegationIfStale( - tableIdentifier, ifNoneMatch, snapshots, refreshCredentialsEndpoint) - .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_MODIFIED)); + catalog.loadTableWithAccessDelegationIfStale( + tableIdentifier, ifNoneMatch, snapshots, refreshCredentialsEndpoint); + } + + if (response.isEmpty()) { + return Response.notModified().build(); } - return tryInsertETagHeader(Response.ok(response), response, namespace, table).build(); + return tryInsertETagHeader(Response.ok(response.get()), response.get(), namespace, table) + .build(); }); }