From 8c97645454c5ff461fd070ca6bf70126708f1924 Mon Sep 17 00:00:00 2001 From: Megan Carey Date: Mon, 25 Jan 2021 16:28:37 -0800 Subject: [PATCH] Adding null checks to lambdas and log to show size of shards when splits are enqueued --- .../cloud/autoscaling/IndexSizeTrigger.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/IndexSizeTrigger.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/IndexSizeTrigger.java index eb0ce52eb54b..5e0fd2a77517 100644 --- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/IndexSizeTrigger.java +++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/IndexSizeTrigger.java @@ -328,23 +328,24 @@ public void run() { final ReplicaInfo info = metricTags.get(tag); if (info == null) { log.warn("Missing replica info for response tag {}", tag); - } else { - // verify that it's a Number - if (!(size instanceof Number)) { - log.warn("invalid size value for tag {} - not a number: '{}' is {}", tag, size, size.getClass().getName()); - return; - } + return; + } + + // verify that it's a Number + if (!(size instanceof Number)) { + log.warn("invalid size value for tag {} - not a number: '{}' is {}", tag, size, size.getClass().getName()); + return; + } - ReplicaInfo currentInfo = currentSizes.computeIfAbsent(info.getCore(), k -> (ReplicaInfo)info.clone()); - if (tag.contains("INDEX")) { - currentInfo.getVariables().put(TOTAL_BYTES_SIZE_KEY, ((Number) size).longValue()); - } else if (tag.endsWith("SEARCHER.searcher.numDocs")) { - currentInfo.getVariables().put(DOCS_SIZE_KEY, ((Number) size).longValue()); - } else if (tag.endsWith("SEARCHER.searcher.maxDoc")) { - currentInfo.getVariables().put(MAX_DOC_KEY, ((Number) size).longValue()); - } else if (tag.endsWith("SEARCHER.searcher.indexCommitSize")) { - currentInfo.getVariables().put(COMMIT_SIZE_KEY, ((Number) size).longValue()); - } + ReplicaInfo currentInfo = currentSizes.computeIfAbsent(info.getCore(), k -> (ReplicaInfo)info.clone()); + if (tag.contains(CORE_IDX.metricsAttribute)) { + currentInfo.getVariables().put(TOTAL_BYTES_SIZE_KEY, ((Number) size).longValue()); + } else if (tag.endsWith("SEARCHER.searcher.numDocs")) { + currentInfo.getVariables().put(DOCS_SIZE_KEY, ((Number) size).longValue()); + } else if (tag.endsWith("SEARCHER.searcher.maxDoc")) { + currentInfo.getVariables().put(MAX_DOC_KEY, ((Number) size).longValue()); + } else if (tag.endsWith("SEARCHER.searcher.indexCommitSize")) { + currentInfo.getVariables().put(COMMIT_SIZE_KEY, ((Number) size).longValue()); } }); } @@ -363,6 +364,11 @@ public void run() { Set splittable = new HashSet<>(); currentSizes.forEach((coreName, info) -> { + // check for null + if (info == null) { + return; + } + // calculate estimated bytes long maxDoc = (Long)info.getVariable(MAX_DOC_KEY); long numDocs = (Long)info.getVariable(DOCS_SIZE_KEY); @@ -398,6 +404,11 @@ public void run() { Map> belowSize = new HashMap<>(); currentSizes.forEach((coreName, info) -> { + // check for null + if (info == null) { + return; + } + if (((Long)info.getVariable(BYTES_SIZE_KEY) < belowBytes || (Long)info.getVariable(DOCS_SIZE_KEY) < belowDocs) && // make sure we don't produce conflicting ops @@ -458,6 +469,9 @@ public void run() { params.put(SPLIT_BY_PREFIX, splitByPrefix); op.addHint(Suggester.Hint.PARAMS, params); ops.add(op); + + log.info("Shard with shardName={}, sizeInBytes={}, numDocs={} has exceeded configured threshold and will be split", + r.getShard(), r.getVariable(BYTES_SIZE_KEY), r.getVariable(DOCS_SIZE_KEY)); Long time = lastAboveEventMap.get(r.getCore()); if (time != null && eventTime.get() > time) { eventTime.set(time);