You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/09/17 18:42:17 UTC

[GitHub] [solr] anshumg commented on a change in pull request #238: SOLR-15286: A brand new follower in the legacy mode should wait to replicate index before reporting healthy

anshumg commented on a change in pull request #238:
URL: https://github.com/apache/solr/pull/238#discussion_r711275583



##########
File path: solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
##########
@@ -135,6 +157,77 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
     rsp.add(STATUS, OK);
   }
 
+  private void healthCheckLegacyMode(SolrQueryRequest req, SolrQueryResponse rsp) {
+    Integer maxGenerationLag = req.getParams().getInt(HealthCheckRequest.PARAM_MAX_GENERATION_LAG);
+    List<String> laggingCoresInfo = new ArrayList<>();
+    boolean allCoresAreInSync = true;
+
+    // check only if max generation lag is specified
+    if(maxGenerationLag != null) {
+      for(SolrCore core : coreContainer.getCores()) {
+        ReplicationHandler replicationHandler =
+          (ReplicationHandler) core.getRequestHandler(ReplicationHandler.PATH);
+        if(replicationHandler.isFollower()) {
+          boolean isCoreInSync =
+            isWithinGenerationLag(core, replicationHandler, maxGenerationLag, laggingCoresInfo);
+
+          allCoresAreInSync &= isCoreInSync;
+        }
+      }
+    }
+
+    if(allCoresAreInSync) {
+      rsp.add("message",
+        String.format(Locale.ROOT, "All the followers are in sync with leader (within maxGenerationLag: %d) " +
+          "or all the cores are acting as leader", maxGenerationLag));
+      rsp.add(STATUS, OK);
+    } else {
+      rsp.add("message",
+        String.format(Locale.ROOT,"Cores violating maxGenerationLag:%d.%n%s", maxGenerationLag,
+          String.join(",\n", laggingCoresInfo)));
+      rsp.add(STATUS, FAILURE);
+    }
+  }
+
+  private boolean isWithinGenerationLag(final SolrCore core, ReplicationHandler replicationHandler,
+                                        int maxGenerationLag, List<String> laggingCoresInfo) {
+    IndexFetcher indexFetcher = null;
+    try {
+      // may not be the best way to get leader's replicableCommit
+      NamedList<?> follower =
+        ReplicationHandler.getObjectWithBackwardCompatibility(replicationHandler.getInitArgs(), "follower",
+                  "slave");
+      indexFetcher = new IndexFetcher(follower, replicationHandler, core);
+
+      NamedList<?> replicableCommitOnLeader = indexFetcher.getLatestVersion();
+      long leaderGeneration = (Long) replicableCommitOnLeader.get(GENERATION);

Review comment:
       @sonatype-lift ignore




-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org