eric-maynard commented on code in PR #1037:
URL: https://github.com/apache/polaris/pull/1037#discussion_r1972670130


##########
service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java:
##########
@@ -804,15 +834,57 @@ public boolean sendNotification(TableIdentifier 
identifier, NotificationRequest
         && notificationCatalog.sendNotification(identifier, request);
   }
 
+  /**
+   * Fetch the metastore table entity for the given table identifier
+   * @param tableIdentifier The identifier of the table
+   * @return the Polaris table entity for the table
+   */
+  private TableLikeEntity getTableEntity(TableIdentifier tableIdentifier) {
+    PolarisResolvedPathWrapper target = 
resolutionManifest.getPassthroughResolvedPath(tableIdentifier);
+
+    return TableLikeEntity.of(target.getRawLeafEntity());
+  }
+
   public LoadTableResponse loadTable(TableIdentifier tableIdentifier, String 
snapshots) {
-    PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LOAD_TABLE;
-    authorizeBasicTableLikeOperationOrThrow(op, PolarisEntitySubType.TABLE, 
tableIdentifier);
+    return loadTableIfStale(tableIdentifier, null, 
snapshots).get().getResponse();
+  }
+
+  /**
+   * Attempt to perform a loadTable operation only when the specified etag 
does not match the current state of the table.
+   * @param tableIdentifier The identifier of the table to load
+   * @param etag The ETag which identifies the metadata currently known
+   * @param snapshots
+   * @return {@link Optional#empty()} if the ETag is current, an {@link 
Optional} containing the load table response, otherwise
+   */
+  public Optional<ETaggedResponse<LoadTableResponse>> 
loadTableIfStale(TableIdentifier tableIdentifier, String etag, String 
snapshots) {
+      PolarisAuthorizableOperation op = 
PolarisAuthorizableOperation.LOAD_TABLE;
+      authorizeBasicTableLikeOperationOrThrow(op, PolarisEntitySubType.TABLE, 
tableIdentifier);
+
+      TableLikeEntity tableEntity = getTableEntity(tableIdentifier);
+
+      if (tableEntity.isCurrent(etag)) {

Review Comment:
   Do we need to actually load the entire entity? Can't we just check if the 
version is still the one mentioned in the etag?



-- 
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]

Reply via email to