Remove useless PK lookup in IndicesTTLService
This is a follow up of https://github.com/elastic/elasticsearch/pull/19944#issuecomment-239119859 Since the docid is known we can directly access the version doc value.
This commit is contained in:
parent
a1538de1a1
commit
729f443199
|
@ -20,7 +20,7 @@
|
||||||
package org.elasticsearch.indices.ttl;
|
package org.elasticsearch.indices.ttl;
|
||||||
|
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.search.SimpleCollector;
|
import org.apache.lucene.search.SimpleCollector;
|
||||||
|
@ -48,7 +48,7 @@ import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.TTLFieldMapper;
|
import org.elasticsearch.index.mapper.TTLFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.Uid;
|
import org.elasticsearch.index.mapper.Uid;
|
||||||
import org.elasticsearch.index.mapper.UidFieldMapper;
|
import org.elasticsearch.index.mapper.VersionFieldMapper;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
import org.elasticsearch.index.shard.IndexShardState;
|
import org.elasticsearch.index.shard.IndexShardState;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
|
@ -237,6 +237,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent {
|
||||||
private class ExpiredDocsCollector extends SimpleCollector {
|
private class ExpiredDocsCollector extends SimpleCollector {
|
||||||
private LeafReaderContext context;
|
private LeafReaderContext context;
|
||||||
private List<DocToPurge> docsToPurge = new ArrayList<>();
|
private List<DocToPurge> docsToPurge = new ArrayList<>();
|
||||||
|
private NumericDocValues versions;
|
||||||
|
|
||||||
public ExpiredDocsCollector() {
|
public ExpiredDocsCollector() {
|
||||||
}
|
}
|
||||||
|
@ -256,7 +257,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent {
|
||||||
FieldsVisitor fieldsVisitor = new FieldsVisitor(false);
|
FieldsVisitor fieldsVisitor = new FieldsVisitor(false);
|
||||||
context.reader().document(doc, fieldsVisitor);
|
context.reader().document(doc, fieldsVisitor);
|
||||||
Uid uid = fieldsVisitor.uid();
|
Uid uid = fieldsVisitor.uid();
|
||||||
final long version = Versions.loadVersion(context.reader(), new Term(UidFieldMapper.NAME, uid.toBytesRef()));
|
final long version = versions == null ? Versions.NOT_FOUND : versions.get(doc);
|
||||||
docsToPurge.add(new DocToPurge(uid.type(), uid.id(), version, fieldsVisitor.routing()));
|
docsToPurge.add(new DocToPurge(uid.type(), uid.id(), version, fieldsVisitor.routing()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.trace("failed to collect doc", e);
|
logger.trace("failed to collect doc", e);
|
||||||
|
@ -266,6 +267,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent {
|
||||||
@Override
|
@Override
|
||||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.versions = context.reader().getNumericDocValues(VersionFieldMapper.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DocToPurge> getDocsToPurge() {
|
public List<DocToPurge> getDocsToPurge() {
|
||||||
|
|
Loading…
Reference in New Issue