forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
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 possible.
This commit introduces an optimization that allows skipping shardsthat 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 elastic#65689). For indices that don't have that information available, the behaviour is the sameas it used to be.
- Loading branch information
Showing
14 changed files
with
1,058 additions
and
44 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
74 changes: 74 additions & 0 deletions
74
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,74 @@ | ||
/* | ||
* 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 java.util.function.LongSupplier; | ||
|
||
public class CoordinatorRewriteContext extends QueryRewriteContext { | ||
private final Index index; | ||
private final long minTimestamp; | ||
private final long maxTimestamp; | ||
private final DateFieldMapper.DateFieldType timestampFieldTyped; | ||
|
||
public CoordinatorRewriteContext(NamedXContentRegistry xContentRegistry, | ||
NamedWriteableRegistry writeableRegistry, | ||
Client client, | ||
LongSupplier nowInMillis, | ||
Index index, | ||
long minTimestamp, | ||
long maxTimestamp, | ||
DateFieldMapper.DateFieldType timestampFieldTyped) { | ||
super(xContentRegistry, writeableRegistry, client, nowInMillis); | ||
this.index = index; | ||
this.minTimestamp = minTimestamp; | ||
this.maxTimestamp = maxTimestamp; | ||
this.timestampFieldTyped = timestampFieldTyped; | ||
} | ||
|
||
long getMinTimestamp() { | ||
return minTimestamp; | ||
} | ||
|
||
long getMaxTimestamp() { | ||
return maxTimestamp; | ||
} | ||
|
||
@Nullable | ||
public MappedFieldType getFieldType(String fieldName) { | ||
if (fieldName.equals(timestampFieldTyped.name()) == false) { | ||
return null; | ||
} | ||
|
||
return timestampFieldTyped; | ||
} | ||
|
||
@Override | ||
public CoordinatorRewriteContext convertToCoordinatorRewriteContext() { | ||
return this; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
/* | ||
* 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.getMin(), | ||
timestampMillisRange.getMax(), | ||
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
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.