apurtell commented on code in PR #2658:
URL: https://github.com/apache/phoenix/pull/2658#discussion_r4507808467


##########
phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexCDCConsumer.java:
##########
@@ -319,8 +326,42 @@ private PTable getDataTable(PhoenixConnection conn) throws 
SQLException {
     return dataTable;
   }
 
+  /**
+   * Reads the data table definition from SYSTEM.CATALOG. The metadata cache 
of the region server
+   * can keep an old definition after an ALTER, for example when the region 
moves to this server.
+   */
   private void refreshDataTableCache(PhoenixConnection conn) throws 
SQLException {
-    cachedDataTable = conn.getTable(dataTableName);
+    cachedDataTable = conn.getTableNoCache(conn.getTenantId(), dataTableName);
+  }

Review Comment:
   I checked this, and I don't think we refresh the PTable that the CDC 
consumer uses according to UCF.
   
   getDataTable() calls PhoenixConnection.getTable(String), which only reads 
the cache, doing a lookup only on a cache miss. Otherwise nothing else in the 
consumer resolves the data table through updateCache (with UCF) and nothing 
appears to invalidate the regionserver's PTable cache. An ALTER writes 
SYSTEM.CATALOG with UPSERTs and clears only the endpoint cache. So a 
regionserver can cache the old definition indefinitely and we need to look at 
it proactively.
   
   A UCF-bounded refresh would still not be safe for STRONG→EVENTUAL. Writers 
and the consumer refresh at different times. A writer that sees EVENTUAL first 
stops maintaining the index synchronously. A consumer that still sees STRONG 
skips those events and moves its tracker past them, so the index misses those 
updates permanently. The other direction (EVENTUAL→STRONG with an old view) 
only adds duplicate writes, which do no harm.
   
   I have kept the read in the batch update, but scoped it down to happen much 
less often. Now the consumer reads the definition only when a batch has events 
newer than its last read, and at most once per new 
`phoenix.index.cdc.consumer.metadata.refresh.interval.ms` (default 5 s). Events 
newer than the last read stay in the CDC queue until the next read. An old 
definition can delay an event but never skip it. Idle regions make no 
SYSTEM.CATALOG reads. Busy regions make at most one read per interval, down 
from one per batch.



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