Skip to content

Commit 968b0b1

Browse files
authored
Add soft-deletes upgrade tests (#36286)
This change adds a rolling-upgrade and full-cluster-restart test with soft-deletes enabled.
1 parent 10feb75 commit 968b0b1

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

+50
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,56 @@ public void testHistoryUUIDIsAdded() throws Exception {
953953
}
954954
}
955955

956+
public void testSoftDeletes() throws Exception {
957+
if (isRunningAgainstOldCluster()) {
958+
XContentBuilder mappingsAndSettings = jsonBuilder();
959+
mappingsAndSettings.startObject();
960+
{
961+
mappingsAndSettings.startObject("settings");
962+
mappingsAndSettings.field("number_of_shards", 1);
963+
mappingsAndSettings.field("number_of_replicas", 1);
964+
if (getOldClusterVersion().onOrAfter(Version.V_6_5_0)) {
965+
mappingsAndSettings.field("soft_deletes.enabled", true);
966+
}
967+
mappingsAndSettings.endObject();
968+
}
969+
mappingsAndSettings.endObject();
970+
Request createIndex = new Request("PUT", "/" + index);
971+
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
972+
client().performRequest(createIndex);
973+
int numDocs = between(10, 100);
974+
for (int i = 0; i < numDocs; i++) {
975+
String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v1").endObject());
976+
Request request = new Request("POST", "/" + index + "/doc/" + i);
977+
request.setJsonEntity(doc);
978+
client().performRequest(request);
979+
if (rarely()) {
980+
refresh();
981+
}
982+
}
983+
client().performRequest(new Request("POST", "/" + index + "/_flush"));
984+
int liveDocs = numDocs;
985+
assertTotalHits(liveDocs, entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search"))));
986+
for (int i = 0; i < numDocs; i++) {
987+
if (randomBoolean()) {
988+
String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v2").endObject());
989+
Request request = new Request("POST", "/" + index + "/doc/" + i);
990+
request.setJsonEntity(doc);
991+
client().performRequest(request);
992+
} else if (randomBoolean()) {
993+
client().performRequest(new Request("DELETE", "/" + index + "/doc/" + i));
994+
liveDocs--;
995+
}
996+
}
997+
refresh();
998+
assertTotalHits(liveDocs, entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search"))));
999+
saveInfoDocument("doc_count", Integer.toString(liveDocs));
1000+
} else {
1001+
int liveDocs = Integer.parseInt(loadInfoDocument("doc_count"));
1002+
assertTotalHits(liveDocs, entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search"))));
1003+
}
1004+
}
1005+
9561006
private void checkSnapshot(String snapshotName, int count, Version tookOnVersion) throws IOException {
9571007
// Check the snapshot metadata, especially the version
9581008
Request listSnapshotRequest = new Request("GET", "/_snapshot/repo/" + snapshotName);

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.cluster.metadata.IndexMetaData;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
29+
import org.elasticsearch.index.IndexSettings;
2930
import org.elasticsearch.test.rest.yaml.ObjectPath;
3031

3132
import java.io.IOException;
@@ -272,4 +273,35 @@ public void testRecoverSyncedFlushIndex() throws Exception {
272273
ensureGreen(index);
273274
}
274275

276+
public void testRecoveryWithSoftDeletes() throws Exception {
277+
final String index = "recover_with_soft_deletes";
278+
if (CLUSTER_TYPE == ClusterType.OLD) {
279+
Settings.Builder settings = Settings.builder()
280+
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
281+
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
282+
// if the node with the replica is the first to be restarted, while a replica is still recovering
283+
// then delayed allocation will kick in. When the node comes back, the master will search for a copy
284+
// but the recovering copy will be seen as invalid and the cluster health won't return to GREEN
285+
// before timing out
286+
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
287+
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
288+
if (getNodeId(v -> v.onOrAfter(Version.V_6_5_0)) != null) {
289+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
290+
}
291+
createIndex(index, settings.build());
292+
int numDocs = randomInt(10);
293+
indexDocs(index, 0, numDocs);
294+
if (randomBoolean()) {
295+
client().performRequest(new Request("POST", "/" + index + "/_flush"));
296+
}
297+
for (int i = 0; i < numDocs; i++) {
298+
if (randomBoolean()) {
299+
indexDocs(index, i, 1); // update
300+
} else if (randomBoolean()) {
301+
client().performRequest(new Request("DELETE", index + "/test/" + i));
302+
}
303+
}
304+
}
305+
ensureGreen(index);
306+
}
275307
}

0 commit comments

Comments
 (0)