From 9c011d5b79848489cda5d3d0e34aa6493a0e88b3 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 8 Feb 2011 23:40:49 +0200 Subject: [PATCH] improve get perf by using bloom filter to fetch the doc --- .../action/get/TransportGetAction.java | 35 +++++++++++++++---- .../common/lucene/uid/UidField.java | 14 ++++---- .../elasticsearch/index/cache/IndexCache.java | 4 +++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java index 2fe4f29a16f..7779022b1e7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java @@ -22,22 +22,25 @@ package org.elasticsearch.action.get; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldSelector; import org.apache.lucene.document.Fieldable; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.Term; +import org.apache.lucene.util.UnicodeUtil; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.common.Unicode; +import org.elasticsearch.common.bloom.BloomFilter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.uid.UidField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.cache.bloom.BloomCache; import org.elasticsearch.index.engine.Engine; -import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.FieldMapper; -import org.elasticsearch.index.mapper.FieldMappers; -import org.elasticsearch.index.mapper.FieldMappersFieldSelector; +import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; @@ -80,6 +83,7 @@ public class TransportGetAction extends TransportShardSingleOperationAction fields = null; long version = -1; try { - UidField.DocIdAndVersion docIdAndVersion = UidField.loadDocIdAndVersion(searcher.reader(), docMapper.uidMapper().term(request.type(), request.id())); - if (docIdAndVersion.docId != Lucene.NO_DOC) { + UidField.DocIdAndVersion docIdAndVersion = loadCurrentVersionFromIndex(bloomCache, searcher, docMapper.uidMapper().term(request.type(), request.id())); + if (docIdAndVersion != null && docIdAndVersion.docId != Lucene.NO_DOC) { if (docIdAndVersion.version > 0) { version = docIdAndVersion.version; } exists = true; FieldSelector fieldSelector = buildFieldSelectors(docMapper, request.fields()); if (fieldSelector != null) { - Document doc = searcher.reader().document(docIdAndVersion.docId, fieldSelector); + Document doc = docIdAndVersion.reader.document(docIdAndVersion.docId, fieldSelector); source = extractSource(doc, docMapper); for (Object oField : doc.getFields()) { @@ -180,6 +184,23 @@ public class TransportGetAction extends TransportShardSingleOperationAction