924060929 commented on code in PR #69501:
URL: https://github.com/apache/doris/pull/69501#discussion_r4357958832


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java:
##########
@@ -743,14 +743,34 @@ protected void invalidateTableCache(String 
localTableName) {
         }
     }
 
+    /** Refreshes table membership and lookup identity without loading remote 
metadata. */
+    public void invalidateTableLookup(String tableName) {
+        if (!isInitialized()) {
+            return;
+        }
+        // In case-insensitive lookup mode an older spelling may still be 
loading while a refreshed
+        // names snapshot already contains the new spelling. Fence every 
object/ID load in this database.
+        if (isTableNamesCaseInsensitive()) {
+            invalidateAllTableCache();
+            return;
+        }
+        String localTableName = resolveTableNameForInvalidation(tableName);
+        try {
+            invalidateTableCache(localTableName);

Review Comment:
   Fixed in a099bd2d6c4: numeric lookups now use the guarded 
getTableAndPublishId path, so a replacement loaded after refresh republishes 
its ID. 584871c5dd3 adds a capture/refresh/resume test that verifies the 
replacement object and ID mapping.



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/RefreshManager.java:
##########
@@ -301,18 +316,41 @@ public void refreshExternalTableFromEvent(String 
catalogName, String localDbName
     }
 
     public void refreshTableInternal(ExternalDatabase db, ExternalTable table, 
long updateTime) {
+        refreshTableInternal(db, table, updateTime, false);
+    }
+
+    private void refreshTableInternal(ExternalDatabase db, ExternalTable 
table, long updateTime,
+            boolean invalidateTableLookup) {
+        boolean invalidateDatabase = invalidateTableLookup && 
table.getCatalog().getLowerCaseTableNames() == 2;
         table.unsetObjectCreated();
         if (updateTime > 0) {
             table.setUpdateTime(updateTime);
         }
         // Connector metadata is the row-count source, so invalidate it before 
engine and row-count caches.
         try {
             if (table.getCatalog() instanceof PluginDrivenExternalCatalog) {
-                ((PluginDrivenExternalCatalog) 
table.getCatalog()).getConnector()
-                        .invalidateTable(db.getRemoteName(), 
table.getRemoteName());
+                if (invalidateDatabase) {
+                    // A refreshed local name may resolve to a different 
remote spelling in this database.
+                    ((PluginDrivenExternalCatalog) 
table.getCatalog()).getConnector()
+                            .invalidateDb(db.getRemoteName());
+                } else {
+                    ((PluginDrivenExternalCatalog) 
table.getCatalog()).getConnector()
+                            .invalidateTable(db.getRemoteName(), 
table.getRemoteName());
+                }
             }
         } finally {
-            Env.getCurrentEnv().getExtMetaCacheMgr().invalidateTable(table);
+            try {
+                if (invalidateTableLookup) {
+                    db.invalidateTableLookup(table.getName());

Review Comment:
   Fixed in a099bd2d6c4: buildTableForInit initializes updateTime when it 
reloads the replacement object, before schema loading. 584871c5dd3 adds a 
replay test that reads the replacement timestamp without calling 
getFullSchema().



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/RefreshManager.java:
##########
@@ -301,18 +316,41 @@ public void refreshExternalTableFromEvent(String 
catalogName, String localDbName
     }
 
     public void refreshTableInternal(ExternalDatabase db, ExternalTable table, 
long updateTime) {
+        refreshTableInternal(db, table, updateTime, false);
+    }
+
+    private void refreshTableInternal(ExternalDatabase db, ExternalTable 
table, long updateTime,
+            boolean invalidateTableLookup) {
+        boolean invalidateDatabase = invalidateTableLookup && 
table.getCatalog().getLowerCaseTableNames() == 2;

Review Comment:
   Fixed in a099bd2d6c4: explicit refresh invalidates the connector database in 
both case-folding modes, clearing historical remote spellings. 584871c5dd3 adds 
a mode-1 test with two retained remote spellings.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/plugin/PluginDrivenExternalTable.java:
##########
@@ -119,8 +119,22 @@ public PluginDrivenExternalTable(long id, String name, 
String remoteName,
      */
     public Optional<ConnectorTableHandle> resolveConnectorTableHandle(
             ConnectorSession session, ConnectorMetadata metadata) {
+        PluginDrivenExternalCatalog owner = (PluginDrivenExternalCatalog) 
catalog;
+        Connector connector = owner.getConnector();
+        ExternalDatabase<?> database = getDb();
+        Optional<Runnable> observation = database.observeTableLookup(this, () 
-> {
+            try {
+                connector.invalidateTable(db.getRemoteName(), getRemoteName());
+            } finally {
+                Env.getCurrentEnv().getExtMetaCacheMgr().invalidateTable(this);
+            }
+        });
         String dbName = db != null ? db.getRemoteName() : "";
-        return metadata.getTableHandle(session, dbName, getRemoteName());
+        Optional<ConnectorTableHandle> handle = 
metadata.getTableHandle(session, dbName, getRemoteName());
+        if (!handle.isPresent()) {
+            observation.ifPresent(Runnable::run);

Review Comment:
   Fixed in 584871c5dd3: an empty table handle now triggers missing-table 
cleanup only when live viewExists is also false. The new test checks repeated 
healthy-view lookups retain name/object/ID/connector caches, then removes the 
view and verifies cleanup still occurs.



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

Reply via email to