mchades commented on code in PR #13891:
URL: https://github.com/apache/gravitino/pull/13891#discussion_r4582644972


##########
clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java:
##########
@@ -773,7 +785,7 @@ private FileSystem getActualFileSystemByLocationName(
           filesetIdent);
 
       Path targetLocation = new 
Path(fileset.storageLocations().get(targetLocationName));
-      Map<String, String> allProperties = getAllProperties(filesetIdent);
+      Map<String, String> allProperties = getAllProperties(filesetIdent, 
fileset);

Review Comment:
   With S3A credential vending enabled and metadata caching off, I counted two 
`loadFileset` calls in one `getActualFileSystemByLocationName` invocation. The 
subsequent `getCredentialProperties` call reloads the same fileset. Could we 
pass the same `fileset` to that helper and keep the `getCredentials()` call on 
it? A resolver-level test could then verify one fileset metadata load and one 
fileset credential fetch.



##########
clients/client-python/gravitino/filesystem/gvfs_base_operations.py:
##########
@@ -664,7 +675,9 @@ def _get_actual_filesystem_by_location_name(
                 f"Cannot find the location: {target_location_name} in fileset: 
{fileset_ident}"
             )
 
-        fileset_props = self._merge_fileset_properties(fileset_ident, 
actual_location)
+        fileset_props = self._merge_fileset_properties(
+            fileset_ident, actual_location, fileset=fileset

Review Comment:
   With metadata caching off, `_get_fileset` has already loaded the catalog 
when we reach this line, and `_merge_fileset_properties` loads it again for the 
schema. I counted two `load_catalog` calls per resolution. Java makes three 
with the default settings because `createFilesetLocationIfNeed` also loads the 
catalog. Could we reuse the catalog for the whole resolution in both clients 
and assert the count from the resolver entry points?



##########
clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestFilesetMetadataCache.java:
##########
@@ -118,4 +123,41 @@ public void testNonFilesetCatalogIsNotCached() throws 
IOException {
     // The failed load is not cached, so the second call loads the catalog 
again.
     verify(client, times(2)).loadCatalog("catalog");
   }
+
+  @Test
+  public void testCacheReusesCatalogSchemaAndFileset() throws IOException {
+    GravitinoClient client = mock(GravitinoClient.class);
+    Catalog catalog = mock(Catalog.class);
+    FilesetCatalog filesetCatalog = mock(FilesetCatalog.class);
+    SupportsSchemas schemas = mock(SupportsSchemas.class);
+    Schema schema = mock(Schema.class);
+    Fileset fileset = mock(Fileset.class);
+
+    when(client.loadCatalog("catalog")).thenReturn(catalog);
+    when(catalog.asFilesetCatalog()).thenReturn(filesetCatalog);
+    when(catalog.asSchemas()).thenReturn(schemas);
+    when(schemas.loadSchema("schema")).thenReturn(schema);
+    when(filesetCatalog.loadFileset(NameIdentifier.of("schema", 
"fs"))).thenReturn(fileset);
+
+    NameIdentifier catalogIdent = NameIdentifier.of("ml", "catalog");
+    NameIdentifier schemaIdent = NameIdentifier.of("ml", "catalog", "schema");
+    NameIdentifier filesetIdent = NameIdentifier.of("ml", "catalog", "schema", 
"fs");
+
+    try (FilesetMetadataCache cache = new FilesetMetadataCache(client)) {
+      assertSame(catalog, cache.getCatalog(catalogIdent));
+      assertSame(filesetCatalog, cache.getFilesetCatalog(catalogIdent));
+      assertSame(schema, cache.getSchema(schemaIdent));
+      assertSame(fileset, cache.getFileset(filesetIdent));
+
+      // Second round should all hit caches.
+      assertSame(catalog, cache.getCatalog(catalogIdent));
+      assertSame(filesetCatalog, cache.getFilesetCatalog(catalogIdent));
+      assertSame(schema, cache.getSchema(schemaIdent));
+      assertSame(fileset, cache.getFileset(filesetIdent));

Review Comment:
   I ran this test against the base revision and it passed there too. The old 
`getFileset` still called `getFilesetCatalog` on a fileset cache hit, and the 
warm catalog cache kept `loadCatalog` at one call. Could we clear the `catalog` 
mock’s invocations immediately before this second `getFileset` and verify that 
`asFilesetCatalog()` is never called? That assertion catches the old behavior.



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