yuqi1129 commented on code in PR #15134:
URL: https://github.com/apache/gravitino/pull/15134#discussion_r4638237237
##########
core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java:
##########
@@ -328,6 +330,23 @@ public <E extends Entity & HasIdentifier> E get(
});
}
+ @Override
+ public long getEntityId(NameIdentifier ident, Entity.EntityType entityType)
throws IOException {
+ if (entityType != Entity.EntityType.TABLE) {
+ return EntityStore.super.getEntityId(ident, entityType);
+ }
+
+ return cache.withCacheLock(
+ EntityCacheKey.of(ident, entityType),
+ () -> {
+ Optional<TableEntity> cached = cache.getIfPresent(ident, entityType);
+ // Do not publish a partial TableEntity or introduce a separate
name-to-ID cache.
+ return cached.isPresent()
+ ? cached.get().id()
+ : TableMetaService.getInstance().getTableIdByIdentifier(ident);
Review Comment:
On a cache miss, get() reads through this store’s backend, while this lookup
calls the TableMetaService singleton directly. forOfflineMigration(backend,
config) explicitly accepts a backend and disables caching, so every table ID
lookup on that store bypasses the supplied backend. Could the cold read go
through the backend that owns the entity? A test with an injected backend
should verify that get() and the ID lookup return the same ID.
##########
core/src/main/java/org/apache/gravitino/EntityStore.java:
##########
@@ -216,6 +217,22 @@ <E extends Entity & HasIdentifier> E update(
<E extends Entity & HasIdentifier> E get(NameIdentifier ident, EntityType
entityType, Class<E> e)
throws NoSuchEntityException, IOException;
+ /**
+ * Resolve an entity ID without requiring its complete metadata.
+ *
+ * <p>Stores may override this method to avoid loading expensive child
metadata. The default
+ * implementation retains compatibility with stores that only support full
entity reads.
+ *
+ * @param ident the unique identifier of the entity
+ * @param entityType the general type of the entity
+ * @return the entity ID
+ * @throws NoSuchEntityException if the entity does not exist
+ * @throws IOException if the lookup fails
+ */
+ default long getEntityId(NameIdentifier ident, EntityType entityType) throws
IOException {
Review Comment:
There is already an EntityIdResolver.getEntityId(NameIdentifier, EntityType)
returning Long. I compiled a class implementing both interfaces against the
base and this revision. It compiles on the base and fails here because long and
Long are incompatible return types for an override. The default body therefore
still introduces a source compatibility break for that class. If we keep a
shared lookup API, could we reconcile the two contracts and cover this
combination with a compile check?
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java:
##########
@@ -122,6 +122,20 @@ public String getMetalakeNameByTableId(long tableId) {
return metalake == null ? null : metalake.getMetalakeName();
}
+ /**
+ * Resolve a table ID without reading its column snapshot.
+ *
+ * @param identifier the full table identifier
+ * @return the ID of the active table
+ * @throws NoSuchEntityException if the table or its namespace does not exist
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getTableIdByIdentifier")
+ public long getTableIdByIdentifier(NameIdentifier identifier) {
+ return getTablePOByIdentifier(identifier).getTableId();
Review Comment:
This saves the column snapshot read, but getTablePOByIdentifier still
selects the table metadata and joins table_version_info. Could the JDBC path
project just table_id while preserving the existing name resolution and
missing-table behavior? That would reduce the work per table on the
authorization cache miss that motivated the change.
--
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]