-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search: Remove query-cache serialization optimization.
The query-cache has an optimization to not deserialize the bytes at the shard level. However this is a bit fragile since it assumes that serialized streams can be concatenanted (which is not the case with shared strings) and also does not update the QueryResult object that is held by the SearchContext. So you need to make sure to use the right one. With this change, the query cache just deserializes bytes into the QueryResult object from the context. Close #9500
- Loading branch information
Showing
3 changed files
with
99 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/org/elasticsearch/indices/cache/query/IndicesQueryCacheTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.indices.cache.query; | ||
|
||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.search.SearchType; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket; | ||
import org.elasticsearch.test.ElasticsearchIntegrationTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
|
||
public class IndicesQueryCacheTests extends ElasticsearchIntegrationTest { | ||
|
||
// One of the primary purposes of the query cache is to cache aggs results | ||
public void testCacheAggs() throws Exception { | ||
assertAcked(client().admin().indices().prepareCreate("index") | ||
.addMapping("type", "f", "type=date") | ||
.setSettings(IndicesQueryCache.INDEX_CACHE_QUERY_ENABLED, true).get()); | ||
indexRandom(true, | ||
client().prepareIndex("index", "type").setSource("f", "2014-03-10T00:00:00.000Z"), | ||
client().prepareIndex("index", "type").setSource("f", "2014-05-13T00:00:00.000Z")); | ||
|
||
// This is not a random example: serialization with time zones writes shared strings | ||
// which used to not work well with the query cache because of the handles stream output | ||
// see #9500 | ||
final SearchResponse r1 = client().prepareSearch("index").setSearchType(SearchType.COUNT) | ||
.addAggregation(dateHistogram("histo").field("f").preZone("+01:00").minDocCount(0).interval(DateHistogramInterval.MONTH)).get(); | ||
assertSearchResponse(r1); | ||
|
||
// The cached is actually used | ||
assertThat(client().admin().indices().prepareStats("index").setQueryCache(true).get().getTotal().getQueryCache().getMemorySizeInBytes(), greaterThan(0l)); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
final SearchResponse r2 = client().prepareSearch("index").setSearchType(SearchType.COUNT) | ||
.addAggregation(dateHistogram("histo").field("f").preZone("+01:00").minDocCount(0).interval(DateHistogramInterval.MONTH)).get(); | ||
assertSearchResponse(r2); | ||
Histogram h1 = r1.getAggregations().get("histo"); | ||
Histogram h2 = r2.getAggregations().get("histo"); | ||
final List<? extends Bucket> buckets1 = h1.getBuckets(); | ||
final List<? extends Bucket> buckets2 = h2.getBuckets(); | ||
assertEquals(buckets1.size(), buckets2.size()); | ||
for (int j = 0; j < buckets1.size(); ++j) { | ||
final Bucket b1 = buckets1.get(j); | ||
final Bucket b2 = buckets2.get(j); | ||
assertEquals(b1.getKey(), b2.getKey()); | ||
assertEquals(b1.getDocCount(), b2.getDocCount()); | ||
} | ||
} | ||
} | ||
|
||
} |