Skip to content

Commit 57c2f24

Browse files
committed
Fix issue with readBinary
1 parent d3760fd commit 57c2f24

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.index.codec.tsdb.es819;
1111

12+
import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
1213
import org.apache.lucene.codecs.CodecUtil;
1314
import org.apache.lucene.codecs.DocValuesProducer;
1415
import org.apache.lucene.codecs.lucene90.IndexedDISI;
@@ -337,6 +338,11 @@ private BinaryDocValues getCompressedBinary(BinaryEntry entry) throws IOExceptio
337338
public BytesRef binaryValue() throws IOException {
338339
return decoder.decode(doc);
339340
}
341+
342+
@Override
343+
public BlockLoader.Block tryRead(BlockLoader.BlockFactory factory, BlockLoader.Docs docs, int offset, boolean nullsFiltered, BlockDocValuesReader.ToDouble toDouble, boolean toInt) throws IOException {
344+
return null;
345+
}
340346
};
341347
} else {
342348
// sparse
@@ -1358,15 +1364,27 @@ private BinaryEntry readBinary(IndexInput meta, int version) throws IOException
13581364
entry.numDocsWithField = meta.readInt();
13591365
entry.minLength = meta.readInt();
13601366
entry.maxLength = meta.readInt();
1361-
if (entry.minLength < entry.maxLength) {
1362-
entry.addressesOffset = meta.readLong();
1363-
1364-
// Old count of uncompressed addresses
1365-
long numAddresses = entry.numDocsWithField + 1L;
1366-
1367-
final int blockShift = meta.readVInt();
1368-
entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, numAddresses, blockShift);
1369-
entry.addressesLength = meta.readLong();
1367+
if (compression == BinaryDVCompressionMode.NO_COMPRESS) {
1368+
if (entry.minLength < entry.maxLength) {
1369+
entry.addressesOffset = meta.readLong();
1370+
// Old count of uncompressed addresses
1371+
long numAddresses = entry.numDocsWithField + 1L;
1372+
final int blockShift = meta.readVInt();
1373+
entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, numAddresses, blockShift);
1374+
entry.addressesLength = meta.readLong();
1375+
}
1376+
} else {
1377+
if (entry.numDocsWithField > 0 || entry.minLength < entry.maxLength) {
1378+
entry.addressesOffset = meta.readLong();
1379+
// New count of compressed addresses - the number of compresseed blocks
1380+
int numCompressedChunks = meta.readVInt();
1381+
entry.docsPerChunkShift = meta.readVInt();
1382+
entry.maxUncompressedChunkSize = meta.readVInt();
1383+
1384+
final int blockShift = meta.readVInt();
1385+
entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, numCompressedChunks, blockShift);
1386+
entry.addressesLength = meta.readLong();
1387+
}
13701388
}
13711389
return entry;
13721390
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.index.codec.Elasticsearch92Lucene103Codec;
3030
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormatTests.TestES87TSDBDocValuesFormat;
3131
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat;
32+
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests;
3233
import org.elasticsearch.test.ESTestCase;
3334

3435
import java.io.IOException;
@@ -44,11 +45,6 @@ public class DocValuesCodecDuelTests extends ESTestCase {
4445
private static final String FIELD_4 = "number_field_4";
4546
private static final String FIELD_5 = "binary_field_5";
4647

47-
public static BinaryDVCompressionMode randomCompressionMode() {
48-
BinaryDVCompressionMode[] modes = BinaryDVCompressionMode.values();
49-
return modes[random().nextInt(modes.length)];
50-
}
51-
5248
@SuppressWarnings("checkstyle:LineLength")
5349
public void testDuel() throws IOException {
5450
try (var baselineDirectory = newDirectory(); var contenderDirectory = newDirectory()) {
@@ -67,7 +63,7 @@ public void testDuel() throws IOException {
6763
ESTestCase.randomIntBetween(1, 4096),
6864
ESTestCase.randomIntBetween(1, 512),
6965
random().nextBoolean(),
70-
randomCompressionMode()
66+
ES819TSDBDocValuesFormatTests.randomCompressionMode()
7167
)
7268
: new TestES87TSDBDocValuesFormat();
7369

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.index.codec.perfield.XPerFieldDocValuesFormat;
4343
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormatTests.TestES87TSDBDocValuesFormat;
4444
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat;
45+
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormatTests;
4546
import org.elasticsearch.test.ESTestCase;
4647
import org.hamcrest.Matchers;
4748

@@ -291,7 +292,8 @@ public void testEncodeOrdinalRange() throws IOException {
291292
new ES819TSDBDocValuesFormat(
292293
random().nextInt(16, 128),
293294
nextOrdinalRangeThreshold.getAsInt(),
294-
random().nextBoolean()
295+
random().nextBoolean(),
296+
ES819TSDBDocValuesFormatTests.randomCompressionMode()
295297
)
296298
)
297299
);

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormatTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.index.codec.Elasticsearch900Lucene101Codec;
4444
import org.elasticsearch.index.codec.Elasticsearch92Lucene103Codec;
4545
import org.elasticsearch.index.codec.tsdb.BinaryDVCompressionMode;
46+
import org.elasticsearch.index.codec.tsdb.DocValuesCodecDuelTests;
4647
import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormatTests;
4748
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesProducer.BaseDenseNumericValues;
4849
import org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesProducer.BaseSortedDocValues;
@@ -69,14 +70,18 @@
6970

7071
public class ES819TSDBDocValuesFormatTests extends ES87TSDBDocValuesFormatTests {
7172

73+
public static BinaryDVCompressionMode randomCompressionMode() {
74+
BinaryDVCompressionMode[] modes = BinaryDVCompressionMode.values();
75+
return modes[random().nextInt(modes.length)];
76+
}
77+
7278
private final Codec codec = new Elasticsearch92Lucene103Codec() {
7379

74-
BinaryDVCompressionMode[] modes = BinaryDVCompressionMode.values();
7580
final ES819TSDBDocValuesFormat docValuesFormat = new ES819TSDBDocValuesFormat(
7681
ESTestCase.randomIntBetween(2, 4096),
7782
ESTestCase.randomIntBetween(1, 512),
7883
random().nextBoolean(),
79-
modes[random().nextInt(modes.length)]
84+
randomCompressionMode()
8085
);
8186

8287
@Override

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormatVariableSkipIntervalTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public class ES819TSDBDocValuesFormatVariableSkipIntervalTests extends ES87TSDBD
1919
protected Codec getCodec() {
2020
// small interval size to test with many intervals
2121
return TestUtil.alwaysDocValuesFormat(
22-
new ES819TSDBDocValuesFormat(random().nextInt(4, 16), random().nextInt(1, 32), random().nextBoolean())
22+
new ES819TSDBDocValuesFormat(random().nextInt(4, 16), random().nextInt(1, 32), random().nextBoolean(), ES819TSDBDocValuesFormatTests.randomCompressionMode())
2323
);
2424
}
2525

2626
public void testSkipIndexIntervalSize() {
2727
IllegalArgumentException ex = expectThrows(
2828
IllegalArgumentException.class,
29-
() -> new ES819TSDBDocValuesFormat(random().nextInt(Integer.MIN_VALUE, 2), random().nextInt(1, 32), random().nextBoolean())
29+
() -> new ES819TSDBDocValuesFormat(random().nextInt(Integer.MIN_VALUE, 2), random().nextInt(1, 32), random().nextBoolean(), ES819TSDBDocValuesFormatTests.randomCompressionMode())
3030
);
3131
assertTrue(ex.getMessage().contains("skipIndexIntervalSize must be > 1"));
3232
}

0 commit comments

Comments
 (0)