-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[CCR] Improve error when operations are missing #35179
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
martijnvg
merged 2 commits into
elastic:master
from
martijnvg:ccr_missing_operations_error
Nov 6, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
*/ | ||
package org.elasticsearch.xpack.ccr.action; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
import org.elasticsearch.action.admin.indices.stats.ShardStats; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
|
@@ -84,4 +87,33 @@ public void testGetOperationsBasedOnGlobalSequenceId() throws Exception { | |
assertThat(operation.id(), equalTo("5")); | ||
} | ||
|
||
public void testMissingOperations() { | ||
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. Nice test 👍 |
||
client().admin().indices().prepareCreate("index") | ||
.setSettings(Settings.builder() | ||
.put("index.soft_deletes.enabled", true) | ||
.put("index.soft_deletes.retention.operations", 0) | ||
.put("index.number_of_shards", 1) | ||
.put("index.number_of_replicas", 0)) | ||
.get(); | ||
|
||
for (int i = 0; i < 16; i++) { | ||
client().prepareIndex("index", "_doc", "1").setSource("{}", XContentType.JSON).get(); | ||
client().prepareDelete("index", "_doc", "1").get(); | ||
} | ||
client().admin().indices().refresh(new RefreshRequest("index")).actionGet(); | ||
ForceMergeRequest forceMergeRequest = new ForceMergeRequest("index"); | ||
forceMergeRequest.maxNumSegments(1); | ||
client().admin().indices().forceMerge(forceMergeRequest).actionGet(); | ||
|
||
ShardStats shardStats = client().admin().indices().prepareStats("index").get().getIndex("index").getShards()[0]; | ||
String historyUUID = shardStats.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY); | ||
ShardChangesAction.Request request = new ShardChangesAction.Request(shardStats.getShardRouting().shardId(), historyUUID); | ||
request.setFromSeqNo(0L); | ||
request.setMaxOperationCount(1); | ||
|
||
Exception e = expectThrows(ElasticsearchException.class, () -> client().execute(ShardChangesAction.INSTANCE, request).actionGet()); | ||
assertThat(e.getMessage(), equalTo("Operations are no longer available for replicating. Maybe increase the retention setting " + | ||
"[index.soft_deletes.retention.operations]?")); | ||
} | ||
|
||
} |
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.
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 am fine with this change but I prefer to narrow the scope. How about catching and converting the exception with the existing
try
inShardChangesAction#getOperations
? I am thinking to have a dedicated exception so that we can access "fromSeqNo" and "toSeqNo" but maybe overkilled. WDYT?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.
We should not introduce that dedicated exception I think.
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 think converting the exception there is premature. If a replica shard copy is queried, it may not have all the operations, but another shard may have it, so the shard changes api can retry it on another shard copy. Then the exception convertion was not needed, since the shard changes api was able to serve the request after all.
When we intercept the exception at the place were the exception conversion is now, we know that the shard changes has attempted the read the range of operations on all shard copies, but still wasn't able to satisfy the request.
I was considering this, because the way we detect this kind of error is weak (instance of IllegalStateException AND the exception message containing a specific message). What about throwing an
EngineException
with two headers (from and to seqno) inLuceneChangesSnapshot#rangeCheck(...)
?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 for the explanation. Let's do it here. Since the error has an inner cause which provides from_seq_no and to_seq_no information, I think we are good.
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.
+100 to any way that doesn't rely on message strings. Thanks for iterating on this to get there!