|
@@ -25,6 +25,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
|
|
|
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
|
|
|
|
|
import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.action.support.ActiveShardCount;
|
|
|
import org.elasticsearch.cluster.Diff;
|
|
|
import org.elasticsearch.cluster.Diffable;
|
|
|
import org.elasticsearch.cluster.DiffableUtils;
|
|
@@ -219,6 +220,16 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|
|
public static final Setting<Settings> INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING =
|
|
|
Setting.groupSetting("index.routing.allocation.initial_recovery."); // this is only setable internally not a registered setting!!
|
|
|
|
|
|
+ /**
|
|
|
+ * The number of active shard copies to check for before proceeding with a write operation.
|
|
|
+ */
|
|
|
+ public static final Setting<ActiveShardCount> SETTING_WAIT_FOR_ACTIVE_SHARDS =
|
|
|
+ new Setting<>("index.write.wait_for_active_shards",
|
|
|
+ "1",
|
|
|
+ ActiveShardCount::parseString,
|
|
|
+ Setting.Property.Dynamic,
|
|
|
+ Setting.Property.IndexScope);
|
|
|
+
|
|
|
public static final IndexMetaData PROTO = IndexMetaData.builder("")
|
|
|
.settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT))
|
|
|
.numberOfShards(1).numberOfReplicas(0).build();
|
|
@@ -266,12 +277,14 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|
|
private final Version indexUpgradedVersion;
|
|
|
private final org.apache.lucene.util.Version minimumCompatibleLuceneVersion;
|
|
|
|
|
|
+ private final ActiveShardCount waitForActiveShards;
|
|
|
+
|
|
|
private IndexMetaData(Index index, long version, long[] primaryTerms, State state, int numberOfShards, int numberOfReplicas, Settings settings,
|
|
|
ImmutableOpenMap<String, MappingMetaData> mappings, ImmutableOpenMap<String, AliasMetaData> aliases,
|
|
|
ImmutableOpenMap<String, Custom> customs, ImmutableOpenIntMap<Set<String>> activeAllocationIds,
|
|
|
DiscoveryNodeFilters requireFilters, DiscoveryNodeFilters initialRecoveryFilters, DiscoveryNodeFilters includeFilters, DiscoveryNodeFilters excludeFilters,
|
|
|
Version indexCreatedVersion, Version indexUpgradedVersion, org.apache.lucene.util.Version minimumCompatibleLuceneVersion,
|
|
|
- int routingNumShards) {
|
|
|
+ int routingNumShards, ActiveShardCount waitForActiveShards) {
|
|
|
|
|
|
this.index = index;
|
|
|
this.version = version;
|
|
@@ -295,6 +308,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|
|
this.minimumCompatibleLuceneVersion = minimumCompatibleLuceneVersion;
|
|
|
this.routingNumShards = routingNumShards;
|
|
|
this.routingFactor = routingNumShards / numberOfShards;
|
|
|
+ this.waitForActiveShards = waitForActiveShards;
|
|
|
assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
|
|
|
}
|
|
|
|
|
@@ -378,6 +392,14 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|
|
return totalNumberOfShards;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the configured {@link #SETTING_WAIT_FOR_ACTIVE_SHARDS}, which defaults
|
|
|
+ * to an active shard count of 1 if not specified.
|
|
|
+ */
|
|
|
+ public ActiveShardCount getWaitForActiveShards() {
|
|
|
+ return waitForActiveShards;
|
|
|
+ }
|
|
|
+
|
|
|
public Settings getSettings() {
|
|
|
return settings;
|
|
|
}
|
|
@@ -973,10 +995,17 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|
|
+ "] but should be equal to number of shards [" + numberOfShards() + "]");
|
|
|
}
|
|
|
|
|
|
+ final ActiveShardCount waitForActiveShards = SETTING_WAIT_FOR_ACTIVE_SHARDS.get(settings);
|
|
|
+ if (waitForActiveShards.validate(numberOfReplicas) == false) {
|
|
|
+ throw new IllegalArgumentException("invalid " + SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey() +
|
|
|
+ "[" + waitForActiveShards + "]: cannot be greater than " +
|
|
|
+ "number of shard copies [" + (numberOfReplicas + 1) + "]");
|
|
|
+ }
|
|
|
+
|
|
|
final String uuid = settings.get(SETTING_INDEX_UUID, INDEX_UUID_NA_VALUE);
|
|
|
return new IndexMetaData(new Index(index, uuid), version, primaryTerms, state, numberOfShards, numberOfReplicas, tmpSettings, mappings.build(),
|
|
|
tmpAliases.build(), customs.build(), filledActiveAllocationIds.build(), requireFilters, initialRecoveryFilters, includeFilters, excludeFilters,
|
|
|
- indexCreatedVersion, indexUpgradedVersion, minimumCompatibleLuceneVersion, getRoutingNumShards());
|
|
|
+ indexCreatedVersion, indexUpgradedVersion, minimumCompatibleLuceneVersion, getRoutingNumShards(), waitForActiveShards);
|
|
|
}
|
|
|
|
|
|
public static void toXContent(IndexMetaData indexMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
|