magibney commented on a change in pull request #592:
URL: https://github.com/apache/solr/pull/592#discussion_r800091578



##########
File path: solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
##########
@@ -865,9 +936,26 @@ public BitDocSet getLiveDocSet() throws IOException {
     // Going through the filter cache will provide thread safety here if we 
only had getLiveDocs,
     // but the addition of setLiveDocs means we needed to add volatile to 
"liveDocs".
     BitDocSet docs = liveDocs;
-    if (docs == null) {
-      //note: maybe should instead calc manually by segment, using 
FixedBitSet.copyOf(segLiveDocs); avoid filter cache?
-      liveDocs = docs = getDocSetBits(matchAllDocsQuery);
+    if (docs != null) {
+      matchAllDocsCacheHitCount.incrementAndGet();
+    } else {
+      synchronized (matchAllDocsCacheComputationTracker) {
+        if (liveDocsFuture != null) {
+          // use future if it already exists
+          assert matchAllDocsCacheComputationTracker.incrementAndGet() > 0;
+        } else {
+          // otherwise create the initial/only future, and run it inline
+          assert matchAllDocsCacheComputationTracker.getAndSet(0) == 
Long.MIN_VALUE;
+          liveDocsFuture = new FutureTask<>(this::computeLiveDocs);
+          liveDocsFuture.run(); // first caller will block execution here
+        }
+      }
+      try {
+        docs = liveDocsFuture.get(); // subsequent callers block here, waiting 
for initial/only execution to complete

Review comment:
       resolved this with 779b69b114fd3b7dadb7adf203fd4c7eef5f75ec




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

Reply via email to