You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/09/28 16:39:10 UTC

[GitHub] [lucene] stefanvodita commented on a diff in pull request #11780: GH#11601: Add ability to compute reader states after refresh

stefanvodita commented on code in PR #11780:
URL: https://github.com/apache/lucene/pull/11780#discussion_r982630324


##########
lucene/core/src/java/org/apache/lucene/search/ReferenceManager.java:
##########
@@ -219,6 +219,36 @@ public final boolean maybeRefresh() throws IOException {
     return doTryRefresh;
   }
 
+  /** Compute some state of the reference using a parameter. */
+  @FunctionalInterface
+  public interface StateCalculator<R, G, P> {
+    R calculate(G current, P param);
+  }
+
+  /**
+   * If you need to compute something after the refresh, you can use this method instead of {@link
+   * #maybeRefresh()}.
+   *
+   * @throws IOException if refreshing the resource causes an {@link IOException}
+   */
+  public final <R, P> R maybeRefreshAndReturnState(
+      StateCalculator<R, G, P> refreshedStateCalculator, P param) throws IOException {
+    ensureOpen();
+
+    // Ensure only 1 thread does refresh at once; other threads just return immediately:
+    final boolean doTryRefresh = refreshLock.tryLock();
+    if (doTryRefresh) {
+      try {
+        doMaybeRefresh();
+        return refreshedStateCalculator.calculate(current, param);

Review Comment:
   We’re guaranteeing that no other refresh happens before computing the reader states. Maybe that’s not important to do? If so, then the user can always refresh and then compute their own reader states.



-- 
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@lucene.apache.org

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


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