-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply can match phase on coordinator when the min max field data is a…
…vailable at the coordinator. (#65583) This commit introduces an optimization that allows skipping shards that are not necessary directly on the coordinator for time based indices. This is possible for frozen and searchable snapshots since those store their min/max timestamp range in their IndexMetadata (introduced in #65689). For indices that don't have that information available, the behaviour is the same as it used to be.
- Loading branch information
Showing
17 changed files
with
1,312 additions
and
63 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
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
83 changes: 83 additions & 0 deletions
83
server/src/main/java/org/elasticsearch/index/query/CoordinatorRewriteContext.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,83 @@ | ||
/* | ||
* 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.index.query; | ||
|
||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.mapper.DateFieldMapper; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.index.shard.IndexLongFieldRange; | ||
|
||
import java.util.function.LongSupplier; | ||
|
||
/** | ||
* Context object used to rewrite {@link QueryBuilder} instances into simplified version in the coordinator. | ||
* Instances of this object rely on information stored in the {@code IndexMetadata} for certain indices. | ||
* Right now this context object is able to rewrite range queries that include a known timestamp field | ||
* (i.e. the timestamp field for DataStreams) into a MatchNoneQueryBuilder and skip the shards that | ||
* don't hold queried data. See IndexMetadata#getTimestampMillisRange() for more details | ||
*/ | ||
public class CoordinatorRewriteContext extends QueryRewriteContext { | ||
private final Index index; | ||
private IndexLongFieldRange indexLongFieldRange; | ||
private final DateFieldMapper.DateFieldType timestampFieldType; | ||
|
||
public CoordinatorRewriteContext(NamedXContentRegistry xContentRegistry, | ||
NamedWriteableRegistry writeableRegistry, | ||
Client client, | ||
LongSupplier nowInMillis, | ||
Index index, | ||
IndexLongFieldRange indexLongFieldRange, | ||
DateFieldMapper.DateFieldType timestampFieldType) { | ||
super(xContentRegistry, writeableRegistry, client, nowInMillis); | ||
this.index = index; | ||
this.indexLongFieldRange = indexLongFieldRange; | ||
this.timestampFieldType = timestampFieldType; | ||
} | ||
|
||
long getMinTimestamp() { | ||
return indexLongFieldRange.getMin(); | ||
} | ||
|
||
long getMaxTimestamp() { | ||
return indexLongFieldRange.getMax(); | ||
} | ||
|
||
boolean hasTimestampData() { | ||
return indexLongFieldRange.isComplete() && indexLongFieldRange != IndexLongFieldRange.EMPTY; | ||
} | ||
|
||
@Nullable | ||
public MappedFieldType getFieldType(String fieldName) { | ||
if (fieldName.equals(timestampFieldType.name()) == false) { | ||
return null; | ||
} | ||
|
||
return timestampFieldType; | ||
} | ||
|
||
@Override | ||
public CoordinatorRewriteContext convertToCoordinatorRewriteContext() { | ||
return this; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
server/src/main/java/org/elasticsearch/index/query/CoordinatorRewriteContextProvider.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,83 @@ | ||
/* | ||
* 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.index.query; | ||
|
||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.mapper.DateFieldMapper; | ||
import org.elasticsearch.index.shard.IndexLongFieldRange; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
||
public class CoordinatorRewriteContextProvider { | ||
private final NamedXContentRegistry xContentRegistry; | ||
private final NamedWriteableRegistry writeableRegistry; | ||
private final Client client; | ||
private final LongSupplier nowInMillis; | ||
private final Supplier<ClusterState> clusterStateSupplier; | ||
private final Function<Index, DateFieldMapper.DateFieldType> mappingSupplier; | ||
|
||
public CoordinatorRewriteContextProvider(NamedXContentRegistry xContentRegistry, | ||
NamedWriteableRegistry writeableRegistry, | ||
Client client, | ||
LongSupplier nowInMillis, | ||
Supplier<ClusterState> clusterStateSupplier, | ||
Function<Index, DateFieldMapper.DateFieldType> mappingSupplier) { | ||
this.xContentRegistry = xContentRegistry; | ||
this.writeableRegistry = writeableRegistry; | ||
this.client = client; | ||
this.nowInMillis = nowInMillis; | ||
this.clusterStateSupplier = clusterStateSupplier; | ||
this.mappingSupplier = mappingSupplier; | ||
} | ||
|
||
@Nullable | ||
public CoordinatorRewriteContext getCoordinatorRewriteContext(Index index) { | ||
ClusterState clusterState = clusterStateSupplier.get(); | ||
IndexMetadata indexMetadata = clusterState.metadata().index(index); | ||
|
||
if (indexMetadata == null || indexMetadata.getTimestampMillisRange().containsAllShardRanges() == false) { | ||
return null; | ||
} | ||
|
||
DateFieldMapper.DateFieldType dateFieldType = mappingSupplier.apply(index); | ||
|
||
if (dateFieldType == null) { | ||
return null; | ||
} | ||
|
||
IndexLongFieldRange timestampMillisRange = indexMetadata.getTimestampMillisRange(); | ||
return new CoordinatorRewriteContext(xContentRegistry, | ||
writeableRegistry, | ||
client, | ||
nowInMillis, | ||
index, | ||
timestampMillisRange, | ||
dateFieldType | ||
); | ||
} | ||
} |
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
Oops, something went wrong.