Skip to content

Commit cb44dde

Browse files
committed
Moved docsWithFieldOffset, docsWithFieldLength, jumpTableEntryCount, denseRankPower metadata properties in the format to be after values metadata.
1 parent 705f0fb commit cb44dde

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesConsumer.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,6 @@ private long[] writeField(FieldInfo field, DocValuesProducer valuesProducer, lon
125125
numValues += count;
126126
}
127127

128-
if (numDocsWithValue == 0) { // meta[-2, 0]: No documents with values
129-
meta.writeLong(-2); // docsWithFieldOffset
130-
meta.writeLong(0L); // docsWithFieldLength
131-
meta.writeShort((short) -1); // jumpTableEntryCount
132-
meta.writeByte((byte) -1); // denseRankPower
133-
} else if (numDocsWithValue == maxDoc) { // meta[-1, 0]: All documents have values
134-
meta.writeLong(-1); // docsWithFieldOffset
135-
meta.writeLong(0L); // docsWithFieldLength
136-
meta.writeShort((short) -1); // jumpTableEntryCount
137-
meta.writeByte((byte) -1); // denseRankPower
138-
} else { // meta[data.offset, data.length]: IndexedDISI structure for documents with values
139-
long offset = data.getFilePointer();
140-
meta.writeLong(offset); // docsWithFieldOffset
141-
values = valuesProducer.getSortedNumeric(field);
142-
final short jumpTableEntryCount = IndexedDISI.writeBitSet(values, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
143-
meta.writeLong(data.getFilePointer() - offset); // docsWithFieldLength
144-
meta.writeShort(jumpTableEntryCount);
145-
meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
146-
}
147128
meta.writeLong(numValues);
148129
meta.writeInt(numDocsWithValue);
149130

@@ -207,6 +188,26 @@ private long[] writeField(FieldInfo field, DocValuesProducer valuesProducer, lon
207188
meta.writeLong(valuesDataLength);
208189
}
209190

191+
if (numDocsWithValue == 0) { // meta[-2, 0]: No documents with values
192+
meta.writeLong(-2); // docsWithFieldOffset
193+
meta.writeLong(0L); // docsWithFieldLength
194+
meta.writeShort((short) -1); // jumpTableEntryCount
195+
meta.writeByte((byte) -1); // denseRankPower
196+
} else if (numDocsWithValue == maxDoc) { // meta[-1, 0]: All documents have values
197+
meta.writeLong(-1); // docsWithFieldOffset
198+
meta.writeLong(0L); // docsWithFieldLength
199+
meta.writeShort((short) -1); // jumpTableEntryCount
200+
meta.writeByte((byte) -1); // denseRankPower
201+
} else { // meta[data.offset, data.length]: IndexedDISI structure for documents with values
202+
long offset = data.getFilePointer();
203+
meta.writeLong(offset); // docsWithFieldOffset
204+
values = valuesProducer.getSortedNumeric(field);
205+
final short jumpTableEntryCount = IndexedDISI.writeBitSet(values, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
206+
meta.writeLong(data.getFilePointer() - offset); // docsWithFieldLength
207+
meta.writeShort(jumpTableEntryCount);
208+
meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
209+
}
210+
210211
return new long[] { numDocsWithValue, numValues };
211212
}
212213

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesFormat.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public class ES87TSDBDocValuesFormat extends org.apache.lucene.codecs.DocValuesF
3333
static final byte SORTED_SET = 3;
3434
static final byte SORTED_NUMERIC = 4;
3535

36-
static final int VERSION_META_MOVE_META_ENTRY = 1;
37-
// Move numDocsWithField from SortedNumericEntry to NumericEntry
36+
// Version constants:
3837
static final int VERSION_START = 0;
39-
static final int VERSION_CURRENT = VERSION_META_MOVE_META_ENTRY;
38+
// Second versions has two changes:
39+
// 1) Moved numDocsWithField metadata statistic from SortedNumericEntry to NumericEntry and
40+
// 2) Moved docsWithFieldOffset, docsWithFieldLength, jumpTableEntryCount, denseRankPower metadata properties in the format to be after
41+
// values metadata.
42+
static final int VERSION_TWO = 1;
43+
static final int VERSION_CURRENT = VERSION_TWO;
4044

4145
static final int TERMS_DICT_BLOCK_LZ4_SHIFT = 6;
4246
static final int TERMS_DICT_BLOCK_LZ4_SIZE = 1 << TERMS_DICT_BLOCK_LZ4_SHIFT;

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesProducer.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,14 @@ private static DocValuesSkipperEntry readDocValueSkipperMeta(IndexInput meta) th
904904
}
905905

906906
private static void readNumeric(IndexInput meta, NumericEntry entry, int version) throws IOException {
907-
entry.docsWithFieldOffset = meta.readLong();
908-
entry.docsWithFieldLength = meta.readLong();
909-
entry.jumpTableEntryCount = meta.readShort();
910-
entry.denseRankPower = meta.readByte();
907+
if (version < ES87TSDBDocValuesFormat.VERSION_TWO) {
908+
entry.docsWithFieldOffset = meta.readLong();
909+
entry.docsWithFieldLength = meta.readLong();
910+
entry.jumpTableEntryCount = meta.readShort();
911+
entry.denseRankPower = meta.readByte();
912+
}
911913
entry.numValues = meta.readLong();
912-
if (version >= ES87TSDBDocValuesFormat.VERSION_META_MOVE_META_ENTRY) {
914+
if (version >= ES87TSDBDocValuesFormat.VERSION_TWO) {
913915
entry.numDocsWithField = meta.readInt();
914916
}
915917
if (entry.numValues > 0) {
@@ -928,6 +930,12 @@ private static void readNumeric(IndexInput meta, NumericEntry entry, int version
928930
entry.valuesOffset = meta.readLong();
929931
entry.valuesLength = meta.readLong();
930932
}
933+
if (version >= ES87TSDBDocValuesFormat.VERSION_TWO) {
934+
entry.docsWithFieldOffset = meta.readLong();
935+
entry.docsWithFieldLength = meta.readLong();
936+
entry.jumpTableEntryCount = meta.readShort();
937+
entry.denseRankPower = meta.readByte();
938+
}
931939
}
932940

933941
private BinaryEntry readBinary(IndexInput meta) throws IOException {
@@ -962,7 +970,7 @@ private static SortedNumericEntry readSortedNumeric(IndexInput meta, int version
962970

963971
private static SortedNumericEntry readSortedNumeric(IndexInput meta, SortedNumericEntry entry, int version) throws IOException {
964972
readNumeric(meta, entry, version);
965-
if (version < ES87TSDBDocValuesFormat.VERSION_META_MOVE_META_ENTRY) {
973+
if (version < ES87TSDBDocValuesFormat.VERSION_TWO) {
966974
entry.numDocsWithField = meta.readInt();
967975
}
968976
if (entry.numDocsWithField != entry.numValues) {

0 commit comments

Comments
 (0)