-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Fix assertion at end of forceRefreshes #37559
Conversation
Pinging @elastic/es-distributed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one question/suggestion to package it differently maybe :)
@@ -145,6 +144,9 @@ public boolean addOrNotify(Translog.Location location, Consumer<Boolean> listene | |||
listener.accept(forced); | |||
} | |||
}; | |||
if (refreshListeners == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be less confusing if we just moved the whole logic for creating the refreshListeners
here
So:
diff --git a/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java b/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java
index b4b9e13f7e0..713563eb111 100644
--- a/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java
+++ b/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java
@@ -129,15 +129,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
return true;
}
synchronized (this) {
- List<Tuple<Translog.Location, Consumer<Boolean>>> listeners = refreshListeners;
- if (listeners == null) {
- if (closed) {
- throw new IllegalStateException("can't wait for refresh on a closed index");
- }
- listeners = new ArrayList<>();
- refreshListeners = listeners;
+ if (closed) {
+ throw new IllegalStateException("can't wait for refresh on a closed index");
}
- if (refreshForcers == 0 && listeners.size() < getMaxRefreshListeners.getAsInt()) {
+ List<Tuple<Translog.Location, Consumer<Boolean>>> listeners = refreshListeners;
+ final int maxRefreshes = getMaxRefreshListeners.getAsInt();
+ if (refreshForcers == 0 && maxRefreshes > 0 && (listeners == null || listeners.size() < maxRefreshes)) {
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true);
Consumer<Boolean> contextPreservingListener = forced -> {
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
@@ -145,8 +142,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
listener.accept(forced);
}
};
+ if (listeners == null) {
+ listeners = new ArrayList<>();
+ }
// We have a free slot so register the listener
listeners.add(new Tuple<>(location, contextPreservingListener));
+ refreshListeners = listeners;
return false;
}
}
... would also save needlessly instantiating an ArrayList
when refreshForcers
is > 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, can you push that change directly to the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ee15306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
Jenkins run Gradle build tests 1 |
@elasticmachine please run the Gradle build tests 1 |
1 similar comment
@elasticmachine please run the Gradle build tests 1 |
This commit ensures that we only change refreshListeners to a list if we're actually adding something to the list.
…-response-header-performance * elastic/master: Remove Redundant RestoreRequest Class (elastic#37535) Create specific exception for when snapshots are in progress (elastic#37550) Mute UnicastZenPingTests#testSimplePings [DOCS] Adds size limitation to the get datafeeds APIs (elastic#37578) Fix assertion at end of forceRefreshes (elastic#37559) Propagate Errors in executors to uncaught exception handler (elastic#36137) [DOCS] Adds limitation to the get jobs API (elastic#37549) Add set_priority action to ILM (elastic#37397) Make recovery source send operations non-blocking (elastic#37503) Allow field types to optimize phrase prefix queries (elastic#37436) Added fatal_exception field for ccr stats in monitoring mapping. (elastic#37563) Fix testRelocateWhileContinuouslyIndexingAndWaitingForRefresh (elastic#37560) Moved ccr integration to the package with other ccr integration tests. Mute TransportClientNodesServiceTests#testListenerFailures Decreased time out in test Fix erroneous docstrings for abstract bulk by scroll request (elastic#37517) SQL: Rename SQL type DATE to DATETIME (elastic#37395) Remove the AbstracLifecycleComponent constructor with Settings (elastic#37523)
I've had a local run on my CI where the assertion
assert refreshListeners == null;
at the end offorceRefreshes
tripped during a relocation because a concurrentaddOrNotify
was called that setrefreshListeners
fromnull
to an empty list.This PR ensures, we only change
refreshListeners
to a list if we're actually adding something to the list.