-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fail primary term and generation listeners on a closed shard #122713
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
Changes from 3 commits
1bc218a
c337e28
bba11b4
97f6269
ae93883
5dd1c9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4491,14 +4491,17 @@ public void waitForEngineOrClosedShard(ActionListener<Void> listener) { | |
| } | ||
|
|
||
| /** | ||
| * Registers a listener for an event when the shard advances to the provided primary term and segment generation | ||
| * Registers a listener for an event when the shard advances to the provided primary term and segment generation. | ||
| * Completes the listener with a {@link IndexShardClosedException} if the shard is closed. | ||
| */ | ||
| public void waitForPrimaryTermAndGeneration(long primaryTerm, long segmentGeneration, ActionListener<Long> listener) { | ||
| waitForEngineOrClosedShard( | ||
| listener.delegateFailureAndWrap( | ||
| (l, ignored) -> getEngine().addPrimaryTermAndGenerationListener(primaryTerm, segmentGeneration, l) | ||
| ) | ||
| ); | ||
| waitForEngineOrClosedShard(listener.delegateFailureAndWrap((l, ignored) -> { | ||
| if (state == IndexShardState.CLOSED) { | ||
| l.onFailure(new IndexShardClosedException(shardId)); | ||
|
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. Hmm, I am a bit concerned we might be throwing now in cases where we did not expect. Specifically,
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. The original
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. btw, I still wonder if the shard was relocated before it had the chance to start or what's going on in the failing test, I didn't have the time to check.
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 @arteam can answer your question by checking the original test failure's sequence of events. As to the trappiness of the API, we can correct it (this is something this PR tries to do) but we should ensure we don't change behavior and create bugs. That's why I'd like us to ensure that if the unpromotable refresh ignored the shard being closed, we also ignore it with this PR. @arteam can you check?
Contributor
Author
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. Yes, it's a good point to check for regressions in
Contributor
Author
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.
No, it was during the closure of a shard. I believe the shard got closed before the search shard got initialized.
Contributor
Author
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.
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. @arteam in that case I think that we should add a test and maybe fix it on
Contributor
Author
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. @fcofdez
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. Sounds good to me 👍 |
||
| } else { | ||
| getEngine().addPrimaryTermAndGenerationListener(primaryTerm, segmentGeneration, l); | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3334,6 +3334,22 @@ public void testWaitForClosedListener() throws IOException { | |
| assertThat("listener should have been called", called.get(), equalTo(true)); | ||
| } | ||
|
|
||
| public void testWaitForPrimaryTermAndGenerationFailsForClosedShard() throws IOException { | ||
| Settings settings = indexSettings(IndexVersion.current(), 1, 1).build(); | ||
| IndexMetadata metadata = IndexMetadata.builder("test").putMapping(""" | ||
| { "properties": { "foo": { "type": "text"}}}""").settings(settings).primaryTerm(0, 1).build(); | ||
| IndexShard primary = newShard(new ShardId(metadata.getIndex(), 0), true, "n1", metadata, null); | ||
|
||
|
|
||
| var exception = new AtomicReference<Exception>(); | ||
| ActionListener<Long> listener = ActionListener.wrap(l -> { assert false : l; }, e -> exception.set(e)); | ||
|
||
| primary.waitForPrimaryTermAndGeneration(0L, 0L, listener); | ||
|
|
||
| assertNull("waitForPrimaryTermAndGeneration should be waiting", exception.get()); | ||
| closeShards(primary); | ||
| // Should bail out earlier without calling the engine | ||
| assertThat(exception.get(), instanceOf(IndexShardClosedException.class)); | ||
| } | ||
|
|
||
| public void testRecoverFromLocalShard() throws IOException { | ||
| Settings settings = indexSettings(IndexVersion.current(), 1, 1).build(); | ||
| IndexMetadata metadata = IndexMetadata.builder("source") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.