Skip to content

Commit b75918f

Browse files
Binary doc values have stale value offset array if block contains all empty values (elastic#139922)
If all values are empty, the offsets array isn't decoded. This causes the offsets already present in the offsets array to be used. Instead need to either clear the offset array or read the compressed offsets (which are all 0s.) As follow-up, we should not send the empty offsets at all; but this will require codec version change.
1 parent a45979d commit b75918f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

docs/changelog/139922.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 139922
2+
summary: Binary doc values have stale value offset array if block contains all empty
3+
values
4+
area: Codec
5+
type: bug
6+
issues: []

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.elasticsearch.index.mapper.blockloader.docvalues.CustomBinaryDocValuesReader;
5656

5757
import java.io.IOException;
58+
import java.util.Arrays;
5859

5960
import static org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat.SKIP_INDEX_JUMP_LENGTH_PER_LEVEL;
6061
import static org.elasticsearch.index.codec.tsdb.es819.ES819TSDBDocValuesFormat.SKIP_INDEX_MAX_LEVEL;
@@ -537,6 +538,7 @@ private void decompressBlock(long blockId, int numDocsInBlock) throws IOExceptio
537538
int uncompressedBlockLength = compressedData.readVInt();
538539

539540
if (uncompressedBlockLength == 0) {
541+
Arrays.fill(uncompressedDocStarts, 0);
540542
return;
541543
}
542544

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ public void testBlockWiseBinarySmallValues() throws Exception {
173173
assertBinaryValues(binaryValues);
174174
}
175175

176+
public void testBlockWiseBinaryWithEmptySequences() throws Exception {
177+
// Test long sequences that either have values or are all empty
178+
List<String> binaryValues = new ArrayList<>();
179+
int numSequences = 10;
180+
for (int i = 0; i < numSequences; i++) {
181+
int numInSequence = randomIntBetween(0, 3 * BLOCK_COUNT_THRESHOLD);
182+
boolean emptySequence = randomBoolean();
183+
for (int j = 0; j < numInSequence; j++) {
184+
binaryValues.add(emptySequence ? "" : randomAlphaOfLengthBetween(0, 5));
185+
}
186+
}
187+
assertBinaryValues(binaryValues);
188+
}
189+
176190
public void testBlockWiseBinaryLargeValues() throws Exception {
177191
boolean sparse = randomBoolean();
178192
int numBlocksBound = 5;

0 commit comments

Comments
 (0)