-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index stale operations to Lucene to have complete history #29679
Changes from 1 commit
e24b4e6
d19ef6a
5f6e851
70d5359
0f0a755
5916467
687adc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,4 +145,15 @@ DocIdAndSeqNo lookupSeqNo(BytesRef id, LeafReaderContext context) throws IOExcep | |
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns an internal posting list of the given uid | ||
*/ | ||
PostingsEnum getPostingsOrNull(BytesRef id) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use this method here as well? |
||
if (termsEnum.seekExact(id)) { | ||
docsEnum = termsEnum.postings(docsEnum, 0); | ||
return docsEnum; | ||
} | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
import org.apache.lucene.index.LeafReader; | ||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.index.NumericDocValues; | ||
import org.apache.lucene.index.PostingsEnum; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.util.CloseableThreadLocal; | ||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections; | ||
import org.elasticsearch.index.mapper.SeqNoFieldMapper; | ||
|
@@ -193,4 +195,32 @@ public static long loadVersion(IndexReader reader, Term term) throws IOException | |
final DocIdAndVersion docIdAndVersion = loadDocIdAndVersion(reader, term); | ||
return docIdAndVersion == null ? NOT_FOUND : docIdAndVersion.version; | ||
} | ||
|
||
/** | ||
* Checks for the existence of the history of a pair SeqNo/PrimaryTerm in Lucene. The checking pair is considered as existed | ||
* if there is a pair such as the seqNo equals to the checking seqNo and the primary term is at least the checking term. | ||
*/ | ||
public static boolean hasHistoryInLucene(IndexReader reader, Term idTerm, long seqNo, long primaryTerm) throws IOException { | ||
final PerThreadIDVersionAndSeqNoLookup[] lookups = getLookupState(reader, idTerm.field()); | ||
final List<LeafReaderContext> leaves = reader.leaves(); | ||
// iterate backwards to optimize for the frequently updated documents which are likely to be in the last segments | ||
for (int i = leaves.size() - 1; i >= 0; i--) { | ||
final LeafReaderContext leaf = leaves.get(i); | ||
final PerThreadIDVersionAndSeqNoLookup lookup = lookups[leaf.ord]; | ||
final PostingsEnum postingsEnum = lookup.getPostingsOrNull(idTerm.bytes()); | ||
if (postingsEnum == null) { | ||
continue; | ||
} | ||
final NumericDocValues seqNoDV = leaf.reader().getNumericDocValues(SeqNoFieldMapper.NAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can assert that both seqNoDV and primaryTermDV are non null. They are required at least for this code to work. |
||
final NumericDocValues primaryTermDV = leaf.reader().getNumericDocValues(SeqNoFieldMapper.PRIMARY_TERM_NAME); | ||
for (int docId = postingsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = postingsEnum.nextDoc()) { | ||
if (seqNoDV != null && seqNoDV.advanceExact(docId) && primaryTermDV != null && primaryTermDV.advanceExact(docId)) { | ||
if (seqNoDV.longValue() == seqNo && primaryTermDV.longValue() >= primaryTerm) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just call
wrapAllDocsLive(DirectoryReader in)
it's really unrelated to soft deletes