Fix assertion at end of forceRefreshes#37559
Merged
ywelsch merged 2 commits intoelastic:masterfrom Jan 17, 2019
Merged
Conversation
Collaborator
|
Pinging @elastic/es-distributed |
original-brownbear
approved these changes
Jan 17, 2019
Contributor
original-brownbear
left a comment
There was a problem hiding this comment.
LGTM, one question/suggestion to package it differently maybe :)
| listener.accept(forced); | ||
| } | ||
| }; | ||
| if (refreshListeners == null) { |
Contributor
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
sure, can you push that change directly to the PR?
Contributor
|
Jenkins run Gradle build tests 1 |
Contributor
Author
|
@elasticmachine please run the Gradle build tests 1 |
1 similar comment
Contributor
Author
|
@elasticmachine please run the Gradle build tests 1 |
ywelsch
added a commit
that referenced
this pull request
Jan 17, 2019
This commit ensures that we only change refreshListeners to a list if we're actually adding something to the list.
jasontedor
added a commit
to jasontedor/elasticsearch
that referenced
this pull request
Jan 17, 2019
…-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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've had a local run on my CI where the assertion
assert refreshListeners == null;at the end offorceRefreshestripped during a relocation because a concurrentaddOrNotifywas called that setrefreshListenersfromnullto an empty list.This PR ensures, we only change
refreshListenersto a list if we're actually adding something to the list.