Skip to content

Commit 75304f4

Browse files
committed
Merge branch 'master' into ccr
* master: Add proxy support to RemoteClusterConnection (#33062) TEST: Skip assertSeqNos for closed shards (#33130) TEST: resync operation on replica should acquire shard permit (#33103) Switch remaining x-pack tests to new style Requests (#33108) Switch remaining tests to new style Requests (#33109) Switch remaining ml tests to new style Requests (#33107) Build: Line up IDE detection logic Security index expands to a single replica (#33131) HLRC: request/response homogeneity and JavaDoc improvements (#33133) Checkstyle! [Test] Fix sporadic failure in MembershipActionTests Revert "Do NOT allow termvectors on nested fields (#32728)" [Rollup] Move toAggCap() methods out of rollup config objects (#32583) Fix race condition in scheduler engine test
2 parents ef9607e + 3376922 commit 75304f4

File tree

43 files changed

+1194
-956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1194
-956
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/StoredScriptsIT.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
21-
import org.apache.http.entity.ContentType;
22-
import org.apache.http.entity.StringEntity;
2320
import org.apache.http.util.EntityUtils;
2421
import org.elasticsearch.ElasticsearchStatusException;
2522
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
@@ -35,7 +32,6 @@
3532

3633
import java.util.Collections;
3734

38-
import static java.util.Collections.emptyMap;
3935
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4036
import static org.hamcrest.Matchers.equalTo;
4137

@@ -52,12 +48,9 @@ public void testGetStoredScript() throws Exception {
5248
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
5349
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
5450
// so far - using low-level REST API
55-
Response putResponse =
56-
adminClient()
57-
.performRequest("PUT", "/_scripts/calculate-score", emptyMap(),
58-
new StringEntity("{\"script\":" + script + "}",
59-
ContentType.APPLICATION_JSON));
60-
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
51+
Request putRequest = new Request("PUT", "/_scripts/calculate-score");
52+
putRequest.setJsonEntity("{\"script\":" + script + "}");
53+
Response putResponse = adminClient().performRequest(putRequest);
6154
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
6255

6356
GetStoredScriptRequest getRequest = new GetStoredScriptRequest("calculate-score");
@@ -78,12 +71,9 @@ public void testDeleteStoredScript() throws Exception {
7871
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
7972
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
8073
// so far - using low-level REST API
81-
Response putResponse =
82-
adminClient()
83-
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
84-
new StringEntity("{\"script\":" + script + "}",
85-
ContentType.APPLICATION_JSON));
86-
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
74+
Request putRequest = new Request("PUT", "/_scripts/" + id);
75+
putRequest.setJsonEntity("{\"script\":" + script + "}");
76+
Response putResponse = adminClient().performRequest(putRequest);
8777
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
8878

8979
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest(id);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import org.apache.http.entity.ContentType;
21-
import org.apache.http.entity.StringEntity;
2220
import org.apache.http.util.EntityUtils;
2321
import org.elasticsearch.action.ActionListener;
2422
import org.elasticsearch.action.LatchedActionListener;
@@ -27,6 +25,7 @@
2725
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
2826
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2927
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
28+
import org.elasticsearch.client.Request;
3029
import org.elasticsearch.client.RequestOptions;
3130
import org.elasticsearch.client.Response;
3231
import org.elasticsearch.client.RestHighLevelClient;
@@ -43,7 +42,6 @@
4342
import java.util.concurrent.CountDownLatch;
4443
import java.util.concurrent.TimeUnit;
4544

46-
import static java.util.Collections.emptyMap;
4745
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4846
import static org.hamcrest.Matchers.equalTo;
4947

@@ -193,11 +191,9 @@ private void putStoredScript(String id, StoredScriptSource scriptSource) throws
193191
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
194192
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
195193
// so far - using low-level REST API
196-
Response putResponse =
197-
adminClient()
198-
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
199-
new StringEntity("{\"script\":" + script + "}",
200-
ContentType.APPLICATION_JSON));
194+
Request request = new Request("PUT", "/_scripts/" + id);
195+
request.setJsonEntity("{\"script\":" + script + "}");
196+
Response putResponse = adminClient().performRequest(request);
201197
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
202198
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
203199
}

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void setupIndex() throws IOException {
5353

5454
@After
5555
public void cleanupIndex() throws IOException {
56-
client().performRequest("DELETE", indexName());
56+
client().performRequest(new Request("DELETE", indexName()));
5757
}
5858

5959
private String indexName() {

docs/reference/docs/termvectors.asciidoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ in similar way to the <<query-dsl-multi-match-query,multi match query>>
3030
[WARNING]
3131
Note that the usage of `/_termvector` is deprecated in 2.0, and replaced by `/_termvectors`.
3232

33-
[WARNING]
34-
Term Vectors API doesn't work on nested fields. `/_termvectors` on a nested
35-
field and any sub-fields of a nested field returns empty results.
36-
3733
[float]
3834
=== Return values
3935

rest-api-spec/src/main/resources/rest-api-spec/test/termvectors/50_nested.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public void apply(Settings value, Settings current, Settings previous) {
272272
ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING,
273273
TransportSearchAction.SHARD_COUNT_LIMIT_SETTING,
274274
RemoteClusterAware.REMOTE_CLUSTERS_SEEDS,
275+
RemoteClusterAware.REMOTE_CLUSTERS_PROXY,
275276
RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE,
276277
RemoteClusterService.REMOTE_CONNECTIONS_PER_CLUSTER,
277278
RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING,

server/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ public static Setting<String> simpleString(String key, Property... properties) {
10091009
return new Setting<>(key, s -> "", Function.identity(), properties);
10101010
}
10111011

1012+
public static Setting<String> simpleString(String key, Function<String, String> parser, Property... properties) {
1013+
return new Setting<>(key, s -> "", parser, properties);
1014+
}
1015+
10121016
public static Setting<String> simpleString(String key, Setting<String> fallback, Property... properties) {
10131017
return new Setting<>(key, fallback, Function.identity(), properties);
10141018
}

server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.elasticsearch.index.mapper.KeywordFieldMapper;
4646
import org.elasticsearch.index.mapper.MappedFieldType;
4747
import org.elasticsearch.index.mapper.MapperService;
48-
import org.elasticsearch.index.mapper.ObjectMapper;
4948
import org.elasticsearch.index.mapper.ParseContext;
5049
import org.elasticsearch.index.mapper.ParsedDocument;
5150
import org.elasticsearch.index.mapper.SourceFieldMapper;
@@ -161,7 +160,7 @@ private static void handleFieldWildcards(IndexShard indexShard, TermVectorsReque
161160
request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
162161
}
163162

164-
private static boolean isValidField(MappedFieldType fieldType, IndexShard indexShard) {
163+
private static boolean isValidField(MappedFieldType fieldType) {
165164
// must be a string
166165
if (fieldType instanceof StringFieldType == false) {
167166
return false;
@@ -170,16 +169,6 @@ private static boolean isValidField(MappedFieldType fieldType, IndexShard indexS
170169
if (fieldType.indexOptions() == IndexOptions.NONE) {
171170
return false;
172171
}
173-
// and must not be under nested field
174-
int dotIndex = fieldType.name().indexOf('.');
175-
while (dotIndex > -1) {
176-
String parentField = fieldType.name().substring(0, dotIndex);
177-
ObjectMapper mapper = indexShard.mapperService().getObjectMapper(parentField);
178-
if (mapper != null && mapper.nested().isNested()) {
179-
return false;
180-
}
181-
dotIndex = fieldType.name().indexOf('.', dotIndex + 1);
182-
}
183172
return true;
184173
}
185174

@@ -188,7 +177,7 @@ private static Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetR
188177
Set<String> validFields = new HashSet<>();
189178
for (String field : selectedFields) {
190179
MappedFieldType fieldType = indexShard.mapperService().fullName(field);
191-
if (isValidField(fieldType, indexShard) == false) {
180+
if (!isValidField(fieldType)) {
192181
continue;
193182
}
194183
// already retrieved, only if the analyzer hasn't been overridden at the field
@@ -295,7 +284,7 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect
295284
Collection<DocumentField> documentFields = new HashSet<>();
296285
for (IndexableField field : doc.getFields()) {
297286
MappedFieldType fieldType = indexShard.mapperService().fullName(field.name());
298-
if (isValidField(fieldType, indexShard) == false) {
287+
if (!isValidField(fieldType)) {
299288
continue;
300289
}
301290
if (request.selectedFields() != null && !request.selectedFields().contains(field.name())) {

server/src/main/java/org/elasticsearch/transport/RemoteClusterAware.java

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
*/
1919
package org.elasticsearch.transport;
2020

21+
import java.util.EnumSet;
2122
import java.util.function.Supplier;
2223
import org.elasticsearch.Version;
2324
import org.elasticsearch.cluster.metadata.ClusterNameExpressionResolver;
2425
import org.elasticsearch.cluster.node.DiscoveryNode;
26+
import org.elasticsearch.common.Strings;
27+
import org.elasticsearch.common.UUIDs;
28+
import org.elasticsearch.common.collect.Tuple;
2529
import org.elasticsearch.common.component.AbstractComponent;
2630
import org.elasticsearch.common.settings.ClusterSettings;
2731
import org.elasticsearch.common.settings.Setting;
@@ -66,6 +70,22 @@ public abstract class RemoteClusterAware extends AbstractComponent {
6670
public static final char REMOTE_CLUSTER_INDEX_SEPARATOR = ':';
6771
public static final String LOCAL_CLUSTER_GROUP_KEY = "";
6872

73+
/**
74+
* A proxy address for the remote cluster.
75+
* NOTE: this settings is undocumented until we have at last one transport that supports passing
76+
* on the hostname via a mechanism like SNI.
77+
*/
78+
public static final Setting.AffixSetting<String> REMOTE_CLUSTERS_PROXY = Setting.affixKeySetting(
79+
"search.remote.",
80+
"proxy",
81+
key -> Setting.simpleString(key, s -> {
82+
if (Strings.hasLength(s)) {
83+
parsePort(s);
84+
}
85+
return s;
86+
}, Setting.Property.NodeScope, Setting.Property.Dynamic), REMOTE_CLUSTERS_SEEDS);
87+
88+
6989
protected final ClusterNameExpressionResolver clusterNameResolver;
7090

7191
/**
@@ -77,25 +97,42 @@ protected RemoteClusterAware(Settings settings) {
7797
this.clusterNameResolver = new ClusterNameExpressionResolver(settings);
7898
}
7999

80-
protected static Map<String, List<Supplier<DiscoveryNode>>> buildRemoteClustersSeeds(Settings settings) {
100+
/**
101+
* Builds the dynamic per-cluster config from the given settings. This is a map keyed by the cluster alias that points to a tuple
102+
* (ProxyAddresss, [SeedNodeSuppliers]). If a cluster is configured with a proxy address all seed nodes will point to
103+
* {@link TransportAddress#META_ADDRESS} and their configured address will be used as the hostname for the generated discovery node.
104+
*/
105+
protected static Map<String, Tuple<String, List<Supplier<DiscoveryNode>>>> buildRemoteClustersDynamicConfig(Settings settings) {
81106
Stream<Setting<List<String>>> allConcreteSettings = REMOTE_CLUSTERS_SEEDS.getAllConcreteSettings(settings);
82107
return allConcreteSettings.collect(
83108
Collectors.toMap(REMOTE_CLUSTERS_SEEDS::getNamespace, concreteSetting -> {
84109
String clusterName = REMOTE_CLUSTERS_SEEDS.getNamespace(concreteSetting);
85110
List<String> addresses = concreteSetting.get(settings);
111+
final boolean proxyMode = REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace(clusterName).exists(settings);
86112
List<Supplier<DiscoveryNode>> nodes = new ArrayList<>(addresses.size());
87113
for (String address : addresses) {
88-
nodes.add(() -> {
89-
TransportAddress transportAddress = new TransportAddress(RemoteClusterAware.parseSeedAddress(address));
90-
return new DiscoveryNode(clusterName + "#" + transportAddress.toString(),
91-
transportAddress,
92-
Version.CURRENT.minimumCompatibilityVersion());
93-
});
114+
nodes.add(() -> buildSeedNode(clusterName, address, proxyMode));
94115
}
95-
return nodes;
116+
return new Tuple<>(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace(clusterName).get(settings), nodes);
96117
}));
97118
}
98119

120+
static DiscoveryNode buildSeedNode(String clusterName, String address, boolean proxyMode) {
121+
if (proxyMode) {
122+
TransportAddress transportAddress = new TransportAddress(TransportAddress.META_ADDRESS, 0);
123+
String hostName = address.substring(0, indexOfPortSeparator(address));
124+
return new DiscoveryNode("", clusterName + "#" + address, UUIDs.randomBase64UUID(), hostName, address,
125+
transportAddress, Collections
126+
.emptyMap(), EnumSet.allOf(DiscoveryNode.Role.class),
127+
Version.CURRENT.minimumCompatibilityVersion());
128+
} else {
129+
TransportAddress transportAddress = new TransportAddress(RemoteClusterAware.parseSeedAddress(address));
130+
return new DiscoveryNode(clusterName + "#" + transportAddress.toString(),
131+
transportAddress,
132+
Version.CURRENT.minimumCompatibilityVersion());
133+
}
134+
}
135+
99136
/**
100137
* Groups indices per cluster by splitting remote cluster-alias, index-name pairs on {@link #REMOTE_CLUSTER_INDEX_SEPARATOR}. All
101138
* indices per cluster are collected as a list in the returned map keyed by the cluster alias. Local indices are grouped under
@@ -138,20 +175,24 @@ public Map<String, List<String>> groupClusterIndices(String[] requestIndices, Pr
138175

139176
protected abstract Set<String> getRemoteClusterNames();
140177

178+
141179
/**
142180
* Subclasses must implement this to receive information about updated cluster aliases. If the given address list is
143181
* empty the cluster alias is unregistered and should be removed.
144182
*/
145-
protected abstract void updateRemoteCluster(String clusterAlias, List<String> addresses);
183+
protected abstract void updateRemoteCluster(String clusterAlias, List<String> addresses, String proxy);
146184

147185
/**
148186
* Registers this instance to listen to updates on the cluster settings.
149187
*/
150188
public void listenForUpdates(ClusterSettings clusterSettings) {
151-
clusterSettings.addAffixUpdateConsumer(RemoteClusterAware.REMOTE_CLUSTERS_SEEDS, this::updateRemoteCluster,
189+
clusterSettings.addAffixUpdateConsumer(RemoteClusterAware.REMOTE_CLUSTERS_PROXY,
190+
RemoteClusterAware.REMOTE_CLUSTERS_SEEDS,
191+
(key, value) -> updateRemoteCluster(key, value.v2(), value.v1()),
152192
(namespace, value) -> {});
153193
}
154194

195+
155196
protected static InetSocketAddress parseSeedAddress(String remoteHost) {
156197
String host = remoteHost.substring(0, indexOfPortSeparator(remoteHost));
157198
InetAddress hostAddress;

0 commit comments

Comments
 (0)