fabriziofortino commented on code in PR #2442:
URL: https://github.com/apache/jackrabbit-oak/pull/2442#discussion_r2273961848


##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/facets/ElasticStatisticalFacetAsyncProvider.java:
##########
@@ -96,87 +106,120 @@ public class ElasticStatisticalFacetAsyncProvider 
implements ElasticFacetProvide
                 )
         );
 
-        LOG.trace("Kicking search query with random sampling {}", 
searchRequest);
-        CompletableFuture<SearchResponse<ObjectNode>> searchFuture =
-                connection.getAsyncClient().search(searchRequest, 
ObjectNode.class);
-
-        searchFuture.whenCompleteAsync((searchResponse, throwable) -> {
-            try {
-                if (throwable != null) {
-                    LOG.error("Error while retrieving sample documents. Search 
request: {}", searchRequest, throwable);
-                } else {
-                    List<Hit<ObjectNode>> searchHits = 
searchResponse.hits().hits();
-                    this.sampled = searchHits != null ? searchHits.size() : 0;
-                    if (sampled > 0) {
-                        this.totalHits = searchResponse.hits().total().value();
-                        processAggregations(searchResponse.aggregations());
-                        searchResponse.hits().hits().forEach(this::processHit);
-                        computeStatisticalFacets();
-                    }
-                }
-            } finally {
-                latch.countDown();
-            }
-        });
+        this.queryStartTimeNanos = System.nanoTime();
+        LOG.trace("Kicking search query with random sampling {}", 
searchRequest, new Throwable());

Review Comment:
   any specific reason to print the stacktrace here?



##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/facets/ElasticStatisticalFacetAsyncProvider.java:
##########
@@ -63,14 +64,23 @@ public class ElasticStatisticalFacetAsyncProvider 
implements ElasticFacetProvide
     private final Predicate<String> isAccessible;
     private final Set<String> facetFields;
     private final long facetsEvaluationTimeoutMs;
-    private final Map<String, List<FulltextIndex.Facet>> allFacets = new 
HashMap<>();
-    private final Map<String, Map<String, MutableInt>> accessibleFacetCounts = 
new ConcurrentHashMap<>();
     private Map<String, List<FulltextIndex.Facet>> facets;
     private final SearchRequest searchRequest;
-    private final CountDownLatch latch = new CountDownLatch(1);
+    private final CompletableFuture<Map<String, List<FulltextIndex.Facet>>> 
searchFuture;
     private int sampled;
     private long totalHits;
 
+    private final long queryStartTimeNanos;
+    // All these variables are updated only by the event handler thread of 
Elastic. They are read either by that
+    // same thread or by the client thread that waits for the latch to 
complete. Since the latch causes a memory barrier,
+    // the updated values will be visible to the client thread.
+    private long queryTimeNanos;
+    private long processAggregationsTimeNannos;

Review Comment:
   typo
   ```suggestion
       private long processAggregationsTimeNanos;
   ```



-- 
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: oak-dev-unsubscr...@jackrabbit.apache.org

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

Reply via email to