sonatype-lift[bot] commented on a change in pull request #238: URL: https://github.com/apache/solr/pull/238#discussion_r692353186
########## 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: *NULL_DEREFERENCE:* object returned by `replicableCommitOnLeader.get("generation")` could be null and is dereferenced at line 203. (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `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-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org