@@ -52,12 +52,6 @@ final class PerThreadIDVersionAndSeqNoLookup {
5252 // TODO: do we really need to store all this stuff? some if it might not speed up anything.
5353 // we keep it around for now, to reduce the amount of e.g. hash lookups by field and stuff
5454
55- /** The {@link LeafReaderContext} that needs to be looked up. */
56- private final LeafReaderContext context ;
57- /** Live docs of the context, cached to avoid the cost of ensureOpen() on every
58- * segment for every index operation. */
59- private final Bits liveDocs ;
60-
6155 /** terms enum for uid field */
6256 final String uidField ;
6357 private final TermsEnum termsEnum ;
@@ -71,10 +65,7 @@ final class PerThreadIDVersionAndSeqNoLookup {
7165 /**
7266 * Initialize lookup for the provided segment
7367 */
74- PerThreadIDVersionAndSeqNoLookup (LeafReaderContext context , String uidField ) throws IOException {
75- this .context = context ;
76- final LeafReader reader = context .reader ();
77- this .liveDocs = reader .getLiveDocs ();
68+ PerThreadIDVersionAndSeqNoLookup (LeafReader reader , String uidField ) throws IOException {
7869 this .uidField = uidField ;
7970 Fields fields = reader .fields ();
8071 Terms terms = fields .terms (uidField );
@@ -91,12 +82,17 @@ final class PerThreadIDVersionAndSeqNoLookup {
9182 this .readerKey = readerKey ;
9283 }
9384
94- /** Return null if id is not found. */
95- public DocIdAndVersion lookupVersion (BytesRef id )
85+ /** Return null if id is not found.
86+ * We pass the {@link LeafReaderContext} as an argument so that things
87+ * still work with reader wrappers that hide some documents while still
88+ * using the same cache key. Otherwise we'd have to disable caching
89+ * entirely for these readers.
90+ */
91+ public DocIdAndVersion lookupVersion (BytesRef id , LeafReaderContext context )
9692 throws IOException {
9793 assert context .reader ().getCoreCacheHelper ().getKey ().equals (readerKey ) :
9894 "context's reader is not the same as the reader class was initialized on." ;
99- int docID = getDocID (id );
95+ int docID = getDocID (id , context . reader (). getLiveDocs () );
10096
10197 if (docID != DocIdSetIterator .NO_MORE_DOCS ) {
10298 final NumericDocValues versions = context .reader ().getNumericDocValues (VersionFieldMapper .NAME );
@@ -116,7 +112,7 @@ public DocIdAndVersion lookupVersion(BytesRef id)
116112 * returns the internal lucene doc id for the given id bytes.
117113 * {@link DocIdSetIterator#NO_MORE_DOCS} is returned if not found
118114 * */
119- private int getDocID (BytesRef id ) throws IOException {
115+ private int getDocID (BytesRef id , Bits liveDocs ) throws IOException {
120116 if (termsEnum .seekExact (id )) {
121117 int docID = DocIdSetIterator .NO_MORE_DOCS ;
122118 // there may be more than one matching docID, in the case of nested docs, so we want the last one:
@@ -134,8 +130,10 @@ private int getDocID(BytesRef id) throws IOException {
134130 }
135131
136132 /** Return null if id is not found. */
137- DocIdAndSeqNo lookupSeqNo (BytesRef id ) throws IOException {
138- int docID = getDocID (id );
133+ DocIdAndSeqNo lookupSeqNo (BytesRef id , LeafReaderContext context ) throws IOException {
134+ assert context .reader ().getCoreCacheHelper ().getKey ().equals (readerKey ) :
135+ "context's reader is not the same as the reader class was initialized on." ;
136+ int docID = getDocID (id , context .reader ().getLiveDocs ());
139137 if (docID != DocIdSetIterator .NO_MORE_DOCS ) {
140138 NumericDocValues seqNos = context .reader ().getNumericDocValues (SeqNoFieldMapper .NAME );
141139 long seqNo ;
0 commit comments