Lokesh Khurana created PHOENIX-7965:
---------------------------------------

             Summary: ConnectionQueryServicesImpl.getMetaDataCache() returns 
null after connection close, causing a bare NPE during concurrent query 
compilation
                 Key: PHOENIX-7965
                 URL: https://issues.apache.org/jira/browse/PHOENIX-7965
             Project: Phoenix
          Issue Type: Bug
            Reporter: Lokesh Khurana
            Assignee: Lokesh Khurana


Problem
  ConnectionQueryServicesImpl.getMetaDataCache() is unguarded:
  public PMetaData getMetaDataCache() {
    return latestMetaData;   // no null check
  }
  ConnectionQueryServicesImpl.close() sets latestMetaData = null (the field is 
private volatile PMetaData latestMetaData). The JDBC compile path reads the 
shared cache via
  PhoenixConnection.getTableRef() → 
getQueryServices().getMetaDataCache().getTableRef(key). If a connection/CQSI is 
closed concurrently with an in-flight query compilation (e.g. during a
  cluster failover or connection-pool teardown), getMetaDataCache() returns 
null and the subsequent .getTableRef(key) throws a bare, causeless 
NullPointerException with no message — opaque to
  operators and hard to triage. The same exposure exists via 
PhoenixConnection.getFunction() and getSchema().

  Root cause
  Introduced by PHOENIX-6761 ("Phoenix Client Side Metadata Caching 
Improvement", commit 9f31c3eca3), which replaced PhoenixConnection's 
per-connection metadata snapshot with a read of the
  shared, close()-nullable CQSI cache and added the unguarded 
getMetaDataCache() accessor. A guard method, 
throwConnectionClosedIfNullMetaData(), already exists and is invoked by every 
other
  cache accessor/mutator (addTable, removeTable, pruneTables, the internal 
getTable, etc.) — but not by getMetaDataCache(), which is the one accessor the 
compile path uses.

  Fix
  Invoke throwConnectionClosedIfNullMetaData() inside getMetaDataCache() so a 
closed connection surfaces the existing descriptive "Connection to the cluster 
is closed" exception instead of a
  bare NPE. This makes the failure diagnosable and consistent with the other 
accessors. Add a unit test asserting the descriptive exception (not a bare NPE) 
when the cache has been nulled by
  close().



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to