Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Fix IndexShardTests#testScheduledRefresh #110312

Merged
merged 13 commits into from
Jul 16, 2024
Merged
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) {
kingherc marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -3849,7 +3849,6 @@ public void testIsSearchIdle() throws Exception {
closeShards(primary);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/101008")
@TestIssueLogging(
issueUrl = "https://github.com/elastic/elasticsearch/issues/101008",
value = "org.elasticsearch.index.shard.IndexShard:TRACE"
Expand Down Expand Up @@ -3927,9 +3926,7 @@ public void testScheduledRefresh() throws Exception {
assertTrue(primary.searchIdleTime() >= TimeValue.ZERO.millis());
primary.flushOnIdle(0);
logger.info("--> scheduledRefresh(future5)");
kingherc marked this conversation as resolved.
Show resolved Hide resolved
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
arteam marked this conversation as resolved.
Show resolved Hide resolved
try (Engine.Searcher searcher = primary.acquireSearcher("test")) {
assertEquals(3, searcher.getIndexReader().numDocs());
}
Expand Down
Loading