Skip to content

Commit

Permalink
During parent uid loading seek to next parent type when child type is…
Browse files Browse the repository at this point in the history
… encountered.

Relates to elastic#3028
  • Loading branch information
martijnvg committed May 14, 2013
1 parent b822bfe commit 2fdea74
Showing 1 changed file with 21 additions and 4 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.UTF8SortedAsUnicodeComparator;
import org.elasticsearch.common.trove.ExtTObjectIntHasMap;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.index.AbstractIndexComponent;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void refresh(List<AtomicReaderContext> atomicReaderContexts) throws Excep
Map<Object, IndexReader> cacheToReader = new HashMap<Object, IndexReader>();

// We don't want to load uid of child documents, this allows us to not load uids of child types.
Set<HashedBytesArray> parentTypes = new HashSet<HashedBytesArray>();
TreeSet<HashedBytesArray> parentTypes = new TreeSet<HashedBytesArray>(UTF8SortedAsUnicodeComparator.utf8SortedAsUnicodeSortOrder);
for (String type : indexService.mapperService().types()) {
ParentFieldMapper parentFieldMapper = indexService.mapperService().documentMapper(type).parentFieldMapper();
if (parentFieldMapper != null) {
Expand Down Expand Up @@ -145,11 +146,27 @@ public void refresh(List<AtomicReaderContext> atomicReaderContexts) throws Excep
if (terms != null) {
TermsEnum termsEnum = terms.iterator(null);
DocsEnum docsEnum = null;
for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
uid: for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
HashedBytesArray[] typeAndId = Uid.splitUidIntoTypeAndId(term);
// TODO: seek!
if (!parentTypes.contains(typeAndId[0])) {
continue;
do {
HashedBytesArray nextParent = parentTypes.ceiling(typeAndId[0]);
if (nextParent == null) {
break uid;
}

TermsEnum.SeekStatus status = termsEnum.seekCeil(nextParent.toBytesRef(), false);
if (status == TermsEnum.SeekStatus.END) {
break uid;
} else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
term = termsEnum.term();
typeAndId = Uid.splitUidIntoTypeAndId(term);
} else if (status == TermsEnum.SeekStatus.FOUND) {
assert false : "Seek status should never be FOUND, because we seek only the type part";
term = termsEnum.term();
typeAndId = Uid.splitUidIntoTypeAndId(term);
}
} while (!parentTypes.contains(typeAndId[0]));
}

String type = typeAndId[0].toUtf8();
Expand Down

0 comments on commit 2fdea74

Please sign in to comment.