-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
[CCR] Add create and follow api #30602
Changes from 7 commits
9bb2413
d79989a
cdb1062
9ca0376
491b1a9
48d2fc8
531889a
139977e
6ef4681
c1f8106
1687020
27da0e3
ab53fcf
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 |
---|---|---|
|
@@ -111,6 +111,53 @@ public void testFollowIndex() throws Exception { | |
} | ||
} | ||
|
||
public void testCreateAndFollowIndex() throws Exception { | ||
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 do think that two separate tests would be better. One that tests against an index with appropriate permissions, and one that tests against an index without appropriate permissions. Most of the code can be shared between the two methods, it is only about what is asserted at the end that needs to change. 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. Agreed, I'm going to change this. |
||
final int numDocs = 16; | ||
final String indexName1 = "index3"; | ||
final String indexName2 = "index4"; | ||
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. See my comment above about the index names; this is especially onerous with the variable names not being lined up with the concrete index names (e.g., |
||
if (runningAgainstLeaderCluster) { | ||
logger.info("Running against leader cluster"); | ||
Settings indexSettings = Settings.builder() | ||
.put("index.soft_deletes.enabled", true) | ||
.build(); | ||
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 think this will all fit onto one line. |
||
createIndex(indexName1, indexSettings); | ||
createIndex(indexName2, indexSettings); | ||
for (int i = 0; i < numDocs; i++) { | ||
logger.info("Indexing doc [{}]", i); | ||
index(indexName1, Integer.toString(i), "field", i); | ||
} | ||
for (int i = 0; i < numDocs; i++) { | ||
logger.info("Indexing doc [{}]", i); | ||
index(indexName2, Integer.toString(i), "field", i); | ||
} | ||
refresh(indexName1); | ||
verifyDocuments(adminClient(), indexName1, numDocs); | ||
} else { | ||
logger.info("Running against follow cluster"); | ||
Settings indexSettings = Settings.builder() | ||
.put("index.xpack.ccr.following_index", true) | ||
.build(); | ||
createAndFollowIndex("leader_cluster:" + indexName1, indexName1); | ||
assertBusy(() -> verifyDocuments(client(), indexName1, numDocs)); | ||
assertThat(countCcrNodeTasks(), equalTo(1)); | ||
assertOK(client().performRequest("POST", "/" + indexName1 + "/_xpack/ccr/_unfollow")); | ||
// Make sure that there are no other ccr relates operations running: | ||
assertBusy(() -> { | ||
Map<String, Object> clusterState = toMap(adminClient().performRequest("GET", "/_cluster/state")); | ||
List<?> tasks = (List<?>) XContentMapValues.extractValue("metadata.persistent_tasks.tasks", clusterState); | ||
assertThat(tasks.size(), equalTo(0)); | ||
assertThat(countCcrNodeTasks(), equalTo(0)); | ||
}); | ||
|
||
createAndFollowIndex("leader_cluster:" + indexName2, indexName2); | ||
// Verify that nothing has been replicated and no node tasks are running | ||
// These node tasks should have been failed due to the fact that the user | ||
// has no sufficient priviledges. | ||
assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0))); | ||
verifyDocuments(adminClient(), indexName2, 0); | ||
} | ||
} | ||
|
||
private int countCcrNodeTasks() throws IOException { | ||
Map<String, Object> rsp1 = toMap(adminClient().performRequest("GET", "/_tasks", | ||
Collections.singletonMap("detailed", "true"))); | ||
|
@@ -148,6 +195,11 @@ private static void followIndex(String leaderIndex, String followIndex) throws I | |
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_follow", params)); | ||
} | ||
|
||
private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException { | ||
Map<String, String> params = Collections.singletonMap("leader_index", leaderIndex); | ||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow", params)); | ||
} | ||
|
||
void verifyDocuments(RestClient client, String index, int expectedNumDocs) throws IOException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("size", Integer.toString(expectedNumDocs)); | ||
|
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 more meaningful names are in order here? When I look at this and look at
FollowIndexSecurityIT
it takes some mental energy to keep track of what and whereindex[1234]
are.