-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Run coordinating can_match in field-caps #127734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
pr: 127734 | ||
summary: Run coordinating `can_match` in field-caps | ||
area: ES|QL | ||
type: enhancement | ||
issues: [] |
181 changes: 181 additions & 0 deletions
181
...rc/internalClusterTest/java/org/elasticsearch/action/fieldcaps/FieldCapsWithFilterIT.java
This file contains hidden or 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,181 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.action.fieldcaps; | ||
|
||
import org.apache.lucene.document.LongPoint; | ||
import org.apache.lucene.index.DirectoryReader; | ||
import org.apache.lucene.index.PointValues; | ||
import org.elasticsearch.action.NoShardAvailableActionException; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.engine.EngineConfig; | ||
import org.elasticsearch.index.engine.EngineFactory; | ||
import org.elasticsearch.index.engine.InternalEngine; | ||
import org.elasticsearch.index.engine.InternalEngineFactory; | ||
import org.elasticsearch.index.query.RangeQueryBuilder; | ||
import org.elasticsearch.index.shard.IndexLongFieldRange; | ||
import org.elasticsearch.index.shard.ShardLongFieldRange; | ||
import org.elasticsearch.plugins.EnginePlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
|
||
public class FieldCapsWithFilterIT extends ESIntegTestCase { | ||
@Override | ||
protected boolean addMockInternalEngine() { | ||
return false; | ||
} | ||
|
||
private static class EngineWithExposingTimestamp extends InternalEngine { | ||
EngineWithExposingTimestamp(EngineConfig engineConfig) { | ||
super(engineConfig); | ||
assert IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.get(config().getIndexSettings().getSettings()) : "require read-only index"; | ||
} | ||
|
||
@Override | ||
public ShardLongFieldRange getRawFieldRange(String field) { | ||
try (Searcher searcher = acquireSearcher("test")) { | ||
final DirectoryReader directoryReader = searcher.getDirectoryReader(); | ||
|
||
final byte[] minPackedValue = PointValues.getMinPackedValue(directoryReader, field); | ||
final byte[] maxPackedValue = PointValues.getMaxPackedValue(directoryReader, field); | ||
if (minPackedValue == null || maxPackedValue == null) { | ||
assert minPackedValue == null && maxPackedValue == null | ||
: Arrays.toString(minPackedValue) + "-" + Arrays.toString(maxPackedValue); | ||
return ShardLongFieldRange.EMPTY; | ||
} | ||
|
||
return ShardLongFieldRange.of(LongPoint.decodeDimension(minPackedValue, 0), LongPoint.decodeDimension(maxPackedValue, 0)); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} | ||
|
||
public static class ExposingTimestampEnginePlugin extends Plugin implements EnginePlugin { | ||
@Override | ||
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) { | ||
if (IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.get(indexSettings.getSettings())) { | ||
return Optional.of(EngineWithExposingTimestamp::new); | ||
} else { | ||
return Optional.of(new InternalEngineFactory()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return CollectionUtils.appendToCopy(super.nodePlugins(), ExposingTimestampEnginePlugin.class); | ||
} | ||
|
||
void createIndexAndIndexDocs(String index, Settings.Builder indexSettings, long timestamp, boolean exposeTimestamp) throws Exception { | ||
Client client = client(); | ||
assertAcked( | ||
client.admin() | ||
.indices() | ||
.prepareCreate(index) | ||
.setSettings(indexSettings) | ||
.setMapping("@timestamp", "type=date", "position", "type=long") | ||
); | ||
int numDocs = between(100, 500); | ||
for (int i = 0; i < numDocs; i++) { | ||
client.prepareIndex(index).setSource("position", i, "@timestamp", timestamp + i).get(); | ||
} | ||
if (exposeTimestamp) { | ||
client.admin().indices().prepareClose(index).get(); | ||
client.admin() | ||
.indices() | ||
.prepareUpdateSettings(index) | ||
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true).build()) | ||
.get(); | ||
client.admin().indices().prepareOpen(index).get(); | ||
assertBusy(() -> { | ||
IndexLongFieldRange timestampRange = clusterService().state().metadata().getProject().index(index).getTimestampRange(); | ||
assertTrue(Strings.toString(timestampRange), timestampRange.containsAllShardRanges()); | ||
}); | ||
} else { | ||
client.admin().indices().prepareRefresh(index).get(); | ||
} | ||
} | ||
|
||
public void testSkipUnmatchedShards() throws Exception { | ||
long oldTimestamp = randomLongBetween(10_000_000, 20_000_000); | ||
long newTimestamp = randomLongBetween(30_000_000, 50_000_000); | ||
String redNode = internalCluster().startDataOnlyNode(); | ||
String blueNode = internalCluster().startDataOnlyNode(); | ||
createIndexAndIndexDocs( | ||
"index_old", | ||
indexSettings(between(1, 5), 0).put("index.routing.allocation.include._name", redNode), | ||
oldTimestamp, | ||
true | ||
); | ||
internalCluster().stopNode(redNode); | ||
createIndexAndIndexDocs( | ||
"index_new", | ||
indexSettings(between(1, 5), 0).put("index.routing.allocation.include._name", blueNode), | ||
newTimestamp, | ||
false | ||
); | ||
// fails without index filter | ||
{ | ||
FieldCapabilitiesRequest request = new FieldCapabilitiesRequest(); | ||
request.indices("index_*"); | ||
request.fields("*"); | ||
request.setMergeResults(false); | ||
if (randomBoolean()) { | ||
request.indexFilter(new RangeQueryBuilder("@timestamp").from(oldTimestamp)); | ||
} | ||
var response = safeGet(client().execute(TransportFieldCapabilitiesAction.TYPE, request)); | ||
assertThat(response.getIndexResponses(), hasSize(1)); | ||
assertThat(response.getIndexResponses().get(0).getIndexName(), equalTo("index_new")); | ||
assertThat(response.getFailures(), hasSize(1)); | ||
assertThat(response.getFailures().get(0).getIndices(), equalTo(new String[] { "index_old" })); | ||
assertThat(response.getFailures().get(0).getException(), instanceOf(NoShardAvailableActionException.class)); | ||
} | ||
// skip unavailable shards with index filter | ||
{ | ||
FieldCapabilitiesRequest request = new FieldCapabilitiesRequest(); | ||
request.indices("index_*"); | ||
request.fields("*"); | ||
request.indexFilter(new RangeQueryBuilder("@timestamp").from(newTimestamp)); | ||
request.setMergeResults(false); | ||
var response = safeGet(client().execute(TransportFieldCapabilitiesAction.TYPE, request)); | ||
assertThat(response.getIndexResponses(), hasSize(1)); | ||
assertThat(response.getIndexResponses().get(0).getIndexName(), equalTo("index_new")); | ||
assertThat(response.getFailures(), empty()); | ||
} | ||
// skip both indices on the coordinator, one the data nodes | ||
{ | ||
FieldCapabilitiesRequest request = new FieldCapabilitiesRequest(); | ||
request.indices("index_*"); | ||
request.fields("*"); | ||
request.indexFilter(new RangeQueryBuilder("@timestamp").from(newTimestamp * 2L)); | ||
request.setMergeResults(false); | ||
var response = safeGet(client().execute(TransportFieldCapabilitiesAction.TYPE, request)); | ||
assertThat(response.getIndexResponses(), empty()); | ||
assertThat(response.getFailures(), empty()); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use CanMatchPreFilterSearchPhase to avoid duplicates, but this approach is simpler.