Skip to content

Commit 490a2d5

Browse files
Copy ES819TSDBDocValuesConsumer into tests for version 0 bwc tests (#137404)
In #137139, ES819DocValuesFormat version will increment from 0 to 1. For bwc tests between version 0 and version 1, we need a copy of version 0. So copy the existing ES819TSDBDocValuesConsumer to ES819TSDBDocValuesConsumerVersion0 and add TestES819TSDBDocValuesFormatVersion0 which uses this consumer. Since ES819TSDBDocValuesConsumer and ES819TSDBDocValuesConsumerVersion0 are currently identical, this does not test anything yet, but will once #137139 increments the version.
1 parent 9473216 commit 490a2d5

File tree

4 files changed

+1073
-24
lines changed

4 files changed

+1073
-24
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static boolean getOptimizedMergeEnabledDefault() {
118118

119119
final int skipIndexIntervalSize;
120120
final int minDocsPerOrdinalForRangeEncoding;
121-
private final boolean enableOptimizedMerge;
121+
final boolean enableOptimizedMerge;
122122

123123
/** Default constructor. */
124124
public ES819TSDBDocValuesFormat() {

server/src/test/java/org/elasticsearch/index/codec/tsdb/TsdbDocValueBwcTests.java

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.Map;
5353
import java.util.function.IntSupplier;
5454

55+
import static org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests.TestES819TSDBDocValuesFormatVersion0;
5556
import static org.hamcrest.Matchers.equalTo;
5657

5758
public class TsdbDocValueBwcTests extends ESTestCase {
@@ -62,6 +63,13 @@ public void testMixedIndex() throws Exception {
6263
testMixedIndex(oldCodec, newCodec);
6364
}
6465

66+
// TODO update Current to Version1 once version is incremented
67+
public void testMixedIndexDocValueVersion0ToCurrent() throws Exception {
68+
var oldCodec = TestUtil.alwaysDocValuesFormat(new TestES819TSDBDocValuesFormatVersion0());
69+
var newCodec = TestUtil.alwaysDocValuesFormat(new ES819TSDBDocValuesFormat());
70+
testMixedIndex(oldCodec, newCodec, this::assertVersion819, this::assertVersion819);
71+
}
72+
6573
public void testMixedIndex816To900Lucene101() throws Exception {
6674
var oldCodec = new Elasticsearch816Codec() {
6775

@@ -84,8 +92,37 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
8492
testMixedIndex(oldCodec, newCodec);
8593
}
8694

95+
void assertFieldInfoDocValuesFormat(DirectoryReader reader, String expectedSuffix, String expectedFormat) throws IOException,
96+
NoSuchFieldException, IllegalAccessException {
97+
// Assert per field format field info attributes:
98+
// (XPerFieldDocValuesFormat must produce the same attributes as PerFieldDocValuesFormat for BWC.
99+
// Otherwise, doc values fields may disappear)
100+
for (var leaf : reader.leaves()) {
101+
for (var fieldInfo : leaf.reader().getFieldInfos()) {
102+
assertThat(fieldInfo.attributes(), Matchers.aMapWithSize(2));
103+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.suffix", expectedSuffix));
104+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.format", expectedFormat));
105+
}
106+
}
107+
}
108+
109+
void assertVersion87(DirectoryReader reader) throws IOException, NoSuchFieldException, IllegalAccessException {
110+
assert87DocValuesFormatVersion(reader);
111+
assertFieldInfoDocValuesFormat(reader, "0", "ES87TSDB");
112+
}
113+
114+
void assertVersion819(DirectoryReader reader) throws IOException, NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
115+
assert819DocValuesFormatVersion(reader);
116+
assertFieldInfoDocValuesFormat(reader, "0", "ES819TSDB");
117+
}
118+
87119
void testMixedIndex(Codec oldCodec, Codec newCodec) throws IOException, NoSuchFieldException, IllegalAccessException,
88120
ClassNotFoundException {
121+
testMixedIndex(oldCodec, newCodec, this::assertVersion87, this::assertVersion819);
122+
}
123+
124+
void testMixedIndex(Codec oldCodec, Codec newCodec, VersionAssert assertOldVersion, VersionAssert assertNewVersion) throws IOException,
125+
NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
89126
String timestampField = "@timestamp";
90127
String hostnameField = "host.name";
91128
long baseTimestamp = 1704067200000L;
@@ -136,17 +173,7 @@ void testMixedIndex(Codec oldCodec, Codec newCodec) throws IOException, NoSuchFi
136173
}
137174
// Check documents before force merge:
138175
try (var reader = DirectoryReader.open(dir)) {
139-
assertOldDocValuesFormatVersion(reader);
140-
// Assert per field format field info attributes:
141-
// (XPerFieldDocValuesFormat must produce the same attributes as PerFieldDocValuesFormat for BWC.
142-
// Otherwise, doc values fields may disappear)
143-
for (var leaf : reader.leaves()) {
144-
for (var fieldInfo : leaf.reader().getFieldInfos()) {
145-
assertThat(fieldInfo.attributes(), Matchers.aMapWithSize(2));
146-
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.suffix", "0"));
147-
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.format", "ES87TSDB"));
148-
}
149-
}
176+
assertOldVersion.run(reader);
150177

151178
var hostNameDV = MultiDocValues.getSortedValues(reader, hostnameField);
152179
assertNotNull(hostNameDV);
@@ -205,17 +232,9 @@ void testMixedIndex(Codec oldCodec, Codec newCodec) throws IOException, NoSuchFi
205232
try (var reader = DirectoryReader.open(iw)) {
206233
assertEquals(1, reader.leaves().size());
207234
assertEquals(numDocs, reader.maxDoc());
208-
assertNewDocValuesFormatVersion(reader);
209-
var leaf = reader.leaves().get(0).reader();
210-
// Assert per field format field info attributes:
211-
// (XPerFieldDocValuesFormat must produce the same attributes as PerFieldDocValuesFormat for BWC.
212-
// Otherwise, doc values fields may disappear)
213-
for (var fieldInfo : leaf.getFieldInfos()) {
214-
assertThat(fieldInfo.attributes(), Matchers.aMapWithSize(2));
215-
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.suffix", "0"));
216-
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.format", "ES819TSDB"));
217-
}
235+
assertNewVersion.run(reader);
218236

237+
var leaf = reader.leaves().get(0).reader();
219238
var hostNameDV = leaf.getSortedDocValues(hostnameField);
220239
assertNotNull(hostNameDV);
221240
var timestampDV = DocValues.unwrapSingleton(leaf.getSortedNumericDocValues(timestampField));
@@ -385,7 +404,7 @@ private IndexWriterConfig getTimeSeriesIndexWriterConfig(String hostnameField, S
385404

386405
// A hacky way to figure out whether doc values format is written in what version. Need to use reflection, because
387406
// PerFieldDocValuesFormat hides the doc values formats it wraps.
388-
private void assertOldDocValuesFormatVersion(DirectoryReader reader) throws NoSuchFieldException, IllegalAccessException, IOException {
407+
private void assert87DocValuesFormatVersion(DirectoryReader reader) throws NoSuchFieldException, IllegalAccessException, IOException {
389408
if (System.getSecurityManager() != null) {
390409
// With jvm version 24 entitlements are used and security manager is nog longer used.
391410
// Making this assertion work with security manager requires granting the entire test codebase privileges to use
@@ -406,7 +425,7 @@ private void assertOldDocValuesFormatVersion(DirectoryReader reader) throws NoSu
406425
}
407426
}
408427

409-
private void assertNewDocValuesFormatVersion(DirectoryReader reader) throws NoSuchFieldException, IllegalAccessException, IOException,
428+
private void assert819DocValuesFormatVersion(DirectoryReader reader) throws NoSuchFieldException, IllegalAccessException, IOException,
410429
ClassNotFoundException {
411430

412431
for (var leafReaderContext : reader.leaves()) {
@@ -451,4 +470,7 @@ private static Field getFormatsFieldFromPerFieldFieldsReader(Class<?> c) throws
451470
return field;
452471
}
453472

473+
interface VersionAssert {
474+
void run(DirectoryReader reader) throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException;
475+
}
454476
}

0 commit comments

Comments
 (0)