Skip to content

Commit 09a11a3

Browse files
authored
Remove clusterAlias instance member from QueryShardContext (#37923)
The clusterAlias member is only used in the copy constructor, to be able to reconstruct the fully qualified index. It is also possible to remove the instance member and add a private constructor that accepts the already built Index object which contains the cluster alias.
1 parent 65a9b61 commit 09a11a3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Diff for: server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public class QueryShardContext extends QueryRewriteContext {
8686
private final BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataService;
8787
private final int shardId;
8888
private final IndexReader reader;
89-
private final String clusterAlias;
9089
private String[] types = Strings.EMPTY_ARRAY;
9190
private boolean cacheable = true;
9291
private final SetOnce<Boolean> frozen = new SetOnce<>();
@@ -110,6 +109,23 @@ public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterC
110109
SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
111110
NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis,
112111
String clusterAlias) {
112+
this(shardId, indexSettings, bitsetFilterCache, indexFieldDataLookup, mapperService, similarityService, scriptService,
113+
xContentRegistry, namedWriteableRegistry, client, reader, nowInMillis, new Index(RemoteClusterAware.buildRemoteIndexName(
114+
clusterAlias, indexSettings.getIndex().getName()), indexSettings.getIndex().getUUID()));
115+
}
116+
117+
public QueryShardContext(QueryShardContext source) {
118+
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService,
119+
source.similarityService, source.scriptService, source.getXContentRegistry(), source.getWriteableRegistry(),
120+
source.client, source.reader, source.nowInMillis, source.fullyQualifiedIndex);
121+
this.types = source.getTypes();
122+
}
123+
124+
private QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
125+
BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService,
126+
SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
127+
NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis,
128+
Index fullyQualifiedIndex) {
113129
super(xContentRegistry, namedWriteableRegistry,client, nowInMillis);
114130
this.shardId = shardId;
115131
this.similarityService = similarityService;
@@ -121,16 +137,7 @@ public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterC
121137
this.scriptService = scriptService;
122138
this.indexSettings = indexSettings;
123139
this.reader = reader;
124-
this.clusterAlias = clusterAlias;
125-
this.fullyQualifiedIndex = new Index(RemoteClusterAware.buildRemoteIndexName(clusterAlias, indexSettings.getIndex().getName()),
126-
indexSettings.getIndex().getUUID());
127-
}
128-
129-
public QueryShardContext(QueryShardContext source) {
130-
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService,
131-
source.similarityService, source.scriptService, source.getXContentRegistry(), source.getWriteableRegistry(),
132-
source.client, source.reader, source.nowInMillis, source.clusterAlias);
133-
this.types = source.getTypes();
140+
this.fullyQualifiedIndex = fullyQualifiedIndex;
134141
}
135142

136143
private void reset() {

0 commit comments

Comments
 (0)