-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Force Refresh Listeners when Acquiring all Operation Permits #36835
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
Merged
original-brownbear
merged 12 commits into
elastic:master
from
original-brownbear:relocation-refresh-fix
Dec 28, 2018
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
146f1d0
RELOCATION:Fix Indef. Block when Wait on Refresh
original-brownbear f40c6a6
CR: different fix
original-brownbear 70d2a24
Merge remote-tracking branch 'elastic/master' into relocation-refresh…
original-brownbear b426bd2
Merge remote-tracking branch 'elastic/master' into relocation-refresh…
original-brownbear a822245
Merge remote-tracking branch 'elastic/master' into relocation-refresh…
original-brownbear c0893c4
CR: Prevent new listeners more reliably
original-brownbear ca07cb3
Merge remote-tracking branch 'elastic/master' into relocation-refresh…
original-brownbear f7a5171
CR: handle multiple concurrent force refresh, cover other cases of ac…
original-brownbear daa9fc7
Refactor
ywelsch 71bef56
CR: add test
original-brownbear 4a5483d
Merge remote-tracking branch 'elastic/master' into relocation-refresh…
original-brownbear bf73f54
CR: add assert
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.lucene.search.ReferenceManager; | ||
| import org.elasticsearch.common.collect.Tuple; | ||
| import org.elasticsearch.common.lease.Releasable; | ||
| import org.elasticsearch.common.util.concurrent.RunOnce; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.index.translog.Translog; | ||
|
|
||
|
|
@@ -53,6 +55,13 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener, | |
| * Is this closed? If true then we won't add more listeners and have flushed all pending listeners. | ||
| */ | ||
| private volatile boolean closed = false; | ||
|
|
||
| /** | ||
| * Force-refreshes new refresh listeners that are added while {@code >= 0}. Used to prevent becoming blocked on operations waiting for | ||
| * refresh during relocation. | ||
| */ | ||
| private int refreshForcers; | ||
|
|
||
| /** | ||
| * List of refresh listeners. Defaults to null and built on demand because most refresh cycles won't need it. Entries are never removed | ||
| * from it, rather, it is nulled and rebuilt when needed again. The (hopefully) rare entries that didn't make the current refresh cycle | ||
|
|
@@ -75,6 +84,32 @@ public RefreshListeners(IntSupplier getMaxRefreshListeners, Runnable forceRefres | |
| this.threadContext = threadContext; | ||
| } | ||
|
|
||
| /** | ||
| * Force-refreshes newly added listeners and forces a refresh if there are currently listeners registered. See {@link #refreshForcers}. | ||
| */ | ||
| public Releasable forceRefreshes() { | ||
| synchronized (this) { | ||
|
original-brownbear marked this conversation as resolved.
|
||
| assert refreshForcers >= 0; | ||
| refreshForcers += 1; | ||
| } | ||
| final RunOnce runOnce = new RunOnce(() -> { | ||
| synchronized (RefreshListeners.this) { | ||
| assert refreshForcers > 0; | ||
| refreshForcers -= 1; | ||
| } | ||
| }); | ||
| if (refreshNeeded()) { | ||
| try { | ||
| forceRefresh.run(); | ||
| } catch (Exception e) { | ||
| runOnce.run(); | ||
| throw e; | ||
| } | ||
| } | ||
| assert refreshListeners == null; | ||
| return () -> runOnce.run(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we could assert before this line here that |
||
| } | ||
|
|
||
| /** | ||
| * Add a listener for refreshes, calling it immediately if the location is already visible. If this runs out of listener slots then it | ||
| * forces a refresh and calls the listener immediately as well. | ||
|
|
@@ -102,7 +137,7 @@ public boolean addOrNotify(Translog.Location location, Consumer<Boolean> listene | |
| listeners = new ArrayList<>(); | ||
| refreshListeners = listeners; | ||
| } | ||
| if (listeners.size() < getMaxRefreshListeners.getAsInt()) { | ||
| if (refreshForcers == 0 && listeners.size() < getMaxRefreshListeners.getAsInt()) { | ||
| ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true); | ||
| Consumer<Boolean> contextPreservingListener = forced -> { | ||
| try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { | ||
|
|
||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.