Skip to content

Commit

Permalink
Not load the ids of child documents into memory.
Browse files Browse the repository at this point in the history
Closes #3028
  • Loading branch information
martijnvg committed May 14, 2013
1 parent abe1707 commit eabd876
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/elasticsearch/index/cache/id/IdCache.java
Expand Up @@ -29,7 +29,8 @@
import java.util.List;

/**
*
* This id cache contains only the ids of parent documents, loaded via the uid or parent field.
* This name IdCache is misleading, parentIdCache would be a better name.
*/
public interface IdCache extends IndexComponent, CloseableComponent, Iterable<IdReaderCache> {

Expand Down
Expand Up @@ -116,6 +116,15 @@ public void refresh(List<AtomicReaderContext> atomicReaderContexts) throws Excep
Map<Object, Map<String, TypeBuilder>> builders = new HashMap<Object, Map<String, TypeBuilder>>();
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>();
for (String type : indexService.mapperService().types()) {
ParentFieldMapper parentFieldMapper = indexService.mapperService().documentMapper(type).parentFieldMapper();
if (parentFieldMapper != null) {
parentTypes.add(new HashedBytesArray(parentFieldMapper.type()));
}
}

// first, go over and load all the id->doc map for all types
for (AtomicReaderContext context : atomicReaderContexts) {
AtomicReader reader = context.reader();
Expand All @@ -138,10 +147,16 @@ public void refresh(List<AtomicReaderContext> atomicReaderContexts) throws Excep
DocsEnum docsEnum = null;
for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
HashedBytesArray[] typeAndId = Uid.splitUidIntoTypeAndId(term);
TypeBuilder typeBuilder = readerBuilder.get(typeAndId[0].toUtf8());
// TODO: seek!
if (!parentTypes.contains(typeAndId[0])) {
continue;
}

String type = typeAndId[0].toUtf8();
TypeBuilder typeBuilder = readerBuilder.get(type);
if (typeBuilder == null) {
typeBuilder = new TypeBuilder(reader);
readerBuilder.put(typeAndId[0].toUtf8(), typeBuilder);
readerBuilder.put(type, typeBuilder);
}

HashedBytesArray idAsBytes = checkIfCanReuse(builders, typeAndId[1]);
Expand Down
Expand Up @@ -69,7 +69,7 @@ public static void main(String[] args) throws Exception {
int QUERY_COUNT = 50;
String indexName = "test";

Thread.sleep(10000);
client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
try {
client.admin().indices().create(createIndexRequest(indexName)).actionGet();
client.admin().indices().preparePutMapping(indexName).setType("child").setSource(XContentFactory.jsonBuilder().startObject().startObject("type")
Expand Down Expand Up @@ -366,6 +366,7 @@ public static void main(String[] args) throws Exception {
System.out.println("--> has_parent query with match_all Query Avg: " + (totalQueryTime / QUERY_COUNT) + "ms");


System.gc();
statsResponse = client.admin().cluster().prepareNodesStats()
.setJvm(true).setIndices(true).execute().actionGet();

Expand Down

0 comments on commit eabd876

Please sign in to comment.