This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git

commit 18fa99b803f763f2b8d91b22768b2ab165b5987f
Author: Keith Turner <ktur...@apache.org>
AuthorDate: Fri Feb 7 17:02:00 2025 +0000

    Defers server invalidation in tablet location cache (#5308)
    
    Reapplies the changes in in 2.1 from #5308 after ignoring those changes
    in the merge commit 9df1a04018f8705a29916bad85de9e0eba969988.  This was
    done because the changes were 2.1 were being made to file that was
    deleted in main and significantly refactored.  Making these updates in a
    stand alone commit makes the diffs easier to look at.
---
 .../core/clientImpl/ClientTabletCacheImpl.java     | 39 ++++++++++++++--------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java
 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java
index 2dfbf288e3..5962c23e98 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java
@@ -101,6 +101,7 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
   protected final Text lastTabletRow;
 
   private final TreeSet<KeyExtent> badExtents = new TreeSet<>();
+  private final HashSet<String> badServers = new HashSet<>();
   private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
   private final Lock rLock = rwLock.readLock();
   private final Lock wLock = rwLock.writeLock();
@@ -504,17 +505,10 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
 
   @Override
   public void invalidateCache(ClientContext context, String server) {
-    int invalidatedCount = 0;
 
     wLock.lock();
     try {
-      for (CachedTablet cacheEntry : metaCache.values()) {
-        var loc = cacheEntry.getTserverLocation();
-        if (loc.isPresent() && loc.orElseThrow().equals(server)) {
-          badExtents.add(cacheEntry.getExtent());
-          invalidatedCount++;
-        }
-      }
+      badServers.add(server);
     } finally {
       wLock.unlock();
     }
@@ -522,10 +516,8 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
     lockChecker.invalidateCache(server);
 
     if (log.isTraceEnabled()) {
-      log.trace("invalidated {} cache entries  table={} server={}", 
invalidatedCount, tableId,
-          server);
+      log.trace("queued invalidation for table={} server={}", tableId, server);
     }
-
   }
 
   @Override
@@ -927,7 +919,7 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
       throws AccumuloSecurityException, AccumuloException, 
TableNotFoundException,
       InvalidTabletHostingRequestException {
 
-    if (badExtents.isEmpty()) {
+    if (badExtents.isEmpty() && badServers.isEmpty()) {
       return;
     }
 
@@ -936,7 +928,7 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
       if (!writeLockHeld) {
         rLock.unlock();
         wLock.lock();
-        if (badExtents.isEmpty()) {
+        if (badExtents.isEmpty() && badServers.isEmpty()) {
           return;
         }
       }
@@ -948,6 +940,27 @@ public class ClientTabletCacheImpl extends 
ClientTabletCache {
         removeOverlapping(metaCache, be);
       }
 
+      if (!badServers.isEmpty()) {
+        int removedCount = 0;
+        var locationIterator = metaCache.values().iterator();
+        while (locationIterator.hasNext()) {
+          var cacheEntry = locationIterator.next();
+          if (cacheEntry.getTserverLocation().isPresent()
+              && 
badServers.contains(cacheEntry.getTserverLocation().orElseThrow())) {
+            locationIterator.remove();
+            lookups.add(cacheEntry.getExtent().toMetaRange());
+            removedCount++;
+          }
+        }
+
+        if (log.isTraceEnabled()) {
+          log.trace("Invalidated {} cache entries for table {} related to 
servers {}", removedCount,
+              tableId, badServers);
+        }
+
+        badServers.clear();
+      }
+
       lookups = Range.mergeOverlapping(lookups);
 
       Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>();

Reply via email to