Skip to content

Commit

Permalink
Add ability to distinguish whether we called refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
arteam committed Jul 3, 2024
1 parent d3781ab commit a37a174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 12 additions & 8 deletions server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3950,8 +3950,8 @@ ReplicationTracker getReplicationTracker() {
/**
* Executes a scheduled refresh if necessary. Completes the listener with true if a refresh was performed otherwise false.
*/
public void scheduledRefresh(ActionListener<Boolean> listener) {
ActionListener.run(listener, l -> {
public boolean scheduledRefresh(ActionListener<Boolean> listener) {
try {
verifyNotClosed();
boolean listenerNeedsRefresh = refreshListeners.refreshNeeded();
final Engine engine = getEngine();
Expand All @@ -3967,18 +3967,22 @@ && isSearchIdle()
logger.trace("scheduledRefresh: search-idle, skipping refresh");
engine.maybePruneDeletes(); // try to prune the deletes in the engine if we accumulated some
setRefreshPending(engine);
l.onResponse(false);
return;
listener.onResponse(false);
return false;
} else {
logger.trace("scheduledRefresh: refresh with source [schedule]");
engine.maybeRefresh("schedule", l.map(Engine.RefreshResult::refreshed));
return;
engine.maybeRefresh("schedule", listener.map(Engine.RefreshResult::refreshed));
return true;
}
}
logger.trace("scheduledRefresh: no refresh needed");
engine.maybePruneDeletes(); // try to prune the deletes in the engine if we accumulated some
l.onResponse(false);
});
listener.onResponse(false);
return false;
} catch (Exception e) {
listener.onFailure(e);
return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3926,11 +3926,7 @@ public void testScheduledRefresh() throws Exception {
assertTrue(primary.searchIdleTime() >= TimeValue.ZERO.millis());
primary.flushOnIdle(0);
logger.info("--> scheduledRefresh(future5)");
assertBusy(() -> {
PlainActionFuture<Boolean> future5 = new PlainActionFuture<>();
primary.scheduledRefresh(future5);
assertTrue(future5.actionGet()); // make sure we refresh once the shard is inactive
});
assertTrue(primary.scheduledRefresh(ActionListener.noop())); // make sure we refresh once the shard is inactive
try (Engine.Searcher searcher = primary.acquireSearcher("test")) {
assertEquals(3, searcher.getIndexReader().numDocs());
}
Expand Down

0 comments on commit a37a174

Please sign in to comment.