Skip to content

Commit 8b3f218

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
* es/6.x: Enable skipping fetching latest for BWC builds (#29497) Add remote cluster client (#29495) Ensure flush happens on shard idle Adds SpanGapQueryBuilder in the query DSL (#28636) Fix auto-generated ID example format (#29461) Fix typo in max number of threads check docs (#29469) Add primary term to translog header (#29227) Add a helper method to get a random java.util.TimeZone (#29487) Move TimeValue into elasticsearch-core project (#29486) Fix NPE in InternalGeoCentroidTests#testReduceRandom (#29481) Build: introduce keystoreFile for cluster config (#29491) test: Index more docs, so that it is less likely the search request does not time out.
2 parents 7870029 + bb3bd10 commit 8b3f218

File tree

62 files changed

+1519
-565
lines changed

Some content is hidden

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

62 files changed

+1519
-565
lines changed

TESTING.asciidoc

+7
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ will contain your change.
498498
. Push both branches to your remote repository.
499499
. Run the tests with `./gradlew check -Dtests.bwc.remote=${remote} -Dtests.bwc.refspec.5.x=index_req_bwc_5.x`.
500500

501+
== Skip fetching latest
502+
503+
For some BWC testing scenarios, you want to use the local clone of the
504+
repository without fetching latest. For these use cases, you can set the system
505+
property `tests.bwc.git_fetch_latest` to `false` and the BWC builds will skip
506+
fetching the latest from the remote.
507+
501508
== Test coverage analysis
502509

503510
Generating test coverage reports for Elasticsearch is currently not possible through Gradle.

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

+11
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class ClusterConfiguration {
141141

142142
Map<String, String> keystoreSettings = new HashMap<>()
143143

144+
Map<String, Object> keystoreFiles = new HashMap<>()
145+
144146
// map from destination path, to source file
145147
Map<String, Object> extraConfigFiles = new HashMap<>()
146148

@@ -167,6 +169,15 @@ class ClusterConfiguration {
167169
keystoreSettings.put(name, value)
168170
}
169171

172+
/**
173+
* Adds a file to the keystore. The name is the secure setting name, and the sourceFile
174+
* is anything accepted by project.file()
175+
*/
176+
@Input
177+
void keystoreFile(String name, Object sourceFile) {
178+
keystoreFiles.put(name, sourceFile)
179+
}
180+
170181
@Input
171182
void plugin(String path) {
172183
Project pluginProject = project.project(path)

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

+33-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class ClusterFormationTasks {
180180
setup = configureWriteConfigTask(taskName(prefix, node, 'configure'), project, setup, node, seedNode)
181181
setup = configureCreateKeystoreTask(taskName(prefix, node, 'createKeystore'), project, setup, node)
182182
setup = configureAddKeystoreSettingTasks(prefix, project, setup, node)
183+
setup = configureAddKeystoreFileTasks(prefix, project, setup, node)
183184

184185
if (node.config.plugins.isEmpty() == false) {
185186
if (node.nodeVersion == VersionProperties.elasticsearch) {
@@ -327,7 +328,7 @@ class ClusterFormationTasks {
327328

328329
/** Adds a task to create keystore */
329330
static Task configureCreateKeystoreTask(String name, Project project, Task setup, NodeInfo node) {
330-
if (node.config.keystoreSettings.isEmpty()) {
331+
if (node.config.keystoreSettings.isEmpty() && node.config.keystoreFiles.isEmpty()) {
331332
return setup
332333
} else {
333334
/*
@@ -361,6 +362,37 @@ class ClusterFormationTasks {
361362
return parentTask
362363
}
363364

365+
/** Adds tasks to add files to the keystore */
366+
static Task configureAddKeystoreFileTasks(String parent, Project project, Task setup, NodeInfo node) {
367+
Map<String, Object> kvs = node.config.keystoreFiles
368+
if (kvs.isEmpty()) {
369+
return setup
370+
}
371+
Task parentTask = setup
372+
/*
373+
* We have to delay building the string as the path will not exist during configuration which will fail on Windows due to getting
374+
* the short name requiring the path to already exist.
375+
*/
376+
final Object esKeystoreUtil = "${-> node.binPath().resolve('elasticsearch-keystore').toString()}"
377+
for (Map.Entry<String, Object> entry in kvs) {
378+
String key = entry.getKey()
379+
String name = taskName(parent, node, 'addToKeystore#' + key)
380+
String srcFileName = entry.getValue()
381+
Task t = configureExecTask(name, project, parentTask, node, esKeystoreUtil, 'add-file', key, srcFileName)
382+
t.doFirst {
383+
File srcFile = project.file(srcFileName)
384+
if (srcFile.isDirectory()) {
385+
throw new GradleException("Source for keystoreFile must be a file: ${srcFile}")
386+
}
387+
if (srcFile.exists() == false) {
388+
throw new GradleException("Source file for keystoreFile does not exist: ${srcFile}")
389+
}
390+
}
391+
parentTask = t
392+
}
393+
return parentTask
394+
}
395+
364396
static Task configureExtraConfigFilesTask(String name, Project project, Task setup, NodeInfo node) {
365397
if (node.config.extraConfigFiles.isEmpty()) {
366398
return setup

distribution/bwc/build.gradle

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ subprojects {
5454

5555
final String remote = System.getProperty("tests.bwc.remote", "elastic")
5656

57+
final boolean gitFetchLatest
58+
final String gitFetchLatestProperty = System.getProperty("tests.bwc.git_fetch_latest", "true")
59+
if ("true".equals(gitFetchLatestProperty)) {
60+
gitFetchLatest = true
61+
} else if ("false".equals(gitFetchLatestProperty)) {
62+
gitFetchLatest = false
63+
} else {
64+
throw new GradleException("tests.bwc.git_fetch_latest must be [true] or [false] but was [" + gitFetchLatestProperty + "]")
65+
}
66+
5767
task createClone(type: LoggedExec) {
5868
onlyIf { checkoutDir.exists() == false }
5969
commandLine = ['git', 'clone', rootDir, checkoutDir]
@@ -83,7 +93,7 @@ subprojects {
8393
}
8494

8595
task fetchLatest(type: LoggedExec) {
86-
onlyIf { project.gradle.startParameter.isOffline() == false }
96+
onlyIf { project.gradle.startParameter.isOffline() == false && gitFetchLatest }
8797
dependsOn addRemote
8898
workingDir = checkoutDir
8999
commandLine = ['git', 'fetch', '--all']

docs/reference/docs/index_.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ The result of the above index operation is:
229229
},
230230
"_index" : "twitter",
231231
"_type" : "_doc",
232-
"_id" : "6a8ca01c-7896-48e9-81cc-9f70661fcb32",
232+
"_id" : "W0tpsmIBdwcYyG50zbta",
233233
"_version" : 1,
234234
"_seq_no" : 0,
235235
"_primary_term" : 1,
236236
"result": "created"
237237
}
238238
--------------------------------------------------
239-
// TESTRESPONSE[s/6a8ca01c-7896-48e9-81cc-9f70661fcb32/$body._id/ s/"successful" : 2/"successful" : 1/]
239+
// TESTRESPONSE[s/W0tpsmIBdwcYyG50zbta/$body._id/ s/"successful" : 2/"successful" : 1/]
240240

241241
[float]
242242
[[index-routing]]

docs/reference/setup/bootstrap-checks.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ that the Elasticsearch process has the rights to create enough threads
114114
under normal use. This check is enforced only on Linux. If you are on
115115
Linux, to pass the maximum number of threads check, you must configure
116116
your system to allow the Elasticsearch process the ability to create at
117-
least 2048 threads. This can be done via `/etc/security/limits.conf`
117+
least 4096 threads. This can be done via `/etc/security/limits.conf`
118118
using the `nproc` setting (note that you might have to increase the
119119
limits for the `root` user too).
120120

server/src/main/java/org/elasticsearch/common/unit/TimeValue.java renamed to libs/elasticsearch-core/src/main/java/org/elasticsearch/common/unit/TimeValue.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919

2020
package org.elasticsearch.common.unit;
2121

22-
import org.elasticsearch.common.xcontent.ToXContentFragment;
23-
import org.elasticsearch.common.xcontent.XContentBuilder;
24-
2522
import java.io.IOException;
2623
import java.util.Locale;
2724
import java.util.Objects;
2825
import java.util.concurrent.TimeUnit;
2926

30-
public class TimeValue implements Comparable<TimeValue>, ToXContentFragment {
27+
public class TimeValue implements Comparable<TimeValue> {
3128

3229
/** How many nano-seconds in one milli-second */
3330
public static final long NSEC_PER_MSEC = TimeUnit.NANOSECONDS.convert(1, TimeUnit.MILLISECONDS);
@@ -352,9 +349,4 @@ public int compareTo(TimeValue timeValue) {
352349
double otherValue = ((double) timeValue.duration) * timeValue.timeUnit.toNanos(1);
353350
return Double.compare(thisValue, otherValue);
354351
}
355-
356-
@Override
357-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
358-
return builder.value(toString());
359-
}
360352
}

server/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java renamed to libs/elasticsearch-core/src/test/java/org/elasticsearch/common/unit/TimeValueTests.java

-30
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@
1919

2020
package org.elasticsearch.common.unit;
2121

22-
import org.elasticsearch.common.io.stream.BytesStreamOutput;
23-
import org.elasticsearch.common.io.stream.StreamInput;
2422
import org.elasticsearch.test.ESTestCase;
2523

26-
import java.io.IOException;
2724
import java.util.concurrent.TimeUnit;
2825

29-
import static org.elasticsearch.common.unit.TimeValue.timeValueNanos;
30-
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
3126
import static org.hamcrest.CoreMatchers.instanceOf;
3227
import static org.hamcrest.CoreMatchers.not;
3328
import static org.hamcrest.Matchers.containsString;
@@ -154,31 +149,6 @@ private String randomTimeUnit() {
154149
return randomFrom("nanos", "micros", "ms", "s", "m", "h", "d");
155150
}
156151

157-
private void assertEqualityAfterSerialize(TimeValue value, int expectedSize) throws IOException {
158-
BytesStreamOutput out = new BytesStreamOutput();
159-
out.writeTimeValue(value);
160-
assertEquals(expectedSize, out.size());
161-
162-
StreamInput in = out.bytes().streamInput();
163-
TimeValue inValue = in.readTimeValue();
164-
165-
assertThat(inValue, equalTo(value));
166-
assertThat(inValue.duration(), equalTo(value.duration()));
167-
assertThat(inValue.timeUnit(), equalTo(value.timeUnit()));
168-
}
169-
170-
public void testSerialize() throws Exception {
171-
assertEqualityAfterSerialize(new TimeValue(100, TimeUnit.DAYS), 3);
172-
assertEqualityAfterSerialize(timeValueNanos(-1), 2);
173-
assertEqualityAfterSerialize(timeValueNanos(1), 2);
174-
assertEqualityAfterSerialize(timeValueSeconds(30), 2);
175-
176-
final TimeValue timeValue = new TimeValue(randomIntBetween(0, 1024), randomFrom(TimeUnit.values()));
177-
BytesStreamOutput out = new BytesStreamOutput();
178-
out.writeZLong(timeValue.duration());
179-
assertEqualityAfterSerialize(timeValue, 1 + out.bytes().length());
180-
}
181-
182152
public void testFailOnUnknownUnits() {
183153
try {
184154
TimeValue.parseTimeValue("23tw", null, "test");

plugins/repository-gcs/build.gradle

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ task createServiceAccountFile() {
9494

9595
integTestCluster {
9696
dependsOn createServiceAccountFile, googleCloudStorageFixture
97-
setupCommand 'create-elasticsearch-keystore', 'bin/elasticsearch-keystore', 'create'
98-
setupCommand 'add-credentials-to-elasticsearch-keystore',
99-
'bin/elasticsearch-keystore', 'add-file', 'gcs.client.integration_test.credentials_file', "${serviceAccountFile.absolutePath}"
97+
keystoreFile 'gcs.client.integration_test.credentials_file', "${serviceAccountFile.absolutePath}"
10098

10199
/* Use a closure on the string to delay evaluation until tests are executed */
102100
setting 'gcs.client.integration_test.endpoint', "http://${ -> googleCloudStorageFixture.addressAndPort }"

server/src/main/java/org/elasticsearch/client/Client.java

+10
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,14 @@ public interface Client extends ElasticsearchClient, Releasable {
477477
* issued from it.
478478
*/
479479
Client filterWithHeader(Map<String, String> headers);
480+
481+
/**
482+
* Returns a client to a remote cluster with the given cluster alias.
483+
*
484+
* @throws IllegalArgumentException if the given clusterAlias doesn't exist
485+
* @throws UnsupportedOperationException if this functionality is not available on this client.
486+
*/
487+
default Client getRemoteClusterClient(String clusterAlias) {
488+
throw new UnsupportedOperationException("this client doesn't support remote cluster connections");
489+
}
480490
}

server/src/main/java/org/elasticsearch/client/FilterClient.java

+5
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ protected <Request extends ActionRequest, Response extends ActionResponse, Reque
7373
protected Client in() {
7474
return in;
7575
}
76+
77+
@Override
78+
public Client getRemoteClusterClient(String clusterAlias) {
79+
return in.getRemoteClusterClient(clusterAlias);
80+
}
7681
}

server/src/main/java/org/elasticsearch/client/node/NodeClient.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.tasks.Task;
3434
import org.elasticsearch.tasks.TaskListener;
3535
import org.elasticsearch.threadpool.ThreadPool;
36+
import org.elasticsearch.transport.RemoteClusterService;
3637

3738
import java.util.Map;
3839
import java.util.function.Supplier;
@@ -48,14 +49,17 @@ public class NodeClient extends AbstractClient {
4849
* {@link #executeLocally(GenericAction, ActionRequest, TaskListener)}.
4950
*/
5051
private Supplier<String> localNodeId;
52+
private RemoteClusterService remoteClusterService;
5153

5254
public NodeClient(Settings settings, ThreadPool threadPool) {
5355
super(settings, threadPool);
5456
}
5557

56-
public void initialize(Map<GenericAction, TransportAction> actions, Supplier<String> localNodeId) {
58+
public void initialize(Map<GenericAction, TransportAction> actions, Supplier<String> localNodeId,
59+
RemoteClusterService remoteClusterService) {
5760
this.actions = actions;
5861
this.localNodeId = localNodeId;
62+
this.remoteClusterService = remoteClusterService;
5963
}
6064

6165
@Override
@@ -117,4 +121,9 @@ > TransportAction<Request, Response> transportAction(GenericAction<Request, Resp
117121
}
118122
return transportAction;
119123
}
124+
125+
@Override
126+
public Client getRemoteClusterClient(String clusterAlias) {
127+
return remoteClusterService.getRemoteClusterClient(threadPool(), clusterAlias);
128+
}
120129
}

server/src/main/java/org/elasticsearch/common/xcontent/XContentElasticsearchExtension.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public Map<Class<?>, XContentBuilder.Writer> getXContentWriters() {
6161
writers.put(FixedDateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
6262
writers.put(MutableDateTime.class, XContentBuilder::timeValue);
6363
writers.put(DateTime.class, XContentBuilder::timeValue);
64+
writers.put(TimeValue.class, (b, v) -> b.value(v.toString()));
6465

6566
writers.put(BytesReference.class, (b, v) -> {
6667
if (v == null) {

server/src/main/java/org/elasticsearch/index/IndexSettings.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public final class IndexSettings {
188188
public static final Setting<ByteSizeValue> INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING =
189189
Setting.byteSizeSetting("index.translog.flush_threshold_size", new ByteSizeValue(512, ByteSizeUnit.MB),
190190
/*
191-
* An empty translog occupies 43 bytes on disk. If the flush threshold is below this, the flush thread
191+
* An empty translog occupies 55 bytes on disk. If the flush threshold is below this, the flush thread
192192
* can get stuck in an infinite loop as the shouldPeriodicallyFlush can still be true after flushing.
193193
* However, small thresholds are useful for testing so we do not add a large lower bound here.
194194
*/
@@ -223,7 +223,7 @@ public final class IndexSettings {
223223
"index.translog.generation_threshold_size",
224224
new ByteSizeValue(64, ByteSizeUnit.MB),
225225
/*
226-
* An empty translog occupies 43 bytes on disk. If the generation threshold is
226+
* An empty translog occupies 55 bytes on disk. If the generation threshold is
227227
* below this, the flush thread can get stuck in an infinite loop repeatedly
228228
* rolling the generation as every new generation will already exceed the
229229
* generation threshold. However, small thresholds are useful for testing so we

server/src/main/java/org/elasticsearch/index/engine/Engine.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1066,14 +1066,13 @@ public Index(Term uid, ParsedDocument doc, long seqNo, long primaryTerm, long ve
10661066
this.autoGeneratedIdTimestamp = autoGeneratedIdTimestamp;
10671067
}
10681068

1069-
public Index(Term uid, ParsedDocument doc) {
1070-
this(uid, doc, Versions.MATCH_ANY);
1069+
public Index(Term uid, long primaryTerm, ParsedDocument doc) {
1070+
this(uid, primaryTerm, doc, Versions.MATCH_ANY);
10711071
} // TEST ONLY
10721072

1073-
Index(Term uid, ParsedDocument doc, long version) {
1074-
// use a primary term of 2 to allow tests to reduce it to a valid >0 term
1075-
this(uid, doc, SequenceNumbers.UNASSIGNED_SEQ_NO, 2, version, VersionType.INTERNAL,
1076-
Origin.PRIMARY, System.nanoTime(), -1, false);
1073+
Index(Term uid, long primaryTerm, ParsedDocument doc, long version) {
1074+
this(uid, doc, SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm, version, VersionType.INTERNAL,
1075+
Origin.PRIMARY, System.nanoTime(), -1, false);
10771076
} // TEST ONLY
10781077

10791078
public ParsedDocument parsedDoc() {
@@ -1147,8 +1146,8 @@ public Delete(String type, String id, Term uid, long seqNo, long primaryTerm, lo
11471146
this.id = Objects.requireNonNull(id);
11481147
}
11491148

1150-
public Delete(String type, String id, Term uid) {
1151-
this(type, id, uid, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, Versions.MATCH_ANY, VersionType.INTERNAL, Origin.PRIMARY, System.nanoTime());
1149+
public Delete(String type, String id, Term uid, long primaryTerm) {
1150+
this(type, id, uid, SequenceNumbers.UNASSIGNED_SEQ_NO, primaryTerm, Versions.MATCH_ANY, VersionType.INTERNAL, Origin.PRIMARY, System.nanoTime());
11521151
}
11531152

11541153
public Delete(Delete template, VersionType versionType) {

server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public final class EngineConfig {
7979
@Nullable
8080
private final CircuitBreakerService circuitBreakerService;
8181
private final LongSupplier globalCheckpointSupplier;
82+
private final LongSupplier primaryTermSupplier;
8283

8384
/**
8485
* Index setting to change the low level lucene codec used for writing new segments.
@@ -125,7 +126,7 @@ public EngineConfig(ShardId shardId, String allocationId, ThreadPool threadPool,
125126
List<ReferenceManager.RefreshListener> externalRefreshListener,
126127
List<ReferenceManager.RefreshListener> internalRefreshListener, Sort indexSort,
127128
TranslogRecoveryRunner translogRecoveryRunner, CircuitBreakerService circuitBreakerService,
128-
LongSupplier globalCheckpointSupplier) {
129+
LongSupplier globalCheckpointSupplier, LongSupplier primaryTermSupplier) {
129130
this.shardId = shardId;
130131
this.allocationId = allocationId;
131132
this.indexSettings = indexSettings;
@@ -152,6 +153,7 @@ public EngineConfig(ShardId shardId, String allocationId, ThreadPool threadPool,
152153
this.translogRecoveryRunner = translogRecoveryRunner;
153154
this.circuitBreakerService = circuitBreakerService;
154155
this.globalCheckpointSupplier = globalCheckpointSupplier;
156+
this.primaryTermSupplier = primaryTermSupplier;
155157
}
156158

157159
/**
@@ -354,4 +356,11 @@ public Sort getIndexSort() {
354356
public CircuitBreakerService getCircuitBreakerService() {
355357
return this.circuitBreakerService;
356358
}
359+
360+
/**
361+
* Returns a supplier that supplies the latest primary term value of the associated shard.
362+
*/
363+
public LongSupplier getPrimaryTermSupplier() {
364+
return primaryTermSupplier;
365+
}
357366
}

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private Translog openTranslog(EngineConfig engineConfig, TranslogDeletionPolicy
432432
translogDeletionPolicy.setMinTranslogGenerationForRecovery(minRequiredTranslogGen);
433433
}
434434
// We expect that this shard already exists, so it must already have an existing translog else something is badly wrong!
435-
return new Translog(translogConfig, translogUUID, translogDeletionPolicy, globalCheckpointSupplier);
435+
return new Translog(translogConfig, translogUUID, translogDeletionPolicy, globalCheckpointSupplier, engineConfig.getPrimaryTermSupplier());
436436
}
437437

438438
@Override

0 commit comments

Comments
 (0)