virajjasani commented on code in PR #2321:
URL: https://github.com/apache/phoenix/pull/2321#discussion_r2600991114


##########
phoenix-core-server/src/main/java/org/apache/phoenix/index/PhoenixIndexMetaDataBuilder.java:
##########
@@ -117,4 +116,101 @@ public int getClientVersion() {
     }
 
   }
+
+  /**
+   * Get IndexMetaDataCache by looking up PTable using table metadata 
attributes attached to the
+   * mutation.
+   * @param env        RegionCoprocessorEnvironment.
+   * @param attributes Mutation attributes.
+   * @return IndexMetaDataCache or null if table metadata not found in 
attributes.
+   */
+  private static IndexMetaDataCache getIndexMetaDataCacheFromPTable(
+    RegionCoprocessorEnvironment env, Map<String, byte[]> attributes) {
+    try {
+      byte[] schemaBytes =
+        
attributes.get(MutationState.MutationMetadataType.SCHEMA_NAME.toString());
+      byte[] tableBytes =
+        
attributes.get(MutationState.MutationMetadataType.LOGICAL_TABLE_NAME.toString());
+      if (schemaBytes == null || tableBytes == null) {
+        LOGGER.error("Table metadata for table name and schema name not found 
in mutation "
+          + "attributes, falling back to GlobalCache lookup");
+        return null;
+      }
+      byte[] tenantIdBytes =
+        
attributes.get(MutationState.MutationMetadataType.TENANT_ID.toString());
+      byte[] txState = 
attributes.get(BaseScannerRegionObserverConstants.TX_STATE);
+      byte[] clientVersionBytes = 
attributes.get(BaseScannerRegionObserverConstants.CLIENT_VERSION);
+
+      final int clientVersion = clientVersionBytes == null
+        ? ScanUtil.UNKNOWN_CLIENT_VERSION
+        : Bytes.toInt(clientVersionBytes);
+      final PhoenixTransactionContext txnContext =
+        TransactionFactory.getTransactionContext(txState, clientVersion);
+
+      String fullTableName = SchemaUtil.getTableName(schemaBytes, tableBytes);
+      String tenantId =
+        tenantIdBytes == null || tenantIdBytes.length == 0 ? null : 
Bytes.toString(tenantIdBytes);
+      Properties props = new Properties();
+      if (tenantId != null) {
+        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+      }
+      try (Connection conn = QueryUtil.getConnectionOnServer(props, 
env.getConfiguration())) {
+        PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
+        PTable dataTable = pconn.getTable(tenantId, fullTableName);
+        final List<IndexMaintainer> indexMaintainers =
+          buildIndexMaintainersFromPTable(dataTable, pconn);

Review Comment:
   @kadirozde we cannot cache them if UPDATE_CACHE_FREQUENCY is ALWAYS. Please 
check the PR description. I have listed all the scenarios that are handled with 
UCF of data table.
   
   Similarly, for PTable of type index also, we should not cache them. What if 
client changes index state from ACTIVE to DISABLE with UCF as 0?
   
   The caching of any of PTable attributes only depends on UCF.



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