From 25ca1ee495a921ef8289f8cd050b699843b1027c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 26 Jan 2024 11:06:01 +0100 Subject: [PATCH] Delta code postings offsets. --- .../postings/ES814InlineFieldsConsumer.java | 4 ++-- .../postings/ES814InlineFieldsProducer.java | 19 ++++++++++++------- .../postings/ES814InlinePostingsFormat.java | 10 ++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsConsumer.java b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsConsumer.java index 6805383f74a42..43c54f9676a66 100644 --- a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsConsumer.java +++ b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsConsumer.java @@ -134,7 +134,7 @@ public void write(Fields fields, NormsProducer norms) throws IOException { continue; } long proxOffset = hasPositions ? prox.getFilePointer() : -1L; - long postingsPointer = postingsOut.size(); + long postingsStartPointer = postingsOut.size(); writer.write(pe, postingsOut); termsOut.writeVInt(term.length); termsOut.writeBytes(term.bytes, term.offset, term.length); @@ -145,7 +145,7 @@ public void write(Fields fields, NormsProducer norms) throws IOException { if (hasPositions) { termsOut.writeLong(proxOffset); } - termsOut.writeLong(postingsPointer); + termsOut.writeVLong(postingsOut.size() - postingsStartPointer); ++numPending; maxTermLength = Math.max(maxTermLength, term.length); ++numTerms; diff --git a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsProducer.java b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsProducer.java index 9cbff04263f37..fdfce5b43278b 100644 --- a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsProducer.java +++ b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlineFieldsProducer.java @@ -332,8 +332,8 @@ private void reset() throws IOException { state.blockIndex = -1; state.termIndexInBlock = 0; state.numTermsInBlock = -1; - state.postingsFP = 0; - state.postingsBytes = 0; + state.blockPostingsFP = 0; + state.blockPostingsBytes = 0; } private long findBlockIndex(BytesRef target) throws IOException { @@ -439,7 +439,7 @@ public BytesRef next() throws IOException { return null; // exhausted } if (state.blockIndex > 0) { - index.seek(state.postingsFP + state.postingsBytes); + index.seek(state.blockPostingsFP + state.blockPostingsBytes); } loadFrame(); } else if (state.blockIndex != loadedFrameIndex) { @@ -467,9 +467,11 @@ private void loadFrame() throws IOException { state.numTermsInBlock = index.readVInt(); final long originalTermsBytes = index.readVLong(); final long termBytes = index.readVLong(); - state.postingsBytes = index.readVLong(); + state.blockPostingsBytes = index.readVLong(); long termsFP = index.getFilePointer(); - state.postingsFP = termsFP + termBytes; + state.blockPostingsFP = termsFP + termBytes; + state.docOffset = state.blockPostingsFP; + state.termPostingsBytes = 0L; decompressTerms((int) termBytes, (int) originalTermsBytes); loadedFrameIndex = state.blockIndex; } @@ -478,7 +480,9 @@ private void resetFrame() throws IOException { assert loadedFrameIndex == state.blockIndex : loadedFrameIndex + " != " + state.blockIndex; state.termIndexInBlock = 0; termsReader.setPosition(0); - index.seek(state.postingsFP); + state.docOffset = state.blockPostingsFP; + state.termPostingsBytes = 0L; + index.seek(state.blockPostingsFP); } private void scanNextTermInCurrentFrame() throws IOException { @@ -495,7 +499,8 @@ private void scanNextTermInCurrentFrame() throws IOException { if (meta.options.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) { state.proxOffset = termsReader.readLong(); } - state.docOffset = state.postingsFP + termsReader.readLong(); + state.docOffset += state.termPostingsBytes; + state.termPostingsBytes = termsReader.readVLong(); state.termIndexInBlock++; } diff --git a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlinePostingsFormat.java b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlinePostingsFormat.java index c8b7766dee982..2296b8d71e02e 100644 --- a/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlinePostingsFormat.java +++ b/server/src/main/java/org/elasticsearch/index/codec/postings/ES814InlinePostingsFormat.java @@ -64,9 +64,10 @@ public static final class InlineTermState extends BlockTermState { public long termIndexInBlock; public long numTermsInBlock; - public long postingsFP; - public long postingsBytes; + public long blockPostingsFP; + public long blockPostingsBytes; + public long termPostingsBytes; public long docOffset; public long proxOffset; @@ -77,9 +78,10 @@ public void copyFrom(TermState _other) { this.blockIndex = state.blockIndex; this.termIndexInBlock = state.termIndexInBlock; this.numTermsInBlock = state.numTermsInBlock; - this.postingsFP = state.postingsFP; - this.postingsBytes = state.postingsBytes; + this.blockPostingsFP = state.blockPostingsFP; + this.blockPostingsBytes = state.blockPostingsBytes; this.docOffset = state.docOffset; + this.termPostingsBytes = state.termPostingsBytes; this.proxOffset = state.proxOffset; }