palashc commented on code in PR #1883:
URL: https://github.com/apache/phoenix/pull/1883#discussion_r1589670671


##########
phoenix-core-client/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java:
##########
@@ -6248,4 +6320,170 @@ public synchronized PhoenixTransactionClient 
initTransactionClient(Provider prov
     public List<LinkedBlockingQueue<WeakReference<PhoenixConnection>>> 
getCachedConnections() {
       return connectionQueues;
     }
+
+    /**
+     * Invalidate metadata cache from all region servers for the given list of
+     * InvalidateServerMetadataCacheRequest.
+     * @throws Throwable
+     */
+    public void 
invalidateServerMetadataCache(List<InvalidateServerMetadataCacheRequest> 
requests)
+            throws Throwable {
+        boolean invalidateCacheEnabled =
+                config.getBoolean(PHOENIX_METADATA_INVALIDATE_CACHE_ENABLED,
+                        DEFAULT_PHOENIX_METADATA_INVALIDATE_CACHE_ENABLED);
+        if (!invalidateCacheEnabled) {
+            LOGGER.info("Skip invalidating server metadata cache since conf 
property"
+                    + " phoenix.metadata.invalidate.cache.enabled is set to 
false");
+            return;
+        }
+        if (!QueryUtil.isServerConnection(props)) {
+            LOGGER.warn(INVALIDATE_SERVER_METADATA_CACHE_EX_MESSAGE);
+            throw new Exception(INVALIDATE_SERVER_METADATA_CACHE_EX_MESSAGE);
+        }
+
+        
metricsMetadataCachingSource.incrementMetadataCacheInvalidationOperationsCount();
+        Admin admin = getInvalidateMetadataCacheConnection().getAdmin();
+        // This will incur an extra RPC to the master. This RPC is required 
since we want to
+        // get current list of regionservers.
+        Collection<ServerName> serverNames = admin.getRegionServers(true);
+        PhoenixStopWatch stopWatch = new PhoenixStopWatch().start();
+        try {
+            invalidateServerMetadataCacheWithRetries(admin, serverNames, 
requests, false);
+            
metricsMetadataCachingSource.incrementMetadataCacheInvalidationSuccessCount();
+        } catch (Throwable t) {
+            
metricsMetadataCachingSource.incrementMetadataCacheInvalidationFailureCount();
+            throw t;
+        } finally {
+            metricsMetadataCachingSource
+                    
.addMetadataCacheInvalidationTotalTime(stopWatch.stop().elapsedMillis());
+        }
+    }
+
+    /**
+     * Invalidate metadata cache on all regionservers with retries for the 
given list of
+     * InvalidateServerMetadataCacheRequest. Each 
InvalidateServerMetadataCacheRequest contains
+     * tenantID, schema name and table name.
+     * We retry once before failing the operation.
+     *
+     * @param admin
+     * @param serverNames
+     * @param invalidateCacheRequests
+     * @param isRetry
+     * @throws Throwable
+     */
+    private void invalidateServerMetadataCacheWithRetries(Admin admin,
+            Collection<ServerName> serverNames,
+            List<InvalidateServerMetadataCacheRequest> invalidateCacheRequests,
+            boolean isRetry) throws Throwable {
+        RegionServerEndpointProtos.InvalidateServerMetadataCacheRequest 
protoRequest =
+                getRequest(invalidateCacheRequests);
+        // TODO Do I need my own executor or can I re-use 
QueryServices#Executor

Review Comment:
   Since the cache invalidation code is in CQSI and we would want to avoid 
creating a new thread pool for every DDL operation, how do you suggest we save 
the executor? We can have an `executor` in CQSI but we would not want client 
side CQSI to create an executor unnecessarily - or is that okay?



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