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
Avoid losing ops in file-based recovery #22945
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -27,14 +27,17 @@ | |
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.seqno.SeqNoStats; | ||
import org.elasticsearch.index.seqno.SequenceNumbersService; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.elasticsearch.test.rest.yaml.ObjectPath; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -109,26 +112,58 @@ public void testSeqNoCheckpoints() throws Exception { | |
createIndex(index, settings.build()); | ||
try (RestClient newNodeClient = buildClient(restClientSettings(), | ||
nodes.getNewNodes().stream().map(Node::getPublishAddress).toArray(HttpHost[]::new))) { | ||
int numDocs = indexDocs(index, 0, randomInt(5)); | ||
int numDocs = 0; | ||
final int numberOfInitialDocs = 1 + randomInt(5); | ||
logger.info("indexing [{}] docs initially", numberOfInitialDocs); | ||
numDocs += indexDocs(index, 0, numberOfInitialDocs); | ||
assertSeqNoOnShards(nodes, checkGlobalCheckpoints, 0, newNodeClient); | ||
|
||
logger.info("allowing shards on all nodes"); | ||
updateIndexSetting(index, Settings.builder().putNull("index.routing.allocation.include._name")); | ||
ensureGreen(); | ||
logger.info("indexing some more docs"); | ||
numDocs += indexDocs(index, numDocs, randomInt(5)); | ||
final int numberOfDocsAfterAllowingShardsOnAllNodes = 1 + randomInt(5); | ||
logger.info("indexing [{}] docs after allowing shards on all nodes", numberOfDocsAfterAllowingShardsOnAllNodes); | ||
numDocs += indexDocs(index, numDocs, numberOfDocsAfterAllowingShardsOnAllNodes); | ||
assertSeqNoOnShards(nodes, checkGlobalCheckpoints, 0, newNodeClient); | ||
logger.info("moving primary to new node"); | ||
Shard primary = buildShards(nodes, newNodeClient).stream().filter(Shard::isPrimary).findFirst().get(); | ||
logger.info("moving primary to new node by excluding {}", primary.getNode().getNodeName()); | ||
updateIndexSetting(index, Settings.builder().put("index.routing.allocation.exclude._name", primary.getNode().getNodeName())); | ||
ensureGreen(); | ||
logger.info("indexing some more docs"); | ||
int numDocsOnNewPrimary = indexDocs(index, numDocs, randomInt(5)); | ||
numDocs += numDocsOnNewPrimary; | ||
int numDocsOnNewPrimary = 0; | ||
final int numberOfDocsAfterMovingPrimary = 1 + randomInt(5); | ||
logger.info("indexing [{}] docs after moving primary", numberOfDocsAfterMovingPrimary); | ||
numDocsOnNewPrimary += indexDocs(index, numDocs, numberOfDocsAfterMovingPrimary); | ||
numDocs += numberOfDocsAfterMovingPrimary; | ||
assertSeqNoOnShards(nodes, checkGlobalCheckpoints, numDocsOnNewPrimary, newNodeClient); | ||
/* | ||
* Dropping the number of replicas to zero, and then increasing it to one triggers a recovery thus exercising any BWC-logic in | ||
* the recovery code. | ||
*/ | ||
logger.info("setting number of replicas to 0"); | ||
updateIndexSetting(index, Settings.builder().put("index.number_of_replicas", 0)); | ||
final int numberOfDocsAfterDroppingReplicas = 1 + randomInt(5); | ||
logger.info("indexing [{}] docs after setting number of replicas to 0", numberOfDocsAfterDroppingReplicas); | ||
numDocsOnNewPrimary += indexDocs(index, numDocs, numberOfDocsAfterDroppingReplicas); | ||
numDocs += numberOfDocsAfterDroppingReplicas; | ||
logger.info("setting number of replicas to 1"); | ||
updateIndexSetting(index, Settings.builder().put("index.number_of_replicas", 1)); | ||
ensureGreen(); | ||
assertOK(client().performRequest("POST", index + "/_refresh")); | ||
// the number of documents on the primary and on the recovered replica should match the number of indexed documents | ||
assertCount(index, "_primary", numDocs); | ||
assertCount(index, "_replica", numDocs); | ||
assertSeqNoOnShards(nodes, checkGlobalCheckpoints, numDocsOnNewPrimary, newNodeClient); | ||
} | ||
} | ||
|
||
private void assertCount(final String index, final String preference, final int expectedCount) throws IOException { | ||
final Response response = client().performRequest("GET", index + "/_count", Collections.singletonMap("preference", preference)); | ||
assertOK(response); | ||
final InputStream content = response.getEntity().getContent(); | ||
final int actualCount = | ||
Integer.parseInt(XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false).get("count").toString()); | ||
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. Any chance to use something like ObjectPath.evaluate(shard, "seq_no.local_checkpoint")? 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. I pushed 4430caa. |
||
assertThat(actualCount, equalTo(expectedCount)); | ||
} | ||
|
||
private void assertSeqNoOnShards(Nodes nodes, boolean checkGlobalCheckpoints, int numDocs, RestClient client) throws Exception { | ||
assertBusy(() -> { | ||
try { | ||
|
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.
shall we add assert counts here too?
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 pushed 0112f90.