keith-turner commented on code in PR #3429:
URL: https://github.com/apache/accumulo/pull/3429#discussion_r1214886547


##########
core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java:
##########
@@ -556,15 +557,68 @@ public CachedTablet findTablet(ClientContext context, 
Text row, boolean skipRow,
           String.format("%.3f secs", timer.scale(SECONDS)));
     }
 
-    if (tl != null && locationNeed == LocationNeed.REQUIRED && 
tl.getTserverLocation().isEmpty()) {
-      requestTabletHosting(context, List.of(tl));
-      return null;
+    if (tl != null && locationNeed == LocationNeed.REQUIRED) {
+      Map<KeyExtent,CachedTablet> extentsToHost =
+          findExtentsToHost(context, minimumHostAhead * 2, hostAheadRange, 
lcSession, tl);
+
+      if (!extentsToHost.isEmpty()) {
+        if (extentsToHost.containsKey(tl.getExtent()) || extentsToHost.size() 
>= minimumHostAhead) {
+          requestTabletHosting(context, extentsToHost.values());
+        }
+      }
+
+      if (tl.getTserverLocation().isEmpty()) {
+        return null;
+      }
     }
 
     return tl;
 
   }
 
+  private Map<KeyExtent,CachedTablet> findExtentsToHost(ClientContext context, 
int hostAheadCount,
+      Range hostAheadRange, LockCheckerSession lcSession, CachedTablet 
firstTablet)
+      throws AccumuloException, TableNotFoundException, 
InvalidTabletHostingRequestException,
+      AccumuloSecurityException {
+    Map<KeyExtent,CachedTablet> extentsToHost;
+
+    if (hostAheadCount > 0) {
+      extentsToHost = new HashMap<>();
+      if (firstTablet.getTserverLocation().isEmpty()) {
+        extentsToHost.put(firstTablet.getExtent(), firstTablet);
+      }
+
+      KeyExtent extent = firstTablet.getExtent();
+
+      var currTablet = extent;
+
+      for (int i = 0; i < hostAheadCount; i++) {
+        if (currTablet.endRow() == null || !hostAheadRange.contains(new 
Key(currTablet.endRow()))) {
+          break;
+        }
+
+        CachedTablet followingTablet = _findTablet(context, 
currTablet.endRow(), true, false, true,
+            lcSession, LocationNeed.REQUIRED);

Review Comment:
   The method is only called when the calling method has location need of 
required.    I had thought of passing location need to this method and having 
it fail if it was not required.  I can try that and see what it looks like.



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