Remove and ban ImmutableSet#builder
This commit is contained in:
parent
4fe243a5ca
commit
6ecda41485
|
@ -380,7 +380,7 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> {
|
|||
|
||||
if (!blocks().indices().isEmpty()) {
|
||||
builder.startObject("indices");
|
||||
for (Map.Entry<String, ImmutableSet<ClusterBlock>> entry : blocks().indices().entrySet()) {
|
||||
for (Map.Entry<String, Set<ClusterBlock>> entry : blocks().indices().entrySet()) {
|
||||
builder.startObject(entry.getKey());
|
||||
for (ClusterBlock block : entry.getValue()) {
|
||||
block.toXContent(builder, params);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.cluster.block;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -28,26 +27,22 @@ import org.elasticsearch.rest.RestStatus;
|
|||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ClusterBlockException extends ElasticsearchException {
|
||||
private final Set<ClusterBlock> blocks;
|
||||
|
||||
private final ImmutableSet<ClusterBlock> blocks;
|
||||
|
||||
public ClusterBlockException(ImmutableSet<ClusterBlock> blocks) {
|
||||
public ClusterBlockException(Set<ClusterBlock> blocks) {
|
||||
super(buildMessage(blocks));
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public ClusterBlockException(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
int num = in.readVInt();
|
||||
ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
|
||||
for (int i = 0; i < num; i++) {
|
||||
builder.add(ClusterBlock.readClusterBlock(in));
|
||||
}
|
||||
blocks = builder.build();
|
||||
blocks = unmodifiableSet(in.readSet(ClusterBlock::readClusterBlock));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,11 +67,11 @@ public class ClusterBlockException extends ElasticsearchException {
|
|||
return true;
|
||||
}
|
||||
|
||||
public ImmutableSet<ClusterBlock> blocks() {
|
||||
public Set<ClusterBlock> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private static String buildMessage(ImmutableSet<ClusterBlock> blocks) {
|
||||
private static String buildMessage(Set<ClusterBlock> blocks) {
|
||||
StringBuilder sb = new StringBuilder("blocked by: ");
|
||||
for (ClusterBlock block : blocks) {
|
||||
sb.append("[").append(block.status()).append("/").append(block.id()).append("/").append(block.description()).append("];");
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.cluster.block;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import org.elasticsearch.cluster.AbstractDiffable;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
||||
|
@ -33,68 +34,68 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static java.util.stream.Stream.concat;
|
||||
|
||||
/**
|
||||
* Represents current cluster level blocks to block dirty operations done against the cluster.
|
||||
*/
|
||||
public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
||||
|
||||
public static final ClusterBlocks EMPTY_CLUSTER_BLOCK = new ClusterBlocks(ImmutableSet.<ClusterBlock>of(), ImmutableMap.<String, ImmutableSet<ClusterBlock>>of());
|
||||
public static final ClusterBlocks EMPTY_CLUSTER_BLOCK = new ClusterBlocks(emptySet(), emptyMap());
|
||||
|
||||
public static final ClusterBlocks PROTO = EMPTY_CLUSTER_BLOCK;
|
||||
|
||||
private final ImmutableSet<ClusterBlock> global;
|
||||
private final Set<ClusterBlock> global;
|
||||
|
||||
private final Map<String, ImmutableSet<ClusterBlock>> indicesBlocks;
|
||||
private final Map<String, Set<ClusterBlock>> indicesBlocks;
|
||||
|
||||
private final ImmutableLevelHolder[] levelHolders;
|
||||
|
||||
ClusterBlocks(ImmutableSet<ClusterBlock> global, Map<String, ImmutableSet<ClusterBlock>> indicesBlocks) {
|
||||
ClusterBlocks(Set<ClusterBlock> global, Map<String, Set<ClusterBlock>> indicesBlocks) {
|
||||
this.global = global;
|
||||
this.indicesBlocks = indicesBlocks;
|
||||
|
||||
levelHolders = new ImmutableLevelHolder[ClusterBlockLevel.values().length];
|
||||
for (ClusterBlockLevel level : ClusterBlockLevel.values()) {
|
||||
ImmutableSet.Builder<ClusterBlock> globalBuilder = ImmutableSet.builder();
|
||||
for (ClusterBlock block : global) {
|
||||
if (block.contains(level)) {
|
||||
globalBuilder.add(block);
|
||||
for (final ClusterBlockLevel level : ClusterBlockLevel.values()) {
|
||||
Predicate<ClusterBlock> containsLevel = block -> block.contains(level);
|
||||
Set<ClusterBlock> newGlobal = unmodifiableSet(global.stream().filter(containsLevel).collect(toSet()));
|
||||
|
||||
ImmutableMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
for (Map.Entry<String, Set<ClusterBlock>> entry : indicesBlocks.entrySet()) {
|
||||
indicesBuilder.put(entry.getKey(), unmodifiableSet(entry.getValue().stream().filter(containsLevel).collect(toSet())));
|
||||
}
|
||||
|
||||
levelHolders[level.id()] = new ImmutableLevelHolder(newGlobal, indicesBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
for (Map.Entry<String, ImmutableSet<ClusterBlock>> entry : indicesBlocks.entrySet()) {
|
||||
ImmutableSet.Builder<ClusterBlock> indexBuilder = ImmutableSet.builder();
|
||||
for (ClusterBlock block : entry.getValue()) {
|
||||
if (block.contains(level)) {
|
||||
indexBuilder.add(block);
|
||||
}
|
||||
}
|
||||
|
||||
indicesBuilder.put(entry.getKey(), indexBuilder.build());
|
||||
}
|
||||
|
||||
levelHolders[level.id()] = new ImmutableLevelHolder(globalBuilder.build(), indicesBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableSet<ClusterBlock> global() {
|
||||
public Set<ClusterBlock> global() {
|
||||
return global;
|
||||
}
|
||||
|
||||
public Map<String, ImmutableSet<ClusterBlock>> indices() {
|
||||
public Map<String, Set<ClusterBlock>> indices() {
|
||||
return indicesBlocks;
|
||||
}
|
||||
|
||||
public ImmutableSet<ClusterBlock> global(ClusterBlockLevel level) {
|
||||
public Set<ClusterBlock> global(ClusterBlockLevel level) {
|
||||
return levelHolders[level.id()].global();
|
||||
}
|
||||
|
||||
public Map<String, ImmutableSet<ClusterBlock>> indices(ClusterBlockLevel level) {
|
||||
public Map<String, Set<ClusterBlock>> indices(ClusterBlockLevel level) {
|
||||
return levelHolders[level.id()].indices();
|
||||
}
|
||||
|
||||
public Set<ClusterBlock> blocksForIndex(ClusterBlockLevel level, String index) {
|
||||
return indices(level).getOrDefault(index, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if one of the global blocks as its disable state persistence flag set.
|
||||
*/
|
||||
|
@ -165,24 +166,15 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
if (!indexBlocked(level, index)) {
|
||||
return null;
|
||||
}
|
||||
ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
|
||||
builder.addAll(global(level));
|
||||
ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index);
|
||||
if (indexBlocks != null) {
|
||||
builder.addAll(indexBlocks);
|
||||
}
|
||||
return new ClusterBlockException(builder.build());
|
||||
Stream<ClusterBlock> blocks = concat(global(level).stream(), blocksForIndex(level, index).stream());
|
||||
return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet())));
|
||||
}
|
||||
|
||||
public boolean indexBlocked(ClusterBlockLevel level, String index) {
|
||||
if (!global(level).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index);
|
||||
if (indexBlocks != null && !indexBlocks.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !blocksForIndex(level, index).isEmpty();
|
||||
}
|
||||
|
||||
public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, String[] indices) {
|
||||
|
@ -195,28 +187,22 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
if (!indexIsBlocked) {
|
||||
return null;
|
||||
}
|
||||
ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
|
||||
builder.addAll(global(level));
|
||||
for (String index : indices) {
|
||||
ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index);
|
||||
if (indexBlocks != null) {
|
||||
builder.addAll(indexBlocks);
|
||||
}
|
||||
}
|
||||
return new ClusterBlockException(builder.build());
|
||||
Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(level, index).stream();
|
||||
Stream<ClusterBlock> blocks = concat(global(level).stream(), Stream.of(indices).flatMap(blocksForIndexAtLevel));
|
||||
return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
writeBlockSet(global, out);
|
||||
out.writeVInt(indicesBlocks.size());
|
||||
for (Map.Entry<String, ImmutableSet<ClusterBlock>> entry : indicesBlocks.entrySet()) {
|
||||
for (Map.Entry<String, Set<ClusterBlock>> entry : indicesBlocks.entrySet()) {
|
||||
out.writeString(entry.getKey());
|
||||
writeBlockSet(entry.getValue(), out);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeBlockSet(ImmutableSet<ClusterBlock> blocks, StreamOutput out) throws IOException {
|
||||
private static void writeBlockSet(Set<ClusterBlock> blocks, StreamOutput out) throws IOException {
|
||||
out.writeVInt(blocks.size());
|
||||
for (ClusterBlock block : blocks) {
|
||||
block.writeTo(out);
|
||||
|
@ -225,8 +211,8 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
|
||||
@Override
|
||||
public ClusterBlocks readFrom(StreamInput in) throws IOException {
|
||||
ImmutableSet<ClusterBlock> global = readBlockSet(in);
|
||||
ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
Set<ClusterBlock> global = readBlockSet(in);
|
||||
ImmutableMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
int size = in.readVInt();
|
||||
for (int j = 0; j < size; j++) {
|
||||
indicesBuilder.put(in.readString().intern(), readBlockSet(in));
|
||||
|
@ -234,32 +220,27 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
return new ClusterBlocks(global, indicesBuilder.build());
|
||||
}
|
||||
|
||||
private static ImmutableSet<ClusterBlock> readBlockSet(StreamInput in) throws IOException {
|
||||
ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.add(ClusterBlock.readClusterBlock(in));
|
||||
}
|
||||
return builder.build();
|
||||
private static Set<ClusterBlock> readBlockSet(StreamInput in) throws IOException {
|
||||
return unmodifiableSet(in.readSet(ClusterBlock::readClusterBlock));
|
||||
}
|
||||
|
||||
static class ImmutableLevelHolder {
|
||||
|
||||
static final ImmutableLevelHolder EMPTY = new ImmutableLevelHolder(ImmutableSet.<ClusterBlock>of(), ImmutableMap.<String, ImmutableSet<ClusterBlock>>of());
|
||||
static final ImmutableLevelHolder EMPTY = new ImmutableLevelHolder(emptySet(), ImmutableMap.of());
|
||||
|
||||
private final ImmutableSet<ClusterBlock> global;
|
||||
private final ImmutableMap<String, ImmutableSet<ClusterBlock>> indices;
|
||||
private final Set<ClusterBlock> global;
|
||||
private final ImmutableMap<String, Set<ClusterBlock>> indices;
|
||||
|
||||
ImmutableLevelHolder(ImmutableSet<ClusterBlock> global, ImmutableMap<String, ImmutableSet<ClusterBlock>> indices) {
|
||||
ImmutableLevelHolder(Set<ClusterBlock> global, ImmutableMap<String, Set<ClusterBlock>> indices) {
|
||||
this.global = global;
|
||||
this.indices = indices;
|
||||
}
|
||||
|
||||
public ImmutableSet<ClusterBlock> global() {
|
||||
public Set<ClusterBlock> global() {
|
||||
return global;
|
||||
}
|
||||
|
||||
public ImmutableMap<String, ImmutableSet<ClusterBlock>> indices() {
|
||||
public ImmutableMap<String, Set<ClusterBlock>> indices() {
|
||||
return indices;
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +260,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
|
||||
public Builder blocks(ClusterBlocks blocks) {
|
||||
global.addAll(blocks.global());
|
||||
for (Map.Entry<String, ImmutableSet<ClusterBlock>> entry : blocks.indices().entrySet()) {
|
||||
for (Map.Entry<String, Set<ClusterBlock>> entry : blocks.indices().entrySet()) {
|
||||
if (!indices.containsKey(entry.getKey())) {
|
||||
indices.put(entry.getKey(), new HashSet<>());
|
||||
}
|
||||
|
@ -345,11 +326,12 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
|||
}
|
||||
|
||||
public ClusterBlocks build() {
|
||||
ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
// We copy the block sets here in case of the builder is modified after build is called
|
||||
ImmutableMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableMap.builder();
|
||||
for (Map.Entry<String, Set<ClusterBlock>> entry : indices.entrySet()) {
|
||||
indicesBuilder.put(entry.getKey(), ImmutableSet.copyOf(entry.getValue()));
|
||||
indicesBuilder.put(entry.getKey(), unmodifiableSet(new HashSet<>(entry.getValue())));
|
||||
}
|
||||
return new ClusterBlocks(ImmutableSet.copyOf(global), indicesBuilder.build());
|
||||
return new ClusterBlocks(unmodifiableSet(new HashSet<>(global)), indicesBuilder.build());
|
||||
}
|
||||
|
||||
public static ClusterBlocks readClusterBlocks(StreamInput in) throws IOException {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.elasticsearch.common.inject;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.inject.internal.ConstructionContext;
|
||||
import org.elasticsearch.common.inject.internal.Errors;
|
||||
import org.elasticsearch.common.inject.internal.ErrorsException;
|
||||
|
@ -24,6 +23,7 @@ import org.elasticsearch.common.inject.internal.InternalContext;
|
|||
import org.elasticsearch.common.inject.spi.InjectionPoint;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Creates instances using an injectable constructor. After construction, all injectable fields and
|
||||
|
@ -33,12 +33,12 @@ import java.lang.reflect.InvocationTargetException;
|
|||
*/
|
||||
class ConstructorInjector<T> {
|
||||
|
||||
private final ImmutableSet<InjectionPoint> injectableMembers;
|
||||
private final Set<InjectionPoint> injectableMembers;
|
||||
private final SingleParameterInjector<?>[] parameterInjectors;
|
||||
private final ConstructionProxy<T> constructionProxy;
|
||||
private final MembersInjectorImpl<T> membersInjector;
|
||||
|
||||
ConstructorInjector(ImmutableSet<InjectionPoint> injectableMembers,
|
||||
ConstructorInjector(Set<InjectionPoint> injectableMembers,
|
||||
ConstructionProxy<T> constructionProxy,
|
||||
SingleParameterInjector<?>[] parameterInjectors,
|
||||
MembersInjectorImpl<T> membersInjector)
|
||||
|
@ -49,7 +49,7 @@ class ConstructorInjector<T> {
|
|||
this.membersInjector = membersInjector;
|
||||
}
|
||||
|
||||
public ImmutableSet<InjectionPoint> getInjectableMembers() {
|
||||
public Set<InjectionPoint> getInjectableMembers() {
|
||||
return injectableMembers;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.elasticsearch.common.inject;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.inject.internal.Errors;
|
||||
import org.elasticsearch.common.inject.internal.ErrorsException;
|
||||
import org.elasticsearch.common.inject.internal.InternalContext;
|
||||
|
@ -24,6 +23,10 @@ import org.elasticsearch.common.inject.spi.InjectionListener;
|
|||
import org.elasticsearch.common.inject.spi.InjectionPoint;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
/**
|
||||
* Injects members of instances of a given type.
|
||||
|
@ -112,11 +115,7 @@ class MembersInjectorImpl<T> implements MembersInjector<T> {
|
|||
return "MembersInjector<" + typeLiteral + ">";
|
||||
}
|
||||
|
||||
public ImmutableSet<InjectionPoint> getInjectionPoints() {
|
||||
ImmutableSet.Builder<InjectionPoint> builder = ImmutableSet.builder();
|
||||
for (SingleMemberInjector memberInjector : memberInjectors) {
|
||||
builder.add(memberInjector.getInjectionPoint());
|
||||
}
|
||||
return builder.build();
|
||||
public Set<InjectionPoint> getInjectionPoints() {
|
||||
return unmodifiableSet(memberInjectors.stream().map(SingleMemberInjector::getInjectionPoint).collect(toSet()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,22 @@ import org.elasticsearch.common.text.Text;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.elasticsearch.ElasticsearchException.readException;
|
||||
import static org.elasticsearch.ElasticsearchException.readStackTrace;
|
||||
|
@ -470,6 +483,18 @@ public abstract class StreamInput extends InputStream {
|
|||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a set using reader to decode the set elements.
|
||||
*/
|
||||
public <T> Set<T> readSet(ObjectReader<T> reader) throws IOException {
|
||||
int num = readVInt();
|
||||
Set<T> builder = new HashSet<>(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
builder.add(reader.read(this));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes a potential null value.
|
||||
*/
|
||||
|
@ -575,4 +600,12 @@ public abstract class StreamInput extends InputStream {
|
|||
public static StreamInput wrap(byte[] bytes, int offset, int length) {
|
||||
return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length));
|
||||
}
|
||||
|
||||
/**
|
||||
* FunctionalInterface for methods that read an object from the stream.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public static interface ObjectReader<T> {
|
||||
public T read(StreamInput in) throws IOException;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,19 @@ public final class Sets {
|
|||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new HashSet copying the original set with elements added. Useful
|
||||
* for initializing constants without static blocks.
|
||||
*/
|
||||
public static <T> HashSet<T> newHashSetCopyWith(Set<T> original, T... elements) {
|
||||
Objects.requireNonNull(original);
|
||||
Objects.requireNonNull(elements);
|
||||
HashSet<T> set = new HashSet<>(original.size() + elements.length);
|
||||
set.addAll(original);
|
||||
Collections.addAll(set, elements);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static <T> Set<T> newConcurrentHashSet() {
|
||||
return Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
}
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
|
||||
package org.elasticsearch.env;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.SegmentInfos;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.Lock;
|
||||
import org.apache.lucene.store.LockObtainFailedException;
|
||||
import org.apache.lucene.store.NativeFSLockFactory;
|
||||
import org.apache.lucene.store.SimpleFSDirectory;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -42,12 +46,27 @@ import org.elasticsearch.monitor.fs.FsProbe;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileStore;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
* A component that holds all data paths for a single node.
|
||||
*/
|
||||
|
@ -507,12 +526,11 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all currently lock shards
|
||||
* Returns all currently lock shards.
|
||||
*/
|
||||
public Set<ShardId> lockedShards() {
|
||||
synchronized (shardLocks) {
|
||||
ImmutableSet.Builder<ShardId> builder = ImmutableSet.builder();
|
||||
return builder.addAll(shardLocks.keySet()).build();
|
||||
return unmodifiableSet(new HashSet<>(shardLocks.keySet()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -60,7 +63,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
|
|||
@Nullable
|
||||
private volatile MetaData previousMetaData;
|
||||
|
||||
private volatile ImmutableSet<String> previouslyWrittenIndices = ImmutableSet.of();
|
||||
private volatile Set<String> previouslyWrittenIndices = emptySet();
|
||||
|
||||
@Inject
|
||||
public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService,
|
||||
|
@ -126,17 +129,18 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
|
|||
// persistence was disabled or the node was restarted), see getRelevantIndicesOnDataOnlyNode().
|
||||
// we therefore have to check here if we have shards on disk and add their indices to the previouslyWrittenIndices list
|
||||
if (isDataOnlyNode(state)) {
|
||||
ImmutableSet.Builder<String> previouslyWrittenIndicesBuilder = ImmutableSet.builder();
|
||||
Set<String> newPreviouslyWrittenIndices = new HashSet<>(previouslyWrittenIndices.size());
|
||||
for (IndexMetaData indexMetaData : newMetaData) {
|
||||
IndexMetaData indexMetaDataOnDisk = null;
|
||||
if (indexMetaData.state().equals(IndexMetaData.State.CLOSE)) {
|
||||
indexMetaDataOnDisk = metaStateService.loadIndexState(indexMetaData.index());
|
||||
}
|
||||
if (indexMetaDataOnDisk != null) {
|
||||
previouslyWrittenIndicesBuilder.add(indexMetaDataOnDisk.index());
|
||||
newPreviouslyWrittenIndices.add(indexMetaDataOnDisk.index());
|
||||
}
|
||||
}
|
||||
previouslyWrittenIndices = previouslyWrittenIndicesBuilder.addAll(previouslyWrittenIndices).build();
|
||||
newPreviouslyWrittenIndices.addAll(previouslyWrittenIndices);
|
||||
previouslyWrittenIndices = unmodifiableSet(newPreviouslyWrittenIndices);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
success = false;
|
||||
|
@ -168,12 +172,11 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
|
|||
|
||||
if (success) {
|
||||
previousMetaData = newMetaData;
|
||||
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
||||
previouslyWrittenIndices = builder.addAll(relevantIndices).build();
|
||||
previouslyWrittenIndices = unmodifiableSet(relevantIndices);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getRelevantIndices(ClusterState state, ClusterState previousState,ImmutableSet<String> previouslyWrittenIndices) {
|
||||
public static Set<String> getRelevantIndices(ClusterState state, ClusterState previousState, Set<String> previouslyWrittenIndices) {
|
||||
Set<String> relevantIndices;
|
||||
if (isDataOnlyNode(state)) {
|
||||
relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices);
|
||||
|
@ -264,7 +267,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
|
|||
* @param newMetaData The new metadata
|
||||
* @return iterable over all indices states that should be written to disk
|
||||
*/
|
||||
public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(ImmutableSet<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) {
|
||||
public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(Set<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) {
|
||||
List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>();
|
||||
for (String index : potentiallyUnwrittenIndices) {
|
||||
IndexMetaData newIndexMetaData = newMetaData.index(index);
|
||||
|
@ -282,7 +285,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
|
|||
return indicesToWrite;
|
||||
}
|
||||
|
||||
public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, ImmutableSet<String> previouslyWrittenIndices) {
|
||||
public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<String> previouslyWrittenIndices) {
|
||||
RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId());
|
||||
if (newRoutingNode == null) {
|
||||
throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import com.carrotsearch.hppc.ObjectHashSet;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
|
@ -64,13 +64,17 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
|
||||
|
||||
/**
|
||||
|
@ -116,7 +120,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|||
|
||||
private volatile ImmutableMap<String, MappedFieldType> unmappedFieldTypes = ImmutableMap.of();
|
||||
|
||||
private volatile ImmutableSet<String> parentTypes = ImmutableSet.of();
|
||||
private volatile Set<String> parentTypes = emptySet();
|
||||
|
||||
@Inject
|
||||
public MapperService(Index index, @IndexSettings Settings indexSettings, AnalysisService analysisService,
|
||||
|
@ -283,10 +287,10 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|||
}
|
||||
mappers = newMapBuilder(mappers).put(mapper.type(), mapper).map();
|
||||
if (mapper.parentFieldMapper().active()) {
|
||||
ImmutableSet.Builder<String> parentTypesCopy = ImmutableSet.builder();
|
||||
Set<String> parentTypesCopy = new HashSet<String>();
|
||||
parentTypesCopy.addAll(parentTypes);
|
||||
parentTypesCopy.add(mapper.parentFieldMapper().type());
|
||||
parentTypes = parentTypesCopy.build();
|
||||
parentTypes = unmodifiableSet(parentTypes);
|
||||
}
|
||||
assert assertSerialization(mapper);
|
||||
return mapper;
|
||||
|
@ -594,7 +598,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public ImmutableSet<String> getParentTypes() {
|
||||
public Set<String> getParentTypes() {
|
||||
return parentTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,17 @@
|
|||
package org.elasticsearch.monitor.jvm;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -117,17 +122,15 @@ public class DeadlockAnalyzer {
|
|||
return threadInfoMap.build();
|
||||
}
|
||||
|
||||
|
||||
public static class Deadlock {
|
||||
|
||||
private final ThreadInfo members[];
|
||||
private final String description;
|
||||
private final ImmutableSet<Long> memberIds;
|
||||
private final Set<Long> memberIds;
|
||||
|
||||
public Deadlock(ThreadInfo[] members) {
|
||||
this.members = members;
|
||||
|
||||
ImmutableSet.Builder<Long> builder = ImmutableSet.builder();
|
||||
Set<Long> builder = new HashSet<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int x = 0; x < members.length; x++) {
|
||||
ThreadInfo ti = members[x];
|
||||
|
@ -139,7 +142,7 @@ public class DeadlockAnalyzer {
|
|||
builder.add(ti.getThreadId());
|
||||
}
|
||||
this.description = sb.toString();
|
||||
this.memberIds = builder.build();
|
||||
this.memberIds = unmodifiableSet(builder);
|
||||
}
|
||||
|
||||
public ThreadInfo[] members() {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.plugins;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.Build;
|
||||
import org.elasticsearch.ElasticsearchCorruptionException;
|
||||
|
@ -41,17 +41,29 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.PosixFileAttributeView;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static org.elasticsearch.common.Strings.hasLength;
|
||||
import static org.elasticsearch.common.cli.Terminal.Verbosity.VERBOSE;
|
||||
import static org.elasticsearch.common.io.FileSystemUtils.moveFilesWithoutOverwriting;
|
||||
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -64,16 +76,15 @@ public class PluginManager {
|
|||
DEFAULT, SILENT, VERBOSE
|
||||
}
|
||||
|
||||
private static final ImmutableSet<String> BLACKLIST = ImmutableSet.<String>builder()
|
||||
.add("elasticsearch",
|
||||
private static final Set<String> BLACKLIST = unmodifiableSet(newHashSet(
|
||||
"elasticsearch",
|
||||
"elasticsearch.bat",
|
||||
"elasticsearch.in.sh",
|
||||
"plugin",
|
||||
"plugin.bat",
|
||||
"service.bat").build();
|
||||
"service.bat"));
|
||||
|
||||
static final ImmutableSet<String> OFFICIAL_PLUGINS = ImmutableSet.<String>builder()
|
||||
.add(
|
||||
static final Set<String> OFFICIAL_PLUGINS = unmodifiableSet(newHashSet(
|
||||
"analysis-icu",
|
||||
"analysis-kuromoji",
|
||||
"analysis-phonetic",
|
||||
|
@ -91,8 +102,7 @@ public class PluginManager {
|
|||
"mapper-size",
|
||||
"repository-azure",
|
||||
"repository-s3",
|
||||
"store-smb"
|
||||
).build();
|
||||
"store-smb"));
|
||||
|
||||
private final Environment environment;
|
||||
private URL url;
|
||||
|
|
|
@ -26,23 +26,31 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static org.elasticsearch.client.Requests.updateSettingsRequest;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RestUpdateSettingsAction extends BaseRestHandler {
|
||||
|
||||
private static final ImmutableSet<String> VALUES_TO_EXCLUDE = ImmutableSet.<String>builder()
|
||||
.add("pretty").add("timeout").add("master_timeout").add("index")
|
||||
.add("expand_wildcards").add("ignore_unavailable").add("allow_no_indices")
|
||||
.build();
|
||||
private static final Set<String> VALUES_TO_EXCLUDE = unmodifiableSet(newHashSet(
|
||||
"pretty",
|
||||
"timeout",
|
||||
"master_timeout",
|
||||
"index",
|
||||
"expand_wildcards",
|
||||
"ignore_unavailable",
|
||||
"allow_no_indices"));
|
||||
|
||||
@Inject
|
||||
public RestUpdateSettingsAction(Settings settings, RestController controller, Client client) {
|
||||
|
|
|
@ -21,11 +21,16 @@ package org.elasticsearch.script;
|
|||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static java.util.stream.Stream.concat;
|
||||
|
||||
/**
|
||||
* Registry for operations that use scripts as part of their execution. Can be standard operations of custom defined ones (via plugin).
|
||||
|
@ -33,7 +38,7 @@ import java.util.Map;
|
|||
* Scripts can be enabled/disabled via fine-grained settings for each single registered operation.
|
||||
*/
|
||||
public final class ScriptContextRegistry {
|
||||
static final ImmutableSet<String> RESERVED_SCRIPT_CONTEXTS = reservedScriptContexts();
|
||||
static final Set<String> RESERVED_SCRIPT_CONTEXTS = reservedScriptContexts();
|
||||
|
||||
private final ImmutableMap<String, ScriptContext> scriptContexts;
|
||||
|
||||
|
@ -76,15 +81,11 @@ public final class ScriptContextRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
private static ImmutableSet<String> reservedScriptContexts() {
|
||||
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
||||
for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) {
|
||||
builder.add(scriptType.toString());
|
||||
}
|
||||
for (ScriptContext.Standard scriptContext : ScriptContext.Standard.values()) {
|
||||
builder.add(scriptContext.getKey());
|
||||
}
|
||||
builder.add("script").add("engine");
|
||||
return builder.build();
|
||||
private static Set<String> reservedScriptContexts() {
|
||||
Set<String> reserved = concat(stream(ScriptService.ScriptType.values()), stream(ScriptContext.Standard.values()))
|
||||
.map(Object::toString).collect(toSet());
|
||||
reserved.add("script");
|
||||
reserved.add("engine");
|
||||
return unmodifiableSet(reserved);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,15 +23,31 @@ import com.carrotsearch.hppc.IntSet;
|
|||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.cluster.*;
|
||||
import org.elasticsearch.cluster.ClusterChangedEvent;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.ClusterStateListener;
|
||||
import org.elasticsearch.cluster.ClusterStateUpdateTask;
|
||||
import org.elasticsearch.cluster.RestoreInProgress;
|
||||
import org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.metadata.*;
|
||||
import org.elasticsearch.cluster.routing.*;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService;
|
||||
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
||||
import org.elasticsearch.cluster.metadata.SnapshotId;
|
||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.RestoreSource;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.cluster.settings.ClusterDynamicSettings;
|
||||
|
@ -53,16 +69,40 @@ import org.elasticsearch.index.shard.StoreRecoveryService;
|
|||
import org.elasticsearch.repositories.RepositoriesService;
|
||||
import org.elasticsearch.repositories.Repository;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.*;
|
||||
import org.elasticsearch.transport.EmptyTransportResponseHandler;
|
||||
import org.elasticsearch.transport.TransportChannel;
|
||||
import org.elasticsearch.transport.TransportRequest;
|
||||
import org.elasticsearch.transport.TransportRequestHandler;
|
||||
import org.elasticsearch.transport.TransportResponse;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_CREATION_DATE;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_INDEX_UUID;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_LEGACY_ROUTING_USE_TYPE;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_UPGRADED;
|
||||
import static org.elasticsearch.cluster.metadata.MetaDataIndexStateService.INDEX_CLOSED_BLOCK;
|
||||
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
||||
import static org.elasticsearch.common.util.set.Sets.newHashSetCopyWith;
|
||||
|
||||
/**
|
||||
* Service responsible for restoring snapshots
|
||||
|
@ -90,22 +130,20 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
|
|||
|
||||
public static final String UPDATE_RESTORE_ACTION_NAME = "internal:cluster/snapshot/update_restore";
|
||||
|
||||
private static final ImmutableSet<String> UNMODIFIABLE_SETTINGS = ImmutableSet.of(
|
||||
private static final Set<String> UNMODIFIABLE_SETTINGS = unmodifiableSet(newHashSet(
|
||||
SETTING_NUMBER_OF_SHARDS,
|
||||
SETTING_VERSION_CREATED,
|
||||
SETTING_LEGACY_ROUTING_HASH_FUNCTION,
|
||||
SETTING_LEGACY_ROUTING_USE_TYPE,
|
||||
SETTING_INDEX_UUID,
|
||||
SETTING_CREATION_DATE);
|
||||
SETTING_CREATION_DATE));
|
||||
|
||||
// It's OK to change some settings, but we shouldn't allow simply removing them
|
||||
private static final ImmutableSet<String> UNREMOVABLE_SETTINGS = ImmutableSet.<String>builder()
|
||||
.addAll(UNMODIFIABLE_SETTINGS)
|
||||
.add(SETTING_NUMBER_OF_REPLICAS)
|
||||
.add(SETTING_AUTO_EXPAND_REPLICAS)
|
||||
.add(SETTING_VERSION_UPGRADED)
|
||||
.add(SETTING_VERSION_MINIMUM_COMPATIBLE)
|
||||
.build();
|
||||
private static final Set<String> UNREMOVABLE_SETTINGS = unmodifiableSet(newHashSetCopyWith(UNMODIFIABLE_SETTINGS,
|
||||
SETTING_NUMBER_OF_REPLICAS,
|
||||
SETTING_AUTO_EXPAND_REPLICAS,
|
||||
SETTING_VERSION_UPGRADED,
|
||||
SETTING_VERSION_MINIMUM_COMPATIBLE));
|
||||
|
||||
private final ClusterService clusterService;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.junit.Test;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -170,11 +171,10 @@ public class GatewayMetaStateTests extends ESAllocationTestCase {
|
|||
boolean stateInMemory,
|
||||
boolean expectMetaData) throws Exception {
|
||||
MetaData inMemoryMetaData = null;
|
||||
ImmutableSet<String> oldIndicesList = ImmutableSet.of();
|
||||
Set<String> oldIndicesList = emptySet();
|
||||
if (stateInMemory) {
|
||||
inMemoryMetaData = event.previousState().metaData();
|
||||
ImmutableSet.Builder<String> relevantIndices = ImmutableSet.builder();
|
||||
oldIndicesList = relevantIndices.addAll(GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList)).build();
|
||||
oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList);
|
||||
}
|
||||
Set<String> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList);
|
||||
// third, get the actual write info
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.gateway;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.block.ClusterBlock;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
|
@ -27,10 +26,12 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
|
@ -39,9 +40,9 @@ public class RecoverAfterNodesIT extends ESIntegTestCase {
|
|||
|
||||
private final static TimeValue BLOCK_WAIT_TIMEOUT = TimeValue.timeValueSeconds(10);
|
||||
|
||||
public ImmutableSet<ClusterBlock> waitForNoBlocksOnNode(TimeValue timeout, Client nodeClient) throws InterruptedException {
|
||||
public Set<ClusterBlock> waitForNoBlocksOnNode(TimeValue timeout, Client nodeClient) throws InterruptedException {
|
||||
long start = System.currentTimeMillis();
|
||||
ImmutableSet<ClusterBlock> blocks;
|
||||
Set<ClusterBlock> blocks;
|
||||
do {
|
||||
blocks = nodeClient.admin().cluster().prepareState().setLocal(true).execute().actionGet()
|
||||
.getState().blocks().global(ClusterBlockLevel.METADATA_WRITE);
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -94,7 +95,7 @@ public class PluginManagerUnitTests extends ESTestCase {
|
|||
|
||||
@Test
|
||||
public void testOfficialPluginName() throws IOException {
|
||||
String randomPluginName = randomFrom(PluginManager.OFFICIAL_PLUGINS.asList());
|
||||
String randomPluginName = randomFrom(new ArrayList<>(PluginManager.OFFICIAL_PLUGINS));
|
||||
PluginManager.PluginHandle handle = PluginManager.PluginHandle.parse(randomPluginName);
|
||||
assertThat(handle.name, is(randomPluginName));
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ com.google.common.collect.FluentIterable
|
|||
com.google.common.io.Files
|
||||
com.google.common.primitives.Ints
|
||||
com.google.common.collect.ImmutableMap#entrySet()
|
||||
com.google.common.collect.ImmutableSet#builder()
|
||||
|
||||
@defaultMessage Do not violate java's access system
|
||||
java.lang.reflect.AccessibleObject#setAccessible(boolean)
|
||||
|
|
Loading…
Reference in New Issue