Merge branch 'master' into feature/ingest
This commit is contained in:
commit
9ec2e140b8
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.SuppressForbidden;
|
|||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
|
||||
|
@ -286,7 +285,8 @@ public class Version {
|
|||
public static final Version CURRENT = V_3_0_0;
|
||||
|
||||
static {
|
||||
assert CURRENT.luceneVersion.equals(Lucene.VERSION) : "Version must be upgraded to [" + Lucene.VERSION + "] is still set to [" + CURRENT.luceneVersion + "]";
|
||||
assert CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) : "Version must be upgraded to ["
|
||||
+ org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]";
|
||||
}
|
||||
|
||||
public static Version readVersion(StreamInput in) throws IOException {
|
||||
|
@ -457,7 +457,6 @@ public class Version {
|
|||
return V_0_90_0_RC1;
|
||||
case V_0_90_0_Beta1_ID:
|
||||
return V_0_90_0_Beta1;
|
||||
|
||||
case V_0_20_7_ID:
|
||||
return V_0_20_7;
|
||||
case V_0_20_6_ID:
|
||||
|
@ -476,7 +475,6 @@ public class Version {
|
|||
return V_0_20_0;
|
||||
case V_0_20_0_RC1_ID:
|
||||
return V_0_20_0_RC1;
|
||||
|
||||
case V_0_19_0_RC1_ID:
|
||||
return V_0_19_0_RC1;
|
||||
case V_0_19_0_RC2_ID:
|
||||
|
@ -511,7 +509,6 @@ public class Version {
|
|||
return V_0_19_12;
|
||||
case V_0_19_13_ID:
|
||||
return V_0_19_13;
|
||||
|
||||
case V_0_18_0_ID:
|
||||
return V_0_18_0;
|
||||
case V_0_18_1_ID:
|
||||
|
@ -530,9 +527,8 @@ public class Version {
|
|||
return V_0_18_7;
|
||||
case V_0_18_8_ID:
|
||||
return V_0_18_8;
|
||||
|
||||
default:
|
||||
return new Version(id, false, Lucene.VERSION);
|
||||
return new Version(id, false, org.apache.lucene.util.Version.LATEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface AliasesRequest extends IndicesRequest.Replaceable {
|
|||
/**
|
||||
* Sets the array of aliases that the action relates to
|
||||
*/
|
||||
AliasesRequest aliases(String[] aliases);
|
||||
AliasesRequest aliases(String... aliases);
|
||||
|
||||
/**
|
||||
* Returns true if wildcards expressions among aliases should be resolved, false otherwise
|
||||
|
|
|
@ -41,9 +41,9 @@ public interface IndicesRequest {
|
|||
IndicesOptions indicesOptions();
|
||||
|
||||
static interface Replaceable extends IndicesRequest {
|
||||
/*
|
||||
* Sets the array of indices that the action relates to
|
||||
/**
|
||||
* Sets the indices that the action relates to.
|
||||
*/
|
||||
IndicesRequest indices(String[] indices);
|
||||
IndicesRequest indices(String... indices);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClusterHealthRequest indices(String[] indices) {
|
||||
public ClusterHealthRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class IndicesExistsRequest extends MasterNodeReadRequest<IndicesExistsReq
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndicesExistsRequest indices(String[] indices) {
|
||||
public IndicesExistsRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class TypesExistsRequest extends MasterNodeReadRequest<TypesExistsRequest
|
|||
}
|
||||
|
||||
@Override
|
||||
public TypesExistsRequest indices(String[] indices) {
|
||||
public TypesExistsRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.admin.indices.mapping.put;
|
||||
|
||||
import com.carrotsearch.hppc.ObjectHashSet;
|
||||
|
||||
import org.elasticsearch.ElasticsearchGenerationException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.IndicesRequest;
|
||||
|
@ -96,7 +97,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
|
|||
* Sets the indices this put mapping operation will execute on.
|
||||
*/
|
||||
@Override
|
||||
public PutMappingRequest indices(String[] indices) {
|
||||
public PutMappingRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class PutWarmerRequest extends AcknowledgedRequest<PutWarmerRequest> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndicesRequest indices(String[] indices) {
|
||||
public IndicesRequest indices(String... indices) {
|
||||
if (searchRequest == null) {
|
||||
throw new IllegalStateException("unable to set indices, search request is null");
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ import org.elasticsearch.action.ActionRunnable;
|
|||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.HandledTransportAction;
|
||||
import org.elasticsearch.action.support.ThreadedActionListener;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateObserver;
|
||||
import org.elasticsearch.cluster.MasterNodeChangePredicate;
|
||||
import org.elasticsearch.cluster.NotMasterException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
|
@ -51,20 +51,6 @@ import java.util.function.Supplier;
|
|||
* A base class for operations that needs to be performed on the master node.
|
||||
*/
|
||||
public abstract class TransportMasterNodeAction<Request extends MasterNodeRequest, Response extends ActionResponse> extends HandledTransportAction<Request, Response> {
|
||||
private static final ClusterStateObserver.ChangePredicate masterNodeChangedPredicate = new ClusterStateObserver.ChangePredicate() {
|
||||
@Override
|
||||
public boolean apply(ClusterState previousState, ClusterState.ClusterStateStatus previousStatus,
|
||||
ClusterState newState, ClusterState.ClusterStateStatus newStatus) {
|
||||
// The condition !newState.nodes().masterNodeId().equals(previousState.nodes().masterNodeId()) is not sufficient as the same master node might get reelected after a disruption.
|
||||
return newState.nodes().masterNodeId() != null && newState != previousState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ClusterChangedEvent event) {
|
||||
return event.nodesDelta().masterNodeChanged();
|
||||
}
|
||||
};
|
||||
|
||||
protected final TransportService transportService;
|
||||
protected final ClusterService clusterService;
|
||||
|
||||
|
@ -164,7 +150,7 @@ public abstract class TransportMasterNodeAction<Request extends MasterNodeReques
|
|||
if (t instanceof Discovery.FailedToCommitClusterStateException
|
||||
|| (t instanceof NotMasterException)) {
|
||||
logger.debug("master could not publish cluster state or stepped down before publishing action [{}], scheduling a retry", t, actionName);
|
||||
retry(t, masterNodeChangedPredicate);
|
||||
retry(t, MasterNodeChangePredicate.INSTANCE);
|
||||
} else {
|
||||
listener.onFailure(t);
|
||||
}
|
||||
|
@ -180,7 +166,7 @@ public abstract class TransportMasterNodeAction<Request extends MasterNodeReques
|
|||
} else {
|
||||
if (nodes.masterNode() == null) {
|
||||
logger.debug("no known master node, scheduling a retry");
|
||||
retry(null, masterNodeChangedPredicate);
|
||||
retry(null, MasterNodeChangePredicate.INSTANCE);
|
||||
} else {
|
||||
transportService.sendRequest(nodes.masterNode(), actionName, request, new ActionListenerResponseHandler<Response>(listener) {
|
||||
@Override
|
||||
|
@ -195,7 +181,7 @@ public abstract class TransportMasterNodeAction<Request extends MasterNodeReques
|
|||
// we want to retry here a bit to see if a new master is elected
|
||||
logger.debug("connection exception while trying to forward request with action name [{}] to master node [{}], scheduling a retry. Error: [{}]",
|
||||
actionName, nodes.masterNode(), exp.getDetailedMessage());
|
||||
retry(cause, masterNodeChangedPredicate);
|
||||
retry(cause, MasterNodeChangePredicate.INSTANCE);
|
||||
} else {
|
||||
listener.onFailure(exp);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.cluster;
|
||||
|
||||
public enum MasterNodeChangePredicate implements ClusterStateObserver.ChangePredicate {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public boolean apply(
|
||||
ClusterState previousState,
|
||||
ClusterState.ClusterStateStatus previousStatus,
|
||||
ClusterState newState,
|
||||
ClusterState.ClusterStateStatus newStatus) {
|
||||
// checking if the masterNodeId changed is insufficient as the
|
||||
// same master node might get re-elected after a disruption
|
||||
return newState.nodes().masterNodeId() != null && newState != previousState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ClusterChangedEvent changedEvent) {
|
||||
return changedEvent.nodesDelta().masterNodeChanged();
|
||||
}
|
||||
}
|
|
@ -86,11 +86,6 @@ import java.util.Objects;
|
|||
*
|
||||
*/
|
||||
public class Lucene {
|
||||
|
||||
// TODO: remove VERSION, and have users use Version.LATEST.
|
||||
public static final Version VERSION = Version.LATEST;
|
||||
public static final Version ANALYZER_VERSION = VERSION;
|
||||
public static final Version QUERYPARSER_VERSION = VERSION;
|
||||
public static final String LATEST_DOC_VALUES_FORMAT = "Lucene54";
|
||||
public static final String LATEST_POSTINGS_FORMAT = "Lucene50";
|
||||
public static final String LATEST_CODEC = "Lucene54";
|
||||
|
@ -109,7 +104,6 @@ public class Lucene {
|
|||
|
||||
public static final TopDocs EMPTY_TOP_DOCS = new TopDocs(0, EMPTY_SCORE_DOCS, 0.0f);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Version parseVersion(@Nullable String version, Version defaultVersion, ESLogger logger) {
|
||||
if (version == null) {
|
||||
return defaultVersion;
|
||||
|
|
|
@ -89,12 +89,12 @@ public class Analysis {
|
|||
// check for explicit version on the specific analyzer component
|
||||
String sVersion = settings.get("version");
|
||||
if (sVersion != null) {
|
||||
return Lucene.parseVersion(sVersion, Lucene.ANALYZER_VERSION, logger);
|
||||
return Lucene.parseVersion(sVersion, Version.LATEST, logger);
|
||||
}
|
||||
// check for explicit version on the index itself as default for all analysis components
|
||||
sVersion = indexSettings.get("index.analysis.version");
|
||||
if (sVersion != null) {
|
||||
return Lucene.parseVersion(sVersion, Lucene.ANALYZER_VERSION, logger);
|
||||
return Lucene.parseVersion(sVersion, Version.LATEST, logger);
|
||||
}
|
||||
// resolve the analysis version based on the version the index was created with
|
||||
return org.elasticsearch.Version.indexCreated(indexSettings).luceneVersion;
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.cluster.service.InternalClusterService;
|
|||
import org.elasticsearch.cluster.service.PendingClusterTask;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -51,9 +52,12 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -61,6 +65,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
|
@ -796,7 +801,92 @@ public class ClusterServiceIT extends ESIntegTestCase {
|
|||
assertTrue(published.get());
|
||||
}
|
||||
|
||||
public void testClusterStateBatchedUpdates() throws InterruptedException {
|
||||
// test that for a single thread, tasks are executed in the order
|
||||
// that they are submitted
|
||||
public void testClusterStateUpdateTasksAreExecutedInOrder() throws BrokenBarrierException, InterruptedException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("discovery.type", "local")
|
||||
.build();
|
||||
internalCluster().startNode(settings);
|
||||
ClusterService clusterService = internalCluster().getInstance(ClusterService.class);
|
||||
|
||||
class TaskExecutor implements ClusterStateTaskExecutor<Integer> {
|
||||
List<Integer> tasks = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public BatchResult<Integer> execute(ClusterState currentState, List<Integer> tasks) throws Exception {
|
||||
this.tasks.addAll(tasks);
|
||||
return BatchResult.<Integer>builder().successes(tasks).build(ClusterState.builder(currentState).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runOnlyOnMaster() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int numberOfThreads = randomIntBetween(2, 8);
|
||||
TaskExecutor[] executors = new TaskExecutor[numberOfThreads];
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
executors[i] = new TaskExecutor();
|
||||
}
|
||||
|
||||
int tasksSubmittedPerThread = randomIntBetween(2, 1024);
|
||||
|
||||
CopyOnWriteArrayList<Tuple<String, Throwable>> failures = new CopyOnWriteArrayList<>();
|
||||
CountDownLatch updateLatch = new CountDownLatch(numberOfThreads * tasksSubmittedPerThread);
|
||||
|
||||
ClusterStateTaskListener listener = new ClusterStateTaskListener() {
|
||||
@Override
|
||||
public void onFailure(String source, Throwable t) {
|
||||
logger.error("unexpected failure: [{}]", t, source);
|
||||
failures.add(new Tuple<>(source, t));
|
||||
updateLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
|
||||
updateLatch.countDown();
|
||||
}
|
||||
};
|
||||
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
final int index = i;
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
barrier.await();
|
||||
for (int j = 0; j < tasksSubmittedPerThread; j++) {
|
||||
clusterService.submitStateUpdateTask("[" + index + "][" + j + "]", j, ClusterStateTaskConfig.build(randomFrom(Priority.values())), executors[index], listener);
|
||||
}
|
||||
barrier.await();
|
||||
} catch (InterruptedException | BrokenBarrierException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
// wait for all threads to be ready
|
||||
barrier.await();
|
||||
// wait for all threads to finish
|
||||
barrier.await();
|
||||
|
||||
updateLatch.await();
|
||||
|
||||
assertThat(failures, empty());
|
||||
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
assertEquals(tasksSubmittedPerThread, executors[i].tasks.size());
|
||||
for (int j = 0; j < tasksSubmittedPerThread; j++) {
|
||||
assertNotNull(executors[i].tasks.get(j));
|
||||
assertEquals("cluster state update task executed out of order", j, (int)executors[i].tasks.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testClusterStateBatchedUpdates() throws BrokenBarrierException, InterruptedException {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("discovery.type", "local")
|
||||
.build();
|
||||
|
@ -884,19 +974,12 @@ public class ClusterServiceIT extends ESIntegTestCase {
|
|||
counts.merge(executor, 1, (previous, one) -> previous + one);
|
||||
}
|
||||
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch endGate = new CountDownLatch(numberOfThreads);
|
||||
AtomicBoolean interrupted = new AtomicBoolean();
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
final int index = i;
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
startGate.await();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted.set(true);
|
||||
return;
|
||||
}
|
||||
barrier.await();
|
||||
for (int j = 0; j < tasksSubmittedPerThread; j++) {
|
||||
ClusterStateTaskExecutor<Task> executor = assignments.get(index * tasksSubmittedPerThread + j);
|
||||
clusterService.submitStateUpdateTask(
|
||||
|
@ -906,16 +989,18 @@ public class ClusterServiceIT extends ESIntegTestCase {
|
|||
executor,
|
||||
listener);
|
||||
}
|
||||
} finally {
|
||||
endGate.countDown();
|
||||
barrier.await();
|
||||
} catch (BrokenBarrierException | InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
startGate.countDown();
|
||||
endGate.await();
|
||||
assertFalse(interrupted.get());
|
||||
// wait for all threads to be ready
|
||||
barrier.await();
|
||||
// wait for all threads to finish
|
||||
barrier.await();
|
||||
|
||||
// wait until all the cluster state updates have been processed
|
||||
updateLatch.await();
|
||||
|
|
|
@ -31,7 +31,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
@ -42,6 +45,8 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class CacheTests extends ESTestCase {
|
||||
private int numberOfEntries;
|
||||
|
@ -483,7 +488,7 @@ public class CacheTests extends ESTestCase {
|
|||
return value;
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
fail(e.getMessage());
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < numberOfEntries; i++) {
|
||||
|
@ -491,25 +496,21 @@ public class CacheTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testComputeIfAbsentCallsOnce() throws InterruptedException {
|
||||
public void testComputeIfAbsentCallsOnce() throws BrokenBarrierException, InterruptedException {
|
||||
int numberOfThreads = randomIntBetween(2, 32);
|
||||
final Cache<Integer, String> cache = CacheBuilder.<Integer, String>builder().build();
|
||||
AtomicReferenceArray flags = new AtomicReferenceArray(numberOfEntries);
|
||||
for (int j = 0; j < numberOfEntries; j++) {
|
||||
flags.set(j, false);
|
||||
}
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch endGate = new CountDownLatch(numberOfThreads);
|
||||
AtomicBoolean interrupted = new AtomicBoolean();
|
||||
|
||||
CopyOnWriteArrayList<ExecutionException> failures = new CopyOnWriteArrayList<>();
|
||||
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
startGate.await();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted.set(true);
|
||||
return;
|
||||
}
|
||||
barrier.await();
|
||||
for (int j = 0; j < numberOfEntries; j++) {
|
||||
try {
|
||||
cache.computeIfAbsent(j, key -> {
|
||||
|
@ -517,18 +518,24 @@ public class CacheTests extends ESTestCase {
|
|||
return Integer.toString(key);
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
failures.add(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
endGate.countDown();
|
||||
barrier.await();
|
||||
} catch (BrokenBarrierException | InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
startGate.countDown();
|
||||
endGate.await();
|
||||
assertFalse(interrupted.get());
|
||||
|
||||
// wait for all threads to be ready
|
||||
barrier.await();
|
||||
// wait for all threads to finish
|
||||
barrier.await();
|
||||
|
||||
assertThat(failures, is(empty()));
|
||||
}
|
||||
|
||||
public void testComputeIfAbsentThrowsExceptionIfLoaderReturnsANullValue() {
|
||||
|
@ -541,7 +548,7 @@ public class CacheTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testDependentKeyDeadlock() throws InterruptedException {
|
||||
public void testDependentKeyDeadlock() throws BrokenBarrierException, InterruptedException {
|
||||
class Key {
|
||||
private final int key;
|
||||
|
||||
|
@ -568,18 +575,19 @@ public class CacheTests extends ESTestCase {
|
|||
|
||||
int numberOfThreads = randomIntBetween(2, 32);
|
||||
final Cache<Key, Integer> cache = CacheBuilder.<Key, Integer>builder().build();
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
|
||||
CopyOnWriteArrayList<ExecutionException> failures = new CopyOnWriteArrayList<>();
|
||||
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
CountDownLatch deadlockLatch = new CountDownLatch(numberOfThreads);
|
||||
AtomicBoolean interrupted = new AtomicBoolean();
|
||||
List<Thread> threads = new ArrayList<>();
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
startGate.await();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted.set(true);
|
||||
return;
|
||||
barrier.await();
|
||||
} catch (BrokenBarrierException | InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
Random random = new Random(random().nextLong());
|
||||
for (int j = 0; j < numberOfEntries; j++) {
|
||||
|
@ -594,7 +602,8 @@ public class CacheTests extends ESTestCase {
|
|||
}
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
fail(e.getMessage());
|
||||
failures.add(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -631,7 +640,7 @@ public class CacheTests extends ESTestCase {
|
|||
}, 1, 1, TimeUnit.SECONDS);
|
||||
|
||||
// everything is setup, release the hounds
|
||||
startGate.countDown();
|
||||
barrier.await();
|
||||
|
||||
// wait for either deadlock to be detected or the threads to terminate
|
||||
deadlockLatch.await();
|
||||
|
@ -639,24 +648,21 @@ public class CacheTests extends ESTestCase {
|
|||
// shutdown the watchdog service
|
||||
scheduler.shutdown();
|
||||
|
||||
assertThat(failures, is(empty()));
|
||||
|
||||
assertFalse("deadlock", deadlock.get());
|
||||
}
|
||||
|
||||
public void testCachePollution() throws InterruptedException {
|
||||
public void testCachePollution() throws BrokenBarrierException, InterruptedException {
|
||||
int numberOfThreads = randomIntBetween(2, 32);
|
||||
final Cache<Integer, String> cache = CacheBuilder.<Integer, String>builder().build();
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch endGate = new CountDownLatch(numberOfThreads);
|
||||
AtomicBoolean interrupted = new AtomicBoolean();
|
||||
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
startGate.await();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted.set(true);
|
||||
return;
|
||||
}
|
||||
barrier.await();
|
||||
Random random = new Random(random().nextLong());
|
||||
for (int j = 0; j < numberOfEntries; j++) {
|
||||
Integer key = random.nextInt(numberOfEntries);
|
||||
|
@ -686,21 +692,23 @@ public class CacheTests extends ESTestCase {
|
|||
cache.get(key);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
endGate.countDown();
|
||||
barrier.await();
|
||||
} catch (BrokenBarrierException | InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
startGate.countDown();
|
||||
endGate.await();
|
||||
assertFalse(interrupted.get());
|
||||
// wait for all threads to be ready
|
||||
barrier.await();
|
||||
// wait for all threads to finish
|
||||
barrier.await();
|
||||
}
|
||||
|
||||
// test that the cache is not corrupted under lots of concurrent modifications, even hitting the same key
|
||||
// here be dragons: this test did catch one subtle bug during development; do not remove lightly
|
||||
public void testTorture() throws InterruptedException {
|
||||
public void testTorture() throws BrokenBarrierException, InterruptedException {
|
||||
int numberOfThreads = randomIntBetween(2, 32);
|
||||
final Cache<Integer, String> cache =
|
||||
CacheBuilder.<Integer, String>builder()
|
||||
|
@ -708,32 +716,28 @@ public class CacheTests extends ESTestCase {
|
|||
.weigher((k, v) -> 2)
|
||||
.build();
|
||||
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch endGate = new CountDownLatch(numberOfThreads);
|
||||
AtomicBoolean interrupted = new AtomicBoolean();
|
||||
CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads);
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
try {
|
||||
startGate.await();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted.set(true);
|
||||
return;
|
||||
}
|
||||
barrier.await();
|
||||
Random random = new Random(random().nextLong());
|
||||
for (int j = 0; j < numberOfEntries; j++) {
|
||||
Integer key = random.nextInt(numberOfEntries);
|
||||
cache.put(key, Integer.toString(j));
|
||||
}
|
||||
} finally {
|
||||
endGate.countDown();
|
||||
barrier.await();
|
||||
} catch (BrokenBarrierException | InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
startGate.countDown();
|
||||
endGate.await();
|
||||
assertFalse(interrupted.get());
|
||||
|
||||
// wait for all threads to be ready
|
||||
barrier.await();
|
||||
// wait for all threads to finish
|
||||
barrier.await();
|
||||
|
||||
cache.refresh();
|
||||
assertEquals(500, cache.count());
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.lucene.search.TermQuery;
|
|||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.MMapDirectory;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -54,14 +53,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
*
|
||||
*/
|
||||
public class LuceneTests extends ESTestCase {
|
||||
/**
|
||||
* simple test that ensures that we bump the version on Upgrade
|
||||
*/
|
||||
public void testVersion() {
|
||||
// note this is just a silly sanity check, we test it in lucene, and we point to it this way
|
||||
assertEquals(Lucene.VERSION, Version.LATEST);
|
||||
}
|
||||
|
||||
public void testWaitForIndex() throws Exception {
|
||||
final MockDirectoryWrapper dir = newMockDirectory();
|
||||
|
||||
|
|
|
@ -223,6 +223,7 @@ public class RecoveryPercolatorIT extends ESIntegTestCase {
|
|||
percolatorRecovery(false);
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "sometimes reprodes with: gradle :core:integTest -Dtests.seed=21DDCAA92013B00C -Dtests.class=org.elasticsearch.percolator.RecoveryPercolatorIT -Dtests.method=\"testMultiPercolatorRecovery\"")
|
||||
public void testMultiPercolatorRecovery() throws Exception {
|
||||
percolatorRecovery(true);
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
|
|||
|
||||
logger.info("Created Random GeometryCollection containing " + gcb.numShapes() + " shapes");
|
||||
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape")
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree")
|
||||
.execute().actionGet();
|
||||
|
||||
XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
|
||||
|
@ -317,10 +317,10 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testContainsShapeQuery() throws Exception {
|
||||
// Create a random geometry collection.
|
||||
Rectangle mbr = xRandomRectangle(getRandom(), xRandomPoint(getRandom()));
|
||||
Rectangle mbr = xRandomRectangle(getRandom(), xRandomPoint(getRandom()), true);
|
||||
GeometryCollectionBuilder gcb = createGeometryCollectionWithin(getRandom(), mbr);
|
||||
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape")
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree" )
|
||||
.execute().actionGet();
|
||||
|
||||
XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
|
||||
|
@ -333,7 +333,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
|
|||
|
||||
ShapeBuilder filterShape = (gcb.getShapeAt(randomIntBetween(0, gcb.numShapes() - 1)));
|
||||
GeoShapeQueryBuilder filter = QueryBuilders.geoShapeQuery("location", filterShape)
|
||||
.relation(ShapeRelation.INTERSECTS);
|
||||
.relation(ShapeRelation.CONTAINS);
|
||||
SearchResponse response = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
|
||||
.setPostFilter(filter).get();
|
||||
assertSearchResponse(response);
|
||||
|
@ -343,7 +343,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testShapeFilterWithDefinedGeoCollection() throws Exception {
|
||||
createIndex("shapes");
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape")
|
||||
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree")
|
||||
.execute().actionGet();
|
||||
|
||||
XContentBuilder docSource = jsonBuilder().startObject().startObject("location")
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.search.highlight;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -802,9 +803,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get();
|
||||
refresh();
|
||||
indexRandom(true, client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog"));
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
|
@ -822,7 +822,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
// LUCENE 3.1 UPGRADE: Caused adding the space at the end...
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("this is a <xxx>test</xxx>"));
|
||||
|
||||
logger.info("--> searching on _all, highlighting on field2");
|
||||
|
@ -832,7 +831,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
// LUCENE 3.1 UPGRADE: Caused adding the space at the end...
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> brown fox jumps over the lazy dog"));
|
||||
|
||||
logger.info("--> searching on _all, highlighting on field2");
|
||||
|
@ -842,8 +840,26 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
// LUCENE 3.1 UPGRADE: Caused adding the space at the end...
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> brown fox jumps over the lazy dog"));
|
||||
|
||||
logger.info("--> searching with boundary characters");
|
||||
source = searchSource()
|
||||
.query(matchQuery("field2", "quick"))
|
||||
.highlighter(highlight().field("field2", 30, 1).boundaryChars(new char[] {' '}));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over"));
|
||||
|
||||
logger.info("--> searching with boundary characters on the field");
|
||||
source = searchSource()
|
||||
.query(matchQuery("field2", "quick"))
|
||||
.highlighter(highlight().field(new Field("field2").fragmentSize(30).numOfFragments(1).boundaryChars(new char[] {' '})));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -114,7 +114,7 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
|
|||
throws InvalidShapeException {
|
||||
if (numGeometries <= 0) {
|
||||
// cap geometry collection at 4 shapes (to save test time)
|
||||
numGeometries = RandomInts.randomIntBetween(r, 2, 5);
|
||||
numGeometries = RandomInts.randomIntBetween(r, 2, 4);
|
||||
}
|
||||
|
||||
if (nearPoint == null) {
|
||||
|
@ -255,11 +255,31 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
|
|||
return p;
|
||||
}
|
||||
|
||||
public static Rectangle xRandomRectangle(Random r, Point nearP) {
|
||||
Rectangle bounds = ctx.getWorldBounds();
|
||||
private static Rectangle xRandomRectangle(Random r, Point nearP, Rectangle bounds, boolean small) {
|
||||
if (nearP == null)
|
||||
nearP = xRandomPointIn(r, bounds);
|
||||
|
||||
if (small == true) {
|
||||
// between 3 and 6 degrees
|
||||
final double latRange = 3 * r.nextDouble() + 3;
|
||||
final double lonRange = 3 * r.nextDouble() + 3;
|
||||
|
||||
double minX = nearP.getX();
|
||||
double maxX = minX + lonRange;
|
||||
if (maxX > 180) {
|
||||
maxX = minX;
|
||||
minX -= lonRange;
|
||||
}
|
||||
double minY = nearP.getY();
|
||||
double maxY = nearP.getY() + latRange;
|
||||
if (maxY > 90) {
|
||||
maxY = minY;
|
||||
minY -= latRange;
|
||||
}
|
||||
|
||||
return ctx.makeRectangle(minX, maxX, minY, maxY);
|
||||
}
|
||||
|
||||
Range xRange = xRandomRange(r, rarely(r) ? 0 : nearP.getX(), Range.xRange(bounds, ctx));
|
||||
Range yRange = xRandomRange(r, rarely(r) ? 0 : nearP.getY(), Range.yRange(bounds, ctx));
|
||||
|
||||
|
@ -270,6 +290,14 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
|
|||
xDivisible(yRange.getMax()*10e3)/10e3);
|
||||
}
|
||||
|
||||
public static Rectangle xRandomRectangle(Random r, Point nearP) {
|
||||
return xRandomRectangle(r, nearP, ctx.getWorldBounds(), false);
|
||||
}
|
||||
|
||||
public static Rectangle xRandomRectangle(Random r, Point nearP, boolean small) {
|
||||
return xRandomRectangle(r, nearP, ctx.getWorldBounds(), small);
|
||||
}
|
||||
|
||||
private static boolean rarely(Random r) {
|
||||
return RandomInts.randomInt(r, 100) >= 90;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ HOSTNAME=`hostname | cut -d. -f1`
|
|||
export HOSTNAME
|
||||
|
||||
# manual parsing to find out, if process should be detached
|
||||
daemonized=`echo $* | grep -E -- '(^-d |-d$| -d |--daemonize$|--daemonize )'`
|
||||
daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'`
|
||||
if [ -z "$daemonized" ] ; then
|
||||
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \
|
||||
org.elasticsearch.bootstrap.Elasticsearch start "$@"
|
||||
|
|
|
@ -28,7 +28,7 @@ The Hadoop HDFS Repository plugin adds support for using HDFS as a repository.
|
|||
|
||||
The following plugin has been contributed by our community:
|
||||
|
||||
* https://github.com/wikimedia/search-repository-swift[Openstack Swift] (by http://en.cam4.es/youngqcmeat/Wikimedia Foundation)
|
||||
* https://github.com/wikimedia/search-repository-swift[Openstack Swift] (by Wikimedia Foundation)
|
||||
|
||||
This community plugin appears to have been abandoned:
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public class DeleteByQueryRequest extends ActionRequest<DeleteByQueryRequest> im
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeleteByQueryRequest indices(String[] indices) {
|
||||
public DeleteByQueryRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue