Skip to content

Improve DocValuesConsumerUtil#compatibleWithOptimizedMerge(...) #126894

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

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me

if (docValuesProducer instanceof XPerFieldDocValuesFormat.FieldsReader perFieldReader) {
var wrapped = perFieldReader.getDocValuesProducer(fieldInfo);
if (wrapped == null) {
continue;
}

if (wrapped instanceof ES819TSDBDocValuesProducer tsdbDocValuesProducer) {
switch (fieldInfo.getDocValuesType()) {
case NUMERIC -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,88 @@ public void testForceMergeDenseCase() throws Exception {
}
}

public void testTwoSegmentsTwoDifferentFields() throws Exception {
String timestampField = "@timestamp";
String hostnameField = "host.name";
long timestamp = 1704067200000L;

var config = getTimeSeriesIndexWriterConfig(hostnameField, timestampField);
try (var dir = newDirectory(); var iw = new IndexWriter(dir, config)) {
long counter1 = 0;
long counter2 = 10_000_000;

{
var d = new Document();
d.add(new SortedDocValuesField(hostnameField, new BytesRef("host-001")));
d.add(new SortedNumericDocValuesField(timestampField, timestamp - 1));
d.add(new NumericDocValuesField("counter_1", counter1));
d.add(new SortedNumericDocValuesField("gauge_1", 2));
iw.addDocument(d);
iw.commit();
}
{
var d = new Document();
d.add(new SortedDocValuesField(hostnameField, new BytesRef("host-001")));
d.add(new SortedNumericDocValuesField(timestampField, timestamp));
d.add(new SortedNumericDocValuesField("counter_2", counter2));
d.add(new SortedNumericDocValuesField("gauge_2", -2));
iw.addDocument(d);
iw.commit();
}

iw.forceMerge(1);

try (var reader = DirectoryReader.open(iw)) {
assertEquals(1, reader.leaves().size());
assertEquals(2, reader.maxDoc());
var leaf = reader.leaves().get(0).reader();
var hostNameDV = leaf.getSortedDocValues(hostnameField);
assertNotNull(hostNameDV);
var timestampDV = DocValues.unwrapSingleton(leaf.getSortedNumericDocValues(timestampField));
assertNotNull(timestampDV);
var counterOneDV = leaf.getNumericDocValues("counter_1");
assertNotNull(counterOneDV);
var counterTwoDV = leaf.getSortedNumericDocValues("counter_2");
assertNotNull(counterTwoDV);
var gaugeOneDV = leaf.getSortedNumericDocValues("gauge_1");
assertNotNull(gaugeOneDV);
var gaugeTwoDV = leaf.getSortedNumericDocValues("gauge_2");
assertNotNull(gaugeTwoDV);
for (int i = 0; i < 2; i++) {
assertEquals(i, hostNameDV.nextDoc());
assertEquals("host-001", hostNameDV.lookupOrd(hostNameDV.ordValue()).utf8ToString());

assertEquals(i, timestampDV.nextDoc());
long actualTimestamp = timestampDV.longValue();
assertTrue(actualTimestamp == timestamp || actualTimestamp == timestamp - 1);

if (counterOneDV.advanceExact(i)) {
long counterOneValue = counterOneDV.longValue();
assertEquals(counter1, counterOneValue);
}

if (counterTwoDV.advanceExact(i)) {
assertEquals(1, counterTwoDV.docValueCount());
long counterTwoValue = counterTwoDV.nextValue();
assertEquals(counter2, counterTwoValue);
}

if (gaugeOneDV.advanceExact(i)) {
assertEquals(1, gaugeOneDV.docValueCount());
long gaugeOneValue = gaugeOneDV.nextValue();
assertEquals(2, gaugeOneValue);
}

if (gaugeTwoDV.advanceExact(i)) {
assertEquals(1, gaugeTwoDV.docValueCount());
long gaugeTwoValue = gaugeTwoDV.nextValue();
assertEquals(-2, gaugeTwoValue);
}
}
}
}
}

public void testForceMergeSparseCase() throws Exception {
String timestampField = "@timestamp";
String hostnameField = "host.name";
Expand Down