Skip to content

Commit d0b74df

Browse files
authored
Handle properly when trying to serialize a zero documents cluster in IVF (#129559)
We currently fail to serialize this case. This change has been made so it is backwards compatible. I label it as non an issue as this feature is behind a feature flag and is not released. fixes #129551
1 parent 505824d commit d0b74df

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/DocIdsWriter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ final class DocIdsWriter {
7070
DocIdsWriter() {}
7171

7272
void writeDocIds(IntToIntFunction docIds, int count, DataOutput out) throws IOException {
73-
// docs can be sorted either when all docs in a block have the same value
74-
// or when a segment is sorted
7573
if (count == 0) {
76-
out.writeByte(CONTINUOUS_IDS);
7774
return;
7875
}
7976
if (count > scratch.length) {
8077
scratch = new int[count];
8178
}
79+
// docs can be sorted either when all docs in a block have the same value
80+
// or when a segment is sorted
8281
boolean strictlySorted = true;
8382
int min = docIds.apply(0);
8483
int max = min;
@@ -215,6 +214,9 @@ private static void writeIdsAsBitSet(IntToIntFunction docIds, int count, DataOut
215214

216215
/** Read {@code count} integers into {@code docIDs}. */
217216
void readInts(IndexInput in, int count, int[] docIDs) throws IOException {
217+
if (count == 0) {
218+
return;
219+
}
218220
if (count > scratch.length) {
219221
scratch = new int[count];
220222
}

server/src/test/java/org/elasticsearch/index/codec/vectors/DocIdsWriterTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040

4141
public class DocIdsWriterTests extends LuceneTestCase {
4242

43+
public void testNoDocs() throws Exception {
44+
try (Directory dir = newDirectory()) {
45+
test(dir, new int[0]);
46+
}
47+
}
48+
4349
public void testRandom() throws Exception {
4450
int numIters = atLeast(100);
4551
try (Directory dir = newDirectory()) {

0 commit comments

Comments
 (0)