Skip to content

Commit b813a4a

Browse files
committed
Add soft-deletes upgrade tests (#36286)
This change adds a rolling-upgrade and full-cluster-restart test with
1 parent 7dd6e58 commit b813a4a

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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;
@@ -316,4 +317,36 @@ public void testRecoverSyncedFlushIndex() throws Exception {
316317
}
317318
ensureGreen(index);
318319
}
320+
321+
public void testRecoveryWithSoftDeletes() throws Exception {
322+
final String index = "recover_with_soft_deletes";
323+
if (CLUSTER_TYPE == ClusterType.OLD) {
324+
Settings.Builder settings = Settings.builder()
325+
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
326+
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
327+
// if the node with the replica is the first to be restarted, while a replica is still recovering
328+
// then delayed allocation will kick in. When the node comes back, the master will search for a copy
329+
// but the recovering copy will be seen as invalid and the cluster health won't return to GREEN
330+
// before timing out
331+
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
332+
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
333+
if (getNodeId(v -> v.onOrAfter(Version.V_6_5_0)) != null) {
334+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
335+
}
336+
createIndex(index, settings.build());
337+
int numDocs = randomInt(10);
338+
indexDocs(index, 0, numDocs);
339+
if (randomBoolean()) {
340+
client().performRequest(new Request("POST", "/" + index + "/_flush"));
341+
}
342+
for (int i = 0; i < numDocs; i++) {
343+
if (randomBoolean()) {
344+
indexDocs(index, i, 1); // update
345+
} else if (randomBoolean()) {
346+
client().performRequest(new Request("DELETE", index + "/test/" + i));
347+
}
348+
}
349+
}
350+
ensureGreen(index);
351+
}
319352
}

0 commit comments

Comments
 (0)