Skip to content

Commit 69ae6dd

Browse files
committed
Migrate muted auto follow rolling upgrade test and unmute this test (#38900)
The rest of `CCRIT` is now no longer relevant, because the remaining test tests the same of the index following test in the rolling upgrade multi cluster module. Added `tests.upgrade_from_version` version to test. It is not needed in this branch, but is in 6.7 branch. Closes #37231
1 parent 23790af commit 69ae6dd

File tree

4 files changed

+166
-288
lines changed

4 files changed

+166
-288
lines changed

x-pack/qa/rolling-upgrade-multi-cluster/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ for (Version version : bwcVersions.wireCompatible) {
4141

4242
Task leaderClusterTestRunner = tasks.getByName("${taskPrefix}#leader#clusterTestRunner")
4343
leaderClusterTestRunner.configure {
44+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
4445
systemProperty 'tests.rest.upgrade_state', 'none'
4546
systemProperty 'tests.rest.cluster_name', 'leader'
4647

@@ -71,6 +72,7 @@ for (Version version : bwcVersions.wireCompatible) {
7172

7273
Task followerClusterTestRunner = tasks.getByName("${taskPrefix}#follower#clusterTestRunner")
7374
followerClusterTestRunner.configure {
75+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
7476
systemProperty 'tests.rest.upgrade_state', 'none'
7577
systemProperty 'tests.rest.cluster_name', 'follower'
7678

@@ -115,6 +117,7 @@ for (Version version : bwcVersions.wireCompatible) {
115117

116118
Task followerOneThirdUpgradedTestRunner = tasks.getByName("${taskPrefix}#follower#oneThirdUpgradedTestRunner")
117119
followerOneThirdUpgradedTestRunner.configure {
120+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
118121
systemProperty 'tests.rest.upgrade_state', 'one_third'
119122
systemProperty 'tests.rest.cluster_name', 'follower'
120123

@@ -135,6 +138,7 @@ for (Version version : bwcVersions.wireCompatible) {
135138

136139
Task followerTwoThirdsUpgradedTestRunner = tasks.getByName("${taskPrefix}#follower#twoThirdsUpgradedTestRunner")
137140
followerTwoThirdsUpgradedTestRunner.configure {
141+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
138142
systemProperty 'tests.rest.upgrade_state', 'two_third'
139143
systemProperty 'tests.rest.cluster_name', 'follower'
140144

@@ -155,6 +159,7 @@ for (Version version : bwcVersions.wireCompatible) {
155159

156160
Task followerUpgradedClusterTestRunner = tasks.getByName("${taskPrefix}#follower#upgradedClusterTestRunner")
157161
followerUpgradedClusterTestRunner.configure {
162+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
158163
systemProperty 'tests.rest.upgrade_state', 'all'
159164
systemProperty 'tests.rest.cluster_name', 'follower'
160165

@@ -181,6 +186,7 @@ for (Version version : bwcVersions.wireCompatible) {
181186

182187
Task leaderOneThirdUpgradedTestRunner = tasks.getByName("${taskPrefix}#leader#oneThirdUpgradedTestRunner")
183188
leaderOneThirdUpgradedTestRunner.configure {
189+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
184190
systemProperty 'tests.rest.upgrade_state', 'one_third'
185191
systemProperty 'tests.rest.cluster_name', 'leader'
186192

@@ -201,6 +207,7 @@ for (Version version : bwcVersions.wireCompatible) {
201207

202208
Task leaderTwoThirdsUpgradedTestRunner = tasks.getByName("${taskPrefix}#leader#twoThirdsUpgradedTestRunner")
203209
leaderTwoThirdsUpgradedTestRunner.configure {
210+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
204211
systemProperty 'tests.rest.upgrade_state', 'two_third'
205212
systemProperty 'tests.rest.cluster_name', 'leader'
206213

@@ -221,6 +228,7 @@ for (Version version : bwcVersions.wireCompatible) {
221228

222229
Task leaderUpgradedClusterTestRunner = tasks.getByName("${taskPrefix}#leader#upgradedClusterTestRunner")
223230
leaderUpgradedClusterTestRunner.configure {
231+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
224232
systemProperty 'tests.rest.upgrade_state', 'all'
225233
systemProperty 'tests.rest.cluster_name', 'leader'
226234

x-pack/qa/rolling-upgrade-multi-cluster/src/test/java/org/elasticsearch/upgrades/AbstractMultiClusterUpgradeTestCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.apache.http.HttpHost;
99
import org.apache.http.util.EntityUtils;
10+
import org.elasticsearch.Version;
1011
import org.elasticsearch.client.Request;
1112
import org.elasticsearch.client.Response;
1213
import org.elasticsearch.client.RestClient;
@@ -71,6 +72,9 @@ public static ClusterName parse(String value) {
7172

7273
protected final ClusterName clusterName = ClusterName.parse(System.getProperty("tests.rest.cluster_name"));
7374

75+
protected static final Version UPGRADE_FROM_VERSION =
76+
Version.fromString(System.getProperty("tests.upgrade_from_version"));
77+
7478
private static RestClient leaderClient;
7579
private static RestClient followerClient;
7680
private static boolean initialized = false;

x-pack/qa/rolling-upgrade-multi-cluster/src/test/java/org/elasticsearch/upgrades/CcrRollingUpgradeIT.java

Lines changed: 154 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66
package org.elasticsearch.upgrades;
77

8+
import org.elasticsearch.Version;
89
import org.elasticsearch.client.Request;
910
import org.elasticsearch.client.ResponseException;
1011
import org.elasticsearch.client.RestClient;
1112
import org.elasticsearch.common.Strings;
1213
import org.elasticsearch.common.settings.Settings;
14+
import org.elasticsearch.common.xcontent.ObjectPath;
1315
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1416

1517
import java.io.IOException;
@@ -88,6 +90,123 @@ public void testIndexFollowing() throws Exception {
8890
}
8991
}
9092

93+
public void testAutoFollowing() throws Exception {
94+
String leaderIndex1 = "logs-20200101";
95+
String leaderIndex2 = "logs-20200102";
96+
String leaderIndex3 = "logs-20200103";
97+
98+
if (clusterName == ClusterName.LEADER) {
99+
switch (upgradeState) {
100+
case NONE:
101+
case ONE_THIRD:
102+
case TWO_THIRD:
103+
break;
104+
case ALL:
105+
index(leaderClient(), leaderIndex1, 64);
106+
assertBusy(() -> {
107+
String followerIndex = "copy-" + leaderIndex1;
108+
assertTotalHitCount(followerIndex, 320, followerClient());
109+
});
110+
index(leaderClient(), leaderIndex2, 64);
111+
assertBusy(() -> {
112+
String followerIndex = "copy-" + leaderIndex2;
113+
assertTotalHitCount(followerIndex, 256, followerClient());
114+
});
115+
index(leaderClient(), leaderIndex3, 64);
116+
assertBusy(() -> {
117+
String followerIndex = "copy-" + leaderIndex3;
118+
assertTotalHitCount(followerIndex, 192, followerClient());
119+
});
120+
121+
deleteAutoFollowPattern(followerClient(), "test_pattern");
122+
stopIndexFollowing(followerClient(), "copy-" + leaderIndex1);
123+
stopIndexFollowing(followerClient(), "copy-" + leaderIndex2);
124+
stopIndexFollowing(followerClient(), "copy-" + leaderIndex3);
125+
break;
126+
default:
127+
throw new AssertionError("unexpected upgrade_state [" + upgradeState + "]");
128+
}
129+
} else if (clusterName == ClusterName.FOLLOWER) {
130+
switch (upgradeState) {
131+
case NONE:
132+
putAutoFollowPattern(followerClient(), "test_pattern", "leader", "logs-*");
133+
createLeaderIndex(leaderClient(), leaderIndex1);
134+
index(leaderClient(), leaderIndex1, 64);
135+
assertBusy(() -> {
136+
String followerIndex = "copy-" + leaderIndex1;
137+
assertThat(getNumberOfSuccessfulFollowedIndices(), equalTo(1));
138+
assertTotalHitCount(followerIndex, 64, followerClient());
139+
});
140+
break;
141+
case ONE_THIRD:
142+
index(leaderClient(), leaderIndex1, 64);
143+
assertBusy(() -> {
144+
String followerIndex = "copy-" + leaderIndex1;
145+
assertTotalHitCount(followerIndex, 128, followerClient());
146+
});
147+
// Auto follow stats are kept in-memory on master elected node
148+
// and if this node get updated then auto follow stats are reset
149+
{
150+
int previousNumberOfSuccessfulFollowedIndices = getNumberOfSuccessfulFollowedIndices();
151+
createLeaderIndex(leaderClient(), leaderIndex2);
152+
index(leaderClient(), leaderIndex2, 64);
153+
assertBusy(() -> {
154+
String followerIndex = "copy-" + leaderIndex2;
155+
assertThat(getNumberOfSuccessfulFollowedIndices(), equalTo(previousNumberOfSuccessfulFollowedIndices + 1));
156+
assertTotalHitCount(followerIndex, 64, followerClient());
157+
});
158+
}
159+
break;
160+
case TWO_THIRD:
161+
index(leaderClient(), leaderIndex1, 64);
162+
assertBusy(() -> {
163+
String followerIndex = "copy-" + leaderIndex1;
164+
assertTotalHitCount(followerIndex, 192, followerClient());
165+
});
166+
index(leaderClient(), leaderIndex2, 64);
167+
assertBusy(() -> {
168+
String followerIndex = "copy-" + leaderIndex2;
169+
assertTotalHitCount(followerIndex, 128, followerClient());
170+
});
171+
172+
// Auto follow stats are kept in-memory on master elected node
173+
// and if this node get updated then auto follow stats are reset
174+
{
175+
int previousNumberOfSuccessfulFollowedIndices = getNumberOfSuccessfulFollowedIndices();
176+
createLeaderIndex(leaderClient(), leaderIndex3);
177+
index(leaderClient(), leaderIndex3, 64);
178+
assertBusy(() -> {
179+
String followerIndex = "copy-" + leaderIndex3;
180+
assertThat(getNumberOfSuccessfulFollowedIndices(), equalTo(previousNumberOfSuccessfulFollowedIndices + 1));
181+
assertTotalHitCount(followerIndex, 64, followerClient());
182+
});
183+
}
184+
break;
185+
case ALL:
186+
index(leaderClient(), leaderIndex1, 64);
187+
assertBusy(() -> {
188+
String followerIndex = "copy-" + leaderIndex1;
189+
assertTotalHitCount(followerIndex, 256, followerClient());
190+
});
191+
index(leaderClient(), leaderIndex2, 64);
192+
assertBusy(() -> {
193+
String followerIndex = "copy-" + leaderIndex2;
194+
assertTotalHitCount(followerIndex, 192, followerClient());
195+
});
196+
index(leaderClient(), leaderIndex3, 64);
197+
assertBusy(() -> {
198+
String followerIndex = "copy-" + leaderIndex3;
199+
assertTotalHitCount(followerIndex, 128, followerClient());
200+
});
201+
break;
202+
default:
203+
throw new UnsupportedOperationException("unexpected upgrade state [" + upgradeState + "]");
204+
}
205+
} else {
206+
throw new AssertionError("unexpected cluster_name [" + clusterName + "]");
207+
}
208+
}
209+
91210
public void testCannotFollowLeaderInUpgradedCluster() throws Exception {
92211
assumeTrue("Tests only runs with upgrade_state [all]", upgradeState == UpgradeState.ALL);
93212

@@ -113,12 +232,13 @@ public void testCannotFollowLeaderInUpgradedCluster() throws Exception {
113232
}
114233

115234
private static void createLeaderIndex(RestClient client, String indexName) throws IOException {
116-
Settings indexSettings = Settings.builder()
117-
.put("index.soft_deletes.enabled", true)
235+
Settings.Builder indexSettings = Settings.builder()
118236
.put("index.number_of_shards", 1)
119-
.put("index.number_of_replicas", 0)
120-
.build();
121-
createIndex(client, indexName, indexSettings);
237+
.put("index.number_of_replicas", 0);
238+
if (UPGRADE_FROM_VERSION.before(Version.V_7_0_0) || randomBoolean()) {
239+
indexSettings.put("index.soft_deletes.enabled", true);
240+
}
241+
createIndex(client, indexName, indexSettings.build());
122242
}
123243

124244
private static void createIndex(RestClient client, String name, Settings settings) throws IOException {
@@ -134,6 +254,29 @@ private static void followIndex(RestClient client, String leaderCluster, String
134254
assertOK(client.performRequest(request));
135255
}
136256

257+
private static void putAutoFollowPattern(RestClient client, String name, String remoteCluster, String pattern) throws IOException {
258+
Request request = new Request("PUT", "/_ccr/auto_follow/" + name);
259+
request.setJsonEntity("{\"leader_index_patterns\": [\"" + pattern + "\"], \"remote_cluster\": \"" + remoteCluster + "\"," +
260+
"\"follow_index_pattern\": \"copy-{{leader_index}}\", \"read_poll_timeout\": \"10ms\"}");
261+
assertOK(client.performRequest(request));
262+
}
263+
264+
private static void deleteAutoFollowPattern(RestClient client, String patternName) throws IOException {
265+
Request request = new Request("DELETE", "/_ccr/auto_follow/" + patternName);
266+
assertOK(client.performRequest(request));
267+
}
268+
269+
private int getNumberOfSuccessfulFollowedIndices() throws IOException {
270+
Request statsRequest = new Request("GET", "/_ccr/stats");
271+
Map<?, ?> response = toMap(client().performRequest(statsRequest));
272+
Integer actualSuccessfulFollowedIndices = ObjectPath.eval("auto_follow_stats.number_of_successful_follow_indices", response);
273+
if (actualSuccessfulFollowedIndices != null) {
274+
return actualSuccessfulFollowedIndices;
275+
} else {
276+
return -1;
277+
}
278+
}
279+
137280
private static void index(RestClient client, String index, int numDocs) throws IOException {
138281
for (int i = 0; i < numDocs; i++) {
139282
final Request request = new Request("POST", "/" + index + "/_doc/");
@@ -162,4 +305,10 @@ private static void verifyTotalHitCount(final String index,
162305
assertThat(totalHits, equalTo(expectedTotalHits));
163306
}
164307

308+
private static void stopIndexFollowing(RestClient client, String followerIndex) throws IOException {
309+
assertOK(client.performRequest(new Request("POST", "/" + followerIndex + "/_ccr/pause_follow")));
310+
assertOK(client.performRequest(new Request("POST", "/" + followerIndex + "/_close")));
311+
assertOK(client.performRequest(new Request("POST", "/" + followerIndex + "/_ccr/unfollow")));
312+
}
313+
165314
}

0 commit comments

Comments
 (0)