Skip to content

Commit 8eec52b

Browse files
martijnvgcbuescher
authored andcommitted
Fix TSDBIndexingIT#testTrimId() test failure. (elastic#112194)
Sometimes initial indexing results into exactly one segment. However, multiple segments are needed to perform the force merge that purges stored fields for _id field in a later stage of the test. This change tweaks the test such that an extra update is performed after initial indexing. This should always create an extra segment, so that this test can actual purge stored fields for _id field. Closes elastic#112124
1 parent 799938b commit 8eec52b

File tree

1 file changed

+13
-1
lines changed
  • modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams

1 file changed

+13
-1
lines changed

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/TSDBIndexingIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.get.GetRequest;
2323
import org.elasticsearch.action.index.IndexRequest;
2424
import org.elasticsearch.action.search.SearchRequest;
25+
import org.elasticsearch.action.support.WriteRequest;
2526
import org.elasticsearch.cluster.metadata.ComponentTemplate;
2627
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
2728
import org.elasticsearch.cluster.metadata.Template;
@@ -35,6 +36,7 @@
3536
import org.elasticsearch.index.query.RangeQueryBuilder;
3637
import org.elasticsearch.indices.InvalidIndexTemplateException;
3738
import org.elasticsearch.plugins.Plugin;
39+
import org.elasticsearch.rest.RestStatus;
3840
import org.elasticsearch.search.builder.SearchSourceBuilder;
3941
import org.elasticsearch.test.ESSingleNodeTestCase;
4042
import org.elasticsearch.test.InternalSettingsPlugin;
@@ -457,6 +459,16 @@ public void testTrimId() throws Exception {
457459
indexName = bulkResponse.getItems()[0].getIndex();
458460
}
459461
client().admin().indices().refresh(new RefreshRequest(dataStreamName)).actionGet();
462+
463+
// In rare cases we can end up with a single segment shard, which means we can't trim away the _id later.
464+
// So update an existing doc to create a new segment without adding a new document after force merging:
465+
var indexRequest = new IndexRequest(indexName).setIfPrimaryTerm(1L)
466+
.setIfSeqNo((numBulkRequests * numDocsPerBulk) - 1)
467+
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
468+
indexRequest.source(DOC.replace("$time", formatInstant(time.minusMillis(1))), XContentType.JSON);
469+
var res = client().index(indexRequest).actionGet();
470+
assertThat(res.status(), equalTo(RestStatus.OK));
471+
assertThat(res.getVersion(), equalTo(2L));
460472
}
461473

462474
// Check whether there are multiple segments:
@@ -494,7 +506,7 @@ public void testTrimId() throws Exception {
494506
assertThat(retentionLeasesStats.retentionLeases().leases(), hasSize(1));
495507
assertThat(
496508
retentionLeasesStats.retentionLeases().leases().iterator().next().retainingSequenceNumber(),
497-
equalTo((long) numBulkRequests * numDocsPerBulk)
509+
equalTo((long) numBulkRequests * numDocsPerBulk + 1)
498510
);
499511
});
500512

0 commit comments

Comments
 (0)