|
@@ -25,6 +25,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
|
|
|
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
|
|
|
|
|
import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
|
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
|
import org.elasticsearch.cluster.Diff;
|
|
|
import org.elasticsearch.cluster.Diffable;
|
|
@@ -294,6 +295,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
static final String KEY_STATE = "state";
|
|
|
static final String KEY_MAPPINGS = "mappings";
|
|
|
static final String KEY_ALIASES = "aliases";
|
|
|
+ static final String KEY_ROLLOVER_INFOS = "rollover_info";
|
|
|
public static final String KEY_PRIMARY_TERMS = "primary_terms";
|
|
|
|
|
|
public static final String INDEX_STATE_FILE_PREFIX = "state-";
|
|
@@ -331,13 +333,14 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
private final Version indexUpgradedVersion;
|
|
|
|
|
|
private final ActiveShardCount waitForActiveShards;
|
|
|
+ private final ImmutableOpenMap<String, RolloverInfo> rolloverInfos;
|
|
|
|
|
|
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>> inSyncAllocationIds,
|
|
|
DiscoveryNodeFilters requireFilters, DiscoveryNodeFilters initialRecoveryFilters, DiscoveryNodeFilters includeFilters, DiscoveryNodeFilters excludeFilters,
|
|
|
Version indexCreatedVersion, Version indexUpgradedVersion,
|
|
|
- int routingNumShards, int routingPartitionSize, ActiveShardCount waitForActiveShards) {
|
|
|
+ int routingNumShards, int routingPartitionSize, ActiveShardCount waitForActiveShards, ImmutableOpenMap<String, RolloverInfo> rolloverInfos) {
|
|
|
|
|
|
this.index = index;
|
|
|
this.version = version;
|
|
@@ -362,6 +365,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
this.routingFactor = routingNumShards / numberOfShards;
|
|
|
this.routingPartitionSize = routingPartitionSize;
|
|
|
this.waitForActiveShards = waitForActiveShards;
|
|
|
+ this.rolloverInfos = rolloverInfos;
|
|
|
assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
|
|
|
}
|
|
|
|
|
@@ -517,6 +521,10 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
return inSyncAllocationIds;
|
|
|
}
|
|
|
|
|
|
+ public ImmutableOpenMap<String, RolloverInfo> getRolloverInfos() {
|
|
|
+ return rolloverInfos;
|
|
|
+ }
|
|
|
+
|
|
|
public Set<String> inSyncAllocationIds(int shardId) {
|
|
|
assert shardId >= 0 && shardId < numberOfShards;
|
|
|
return inSyncAllocationIds.get(shardId);
|
|
@@ -587,6 +595,9 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
if (!inSyncAllocationIds.equals(that.inSyncAllocationIds)) {
|
|
|
return false;
|
|
|
}
|
|
|
+ if (rolloverInfos.equals(that.rolloverInfos) == false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -603,6 +614,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
result = 31 * result + Long.hashCode(routingNumShards);
|
|
|
result = 31 * result + Arrays.hashCode(primaryTerms);
|
|
|
result = 31 * result + inSyncAllocationIds.hashCode();
|
|
|
+ result = 31 * result + rolloverInfos.hashCode();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -638,6 +650,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
private final Diff<ImmutableOpenMap<String, AliasMetaData>> aliases;
|
|
|
private final Diff<ImmutableOpenMap<String, Custom>> customs;
|
|
|
private final Diff<ImmutableOpenIntMap<Set<String>>> inSyncAllocationIds;
|
|
|
+ private final Diff<ImmutableOpenMap<String, RolloverInfo>> rolloverInfos;
|
|
|
|
|
|
IndexMetaDataDiff(IndexMetaData before, IndexMetaData after) {
|
|
|
index = after.index.getName();
|
|
@@ -651,6 +664,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
customs = DiffableUtils.diff(before.customs, after.customs, DiffableUtils.getStringKeySerializer());
|
|
|
inSyncAllocationIds = DiffableUtils.diff(before.inSyncAllocationIds, after.inSyncAllocationIds,
|
|
|
DiffableUtils.getVIntKeySerializer(), DiffableUtils.StringSetValueSerializer.getInstance());
|
|
|
+ rolloverInfos = DiffableUtils.diff(before.rolloverInfos, after.rolloverInfos, DiffableUtils.getStringKeySerializer());
|
|
|
}
|
|
|
|
|
|
IndexMetaDataDiff(StreamInput in) throws IOException {
|
|
@@ -679,6 +693,13 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
});
|
|
|
inSyncAllocationIds = DiffableUtils.readImmutableOpenIntMapDiff(in, DiffableUtils.getVIntKeySerializer(),
|
|
|
DiffableUtils.StringSetValueSerializer.getInstance());
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
|
|
+ rolloverInfos = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), RolloverInfo::new,
|
|
|
+ RolloverInfo::readDiffFrom);
|
|
|
+ } else {
|
|
|
+ ImmutableOpenMap<String, RolloverInfo> emptyMap = ImmutableOpenMap.of();
|
|
|
+ rolloverInfos = DiffableUtils.diff(emptyMap, emptyMap, DiffableUtils.getStringKeySerializer());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -693,6 +714,9 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
aliases.writeTo(out);
|
|
|
customs.writeTo(out);
|
|
|
inSyncAllocationIds.writeTo(out);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
|
|
+ rolloverInfos.writeTo(out);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -707,6 +731,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
builder.aliases.putAll(aliases.apply(part.aliases));
|
|
|
builder.customs.putAll(customs.apply(part.customs));
|
|
|
builder.inSyncAllocationIds.putAll(inSyncAllocationIds.apply(part.inSyncAllocationIds));
|
|
|
+ builder.rolloverInfos.putAll(rolloverInfos.apply(part.rolloverInfos));
|
|
|
return builder.build();
|
|
|
}
|
|
|
}
|
|
@@ -740,6 +765,12 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
Set<String> allocationIds = DiffableUtils.StringSetValueSerializer.getInstance().read(in, key);
|
|
|
builder.putInSyncAllocationIds(key, allocationIds);
|
|
|
}
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
|
|
+ int rolloverAliasesSize = in.readVInt();
|
|
|
+ for (int i = 0; i < rolloverAliasesSize; i++) {
|
|
|
+ builder.putRolloverInfo(new RolloverInfo(in));
|
|
|
+ }
|
|
|
+ }
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
@@ -769,6 +800,12 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
out.writeVInt(cursor.key);
|
|
|
DiffableUtils.StringSetValueSerializer.getInstance().write(cursor.value, out);
|
|
|
}
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
|
|
+ out.writeVInt(rolloverInfos.size());
|
|
|
+ for (ObjectCursor<RolloverInfo> cursor : rolloverInfos.values()) {
|
|
|
+ cursor.value.writeTo(out);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static Builder builder(String index) {
|
|
@@ -790,6 +827,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
private final ImmutableOpenMap.Builder<String, AliasMetaData> aliases;
|
|
|
private final ImmutableOpenMap.Builder<String, Custom> customs;
|
|
|
private final ImmutableOpenIntMap.Builder<Set<String>> inSyncAllocationIds;
|
|
|
+ private final ImmutableOpenMap.Builder<String, RolloverInfo> rolloverInfos;
|
|
|
private Integer routingNumShards;
|
|
|
|
|
|
public Builder(String index) {
|
|
@@ -798,6 +836,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
this.aliases = ImmutableOpenMap.builder();
|
|
|
this.customs = ImmutableOpenMap.builder();
|
|
|
this.inSyncAllocationIds = ImmutableOpenIntMap.builder();
|
|
|
+ this.rolloverInfos = ImmutableOpenMap.builder();
|
|
|
}
|
|
|
|
|
|
public Builder(IndexMetaData indexMetaData) {
|
|
@@ -811,6 +850,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
this.customs = ImmutableOpenMap.builder(indexMetaData.customs);
|
|
|
this.routingNumShards = indexMetaData.routingNumShards;
|
|
|
this.inSyncAllocationIds = ImmutableOpenIntMap.builder(indexMetaData.inSyncAllocationIds);
|
|
|
+ this.rolloverInfos = ImmutableOpenMap.builder(indexMetaData.rolloverInfos);
|
|
|
}
|
|
|
|
|
|
public String index() {
|
|
@@ -951,6 +991,15 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public RolloverInfo getRolloverInfo(String alias) {
|
|
|
+ return rolloverInfos.get(alias);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder putRolloverInfo(RolloverInfo rolloverInfo) {
|
|
|
+ rolloverInfos.put(rolloverInfo.getAlias(), rolloverInfo);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public long version() {
|
|
|
return this.version;
|
|
|
}
|
|
@@ -1089,7 +1138,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
|
|
|
return new IndexMetaData(new Index(index, uuid), version, primaryTerms, state, numberOfShards, numberOfReplicas, tmpSettings, mappings.build(),
|
|
|
tmpAliases.build(), customs.build(), filledInSyncAllocationIds.build(), requireFilters, initialRecoveryFilters, includeFilters, excludeFilters,
|
|
|
- indexCreatedVersion, indexUpgradedVersion, getRoutingNumShards(), routingPartitionSize, waitForActiveShards);
|
|
|
+ indexCreatedVersion, indexUpgradedVersion, getRoutingNumShards(), routingPartitionSize, waitForActiveShards, rolloverInfos.build());
|
|
|
}
|
|
|
|
|
|
public static void toXContent(IndexMetaData indexMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
|
@@ -1143,6 +1192,12 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
}
|
|
|
builder.endObject();
|
|
|
|
|
|
+ builder.startObject(KEY_ROLLOVER_INFOS);
|
|
|
+ for (ObjectCursor<RolloverInfo> cursor : indexMetaData.getRolloverInfos().values()) {
|
|
|
+ cursor.value.toXContent(builder, params);
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+
|
|
|
builder.endObject();
|
|
|
}
|
|
|
|
|
@@ -1202,6 +1257,16 @@ public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragmen
|
|
|
throw new IllegalArgumentException("Unexpected token: " + token);
|
|
|
}
|
|
|
}
|
|
|
+ } else if (KEY_ROLLOVER_INFOS.equals(currentFieldName)) {
|
|
|
+ while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
|
+ if (token == XContentParser.Token.FIELD_NAME) {
|
|
|
+ currentFieldName = parser.currentName();
|
|
|
+ } else if (token == XContentParser.Token.START_OBJECT) {
|
|
|
+ builder.putRolloverInfo(RolloverInfo.parse(parser, currentFieldName));
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("Unexpected token: " + token);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else if ("warmers".equals(currentFieldName)) {
|
|
|
// TODO: do this in 6.0:
|
|
|
// throw new IllegalArgumentException("Warmers are not supported anymore - are you upgrading from 1.x?");
|