Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5750: speed up monotonic address in BINARY/SORTED_SET

Robert Muird3919d3b0ad6
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 253465bc981..d5002f78fee 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -260,6 +260,9 @@ Optimizations
* LUCENE-5721: Monotonic compression doesn't use zig-zag encoding anymore.
(Robert Muir, Adrien Grand)
+* LUCENE-5750: Speed up monotonic addressing for BINARY and SORTED_SET
+ docvalues. (Robert Muir)
+
Bug fixes
* LUCENE-5738: Ensure NativeFSLock prevents opening the file channel for the
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesProducer.java b/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesProducer.java
index 879f90d76c0..b5bde469a67 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesProducer.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/diskdv/DiskDocValuesProducer.java
@@ -34,7 +34,7 @@ class DiskDocValuesProducer extends Lucene49DocValuesProducer {
@Override
protected MonotonicBlockPackedReader getAddressInstance(IndexInput data, FieldInfo field, BinaryEntry bytes) throws IOException {
data.seek(bytes.addressesOffset);
- return MonotonicBlockPackedReader.of(data.clone(), bytes.packedIntsVersion, bytes.blockSize, bytes.count, true);
+ return MonotonicBlockPackedReader.of(data.clone(), bytes.packedIntsVersion, bytes.blockSize, bytes.count+1, true);
}
@Override
@@ -45,6 +45,6 @@ class DiskDocValuesProducer extends Lucene49DocValuesProducer {
@Override
protected MonotonicBlockPackedReader getOrdIndexInstance(IndexInput data, FieldInfo field, NumericEntry entry) throws IOException {
data.seek(entry.offset);
- return MonotonicBlockPackedReader.of(data.clone(), entry.packedIntsVersion, entry.blockSize, entry.count, true);
+ return MonotonicBlockPackedReader.of(data.clone(), entry.packedIntsVersion, entry.blockSize, entry.count+1, true);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesConsumer.java
index b2a8b0edb02..3affc9a568e 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesConsumer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesConsumer.java
@@ -288,6 +288,7 @@ public class Lucene49DocValuesConsumer extends DocValuesConsumer implements Clos
final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(data, BLOCK_SIZE);
long addr = 0;
+ writer.add(addr);
for (BytesRef v : values) {
if (v != null) {
addr += v.length;
@@ -439,6 +440,7 @@ public class Lucene49DocValuesConsumer extends DocValuesConsumer implements Clos
final MonotonicBlockPackedWriter writer = new MonotonicBlockPackedWriter(data, BLOCK_SIZE);
long addr = 0;
+ writer.add(addr);
for (Number v : docToOrdCount) {
addr += v.longValue();
writer.add(addr);
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java
index 3b9e2bf8cd0..43b7c65ccb7 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java
@@ -392,7 +392,7 @@ public class Lucene49DocValuesProducer extends DocValuesProducer implements Clos
MonotonicBlockPackedReader addrInstance = addressInstances.get(field.number);
if (addrInstance == null) {
data.seek(bytes.addressesOffset);
- addrInstance = MonotonicBlockPackedReader.of(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count, false);
+ addrInstance = MonotonicBlockPackedReader.of(data, bytes.packedIntsVersion, bytes.blockSize, bytes.count+1, false);
addressInstances.put(field.number, addrInstance);
ramBytesUsed.addAndGet(addrInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);
}
@@ -411,8 +411,8 @@ public class Lucene49DocValuesProducer extends DocValuesProducer implements Clos
@Override
public BytesRef get(long id) {
- long startAddress = bytes.offset + (id == 0 ? 0 : addresses.get(id-1));
- long endAddress = bytes.offset + addresses.get(id);
+ long startAddress = bytes.offset + addresses.get(id);
+ long endAddress = bytes.offset + addresses.get(id+1);
int length = (int) (endAddress - startAddress);
try {
data.seek(startAddress);
@@ -511,7 +511,7 @@ public class Lucene49DocValuesProducer extends DocValuesProducer implements Clos
MonotonicBlockPackedReader ordIndexInstance = ordIndexInstances.get(field.number);
if (ordIndexInstance == null) {
data.seek(entry.offset);
- ordIndexInstance = MonotonicBlockPackedReader.of(data, entry.packedIntsVersion, entry.blockSize, entry.count, false);
+ ordIndexInstance = MonotonicBlockPackedReader.of(data, entry.packedIntsVersion, entry.blockSize, entry.count+1, false);
ordIndexInstances.put(field.number, ordIndexInstance);
ramBytesUsed.addAndGet(ordIndexInstance.ramBytesUsed() + RamUsageEstimator.NUM_BYTES_INT);
}
@@ -556,8 +556,8 @@ public class Lucene49DocValuesProducer extends DocValuesProducer implements Clos
@Override
public void setDocument(int docID) {
- startOffset = offset = (docID == 0 ? 0 : ordIndex.get(docID-1));
- endOffset = ordIndex.get(docID);
+ startOffset = offset = ordIndex.get(docID);
+ endOffset = ordIndex.get(docID+1L);
}
@Override