|
@@ -43,7 +43,6 @@ import org.elasticsearch.index.IndexSettings;
|
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
|
|
import org.elasticsearch.index.shard.IndexLongFieldRange;
|
|
|
-import org.elasticsearch.index.shard.IndexWriteLoad;
|
|
|
import org.elasticsearch.index.shard.ShardId;
|
|
|
import org.elasticsearch.index.shard.ShardLongFieldRange;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
@@ -70,6 +69,7 @@ import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.OptionalDouble;
|
|
|
+import java.util.OptionalLong;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.Function;
|
|
|
|
|
@@ -522,15 +522,17 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
static final String KEY_SYSTEM = "system";
|
|
|
static final String KEY_TIMESTAMP_RANGE = "timestamp_range";
|
|
|
public static final String KEY_PRIMARY_TERMS = "primary_terms";
|
|
|
- public static final String KEY_WRITE_LOAD = "write_load";
|
|
|
+ public static final String KEY_STATS = "stats";
|
|
|
|
|
|
public static final String KEY_WRITE_LOAD_FORECAST = "write_load_forecast";
|
|
|
|
|
|
+ public static final String KEY_SHARD_SIZE_FORECAST = "shard_size_forecast";
|
|
|
+
|
|
|
public static final String INDEX_STATE_FILE_PREFIX = "state-";
|
|
|
|
|
|
static final Version SYSTEM_INDEX_FLAG_ADDED = Version.V_7_10_0;
|
|
|
|
|
|
- static final Version WRITE_LOAD_ADDED = Version.V_8_6_0;
|
|
|
+ static final Version STATS_AND_FORECAST_ADDED = Version.V_8_6_0;
|
|
|
|
|
|
private final int routingNumShards;
|
|
|
private final int routingFactor;
|
|
@@ -610,9 +612,11 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
@Nullable
|
|
|
private final Instant timeSeriesEnd;
|
|
|
@Nullable
|
|
|
- private final IndexWriteLoad writeLoad;
|
|
|
+ private final IndexMetadataStats stats;
|
|
|
@Nullable
|
|
|
private final Double writeLoadForecast;
|
|
|
+ @Nullable
|
|
|
+ private final Long shardSizeInBytesForecast;
|
|
|
|
|
|
private IndexMetadata(
|
|
|
final Index index,
|
|
@@ -656,8 +660,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
@Nullable final Instant timeSeriesStart,
|
|
|
@Nullable final Instant timeSeriesEnd,
|
|
|
final Version indexCompatibilityVersion,
|
|
|
- @Nullable final IndexWriteLoad writeLoad,
|
|
|
- @Nullable final Double writeLoadForecast
|
|
|
+ @Nullable final IndexMetadataStats stats,
|
|
|
+ @Nullable final Double writeLoadForecast,
|
|
|
+ @Nullable Long shardSizeInBytesForecast
|
|
|
) {
|
|
|
this.index = index;
|
|
|
this.version = version;
|
|
@@ -708,8 +713,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.indexMode = indexMode;
|
|
|
this.timeSeriesStart = timeSeriesStart;
|
|
|
this.timeSeriesEnd = timeSeriesEnd;
|
|
|
- this.writeLoad = writeLoad;
|
|
|
+ this.stats = stats;
|
|
|
this.writeLoadForecast = writeLoadForecast;
|
|
|
+ this.shardSizeInBytesForecast = shardSizeInBytesForecast;
|
|
|
assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
|
|
|
}
|
|
|
|
|
@@ -759,8 +765,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.timeSeriesStart,
|
|
|
this.timeSeriesEnd,
|
|
|
this.indexCompatibilityVersion,
|
|
|
- this.writeLoad,
|
|
|
- this.writeLoadForecast
|
|
|
+ this.stats,
|
|
|
+ this.writeLoadForecast,
|
|
|
+ this.shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -816,8 +823,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.timeSeriesStart,
|
|
|
this.timeSeriesEnd,
|
|
|
this.indexCompatibilityVersion,
|
|
|
- this.writeLoad,
|
|
|
- this.writeLoadForecast
|
|
|
+ this.stats,
|
|
|
+ this.writeLoadForecast,
|
|
|
+ this.shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -871,8 +879,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.timeSeriesStart,
|
|
|
this.timeSeriesEnd,
|
|
|
this.indexCompatibilityVersion,
|
|
|
- this.writeLoad,
|
|
|
- this.writeLoadForecast
|
|
|
+ this.stats,
|
|
|
+ this.writeLoadForecast,
|
|
|
+ this.shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -926,8 +935,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.timeSeriesStart,
|
|
|
this.timeSeriesEnd,
|
|
|
this.indexCompatibilityVersion,
|
|
|
- this.writeLoad,
|
|
|
- this.writeLoadForecast
|
|
|
+ this.stats,
|
|
|
+ this.writeLoadForecast,
|
|
|
+ this.shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -977,8 +987,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.timeSeriesStart,
|
|
|
this.timeSeriesEnd,
|
|
|
this.indexCompatibilityVersion,
|
|
|
- this.writeLoad,
|
|
|
- this.writeLoadForecast
|
|
|
+ this.stats,
|
|
|
+ this.writeLoadForecast,
|
|
|
+ this.shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -1170,14 +1181,18 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
}
|
|
|
|
|
|
@Nullable
|
|
|
- public IndexWriteLoad getWriteLoad() {
|
|
|
- return writeLoad;
|
|
|
+ public IndexMetadataStats getStats() {
|
|
|
+ return stats;
|
|
|
}
|
|
|
|
|
|
public OptionalDouble getForecastedWriteLoad() {
|
|
|
return writeLoadForecast == null ? OptionalDouble.empty() : OptionalDouble.of(writeLoadForecast);
|
|
|
}
|
|
|
|
|
|
+ public OptionalLong getForecastedShardSizeInBytes() {
|
|
|
+ return shardSizeInBytesForecast == null ? OptionalLong.empty() : OptionalLong.of(shardSizeInBytesForecast);
|
|
|
+ }
|
|
|
+
|
|
|
public static final String INDEX_RESIZE_SOURCE_UUID_KEY = "index.resize.source.uuid";
|
|
|
public static final String INDEX_RESIZE_SOURCE_NAME_KEY = "index.resize.source.name";
|
|
|
public static final Setting<String> INDEX_RESIZE_SOURCE_UUID = Setting.simpleString(INDEX_RESIZE_SOURCE_UUID_KEY);
|
|
@@ -1412,8 +1427,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
private final Diff<ImmutableOpenMap<String, RolloverInfo>> rolloverInfos;
|
|
|
private final boolean isSystem;
|
|
|
private final IndexLongFieldRange timestampRange;
|
|
|
- private final IndexWriteLoad indexWriteLoad;
|
|
|
+ private final IndexMetadataStats stats;
|
|
|
private final Double indexWriteLoadForecast;
|
|
|
+ private final Long shardSizeInBytesForecast;
|
|
|
|
|
|
IndexMetadataDiff(IndexMetadata before, IndexMetadata after) {
|
|
|
index = after.index.getName();
|
|
@@ -1447,8 +1463,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
rolloverInfos = DiffableUtils.diff(before.rolloverInfos, after.rolloverInfos, DiffableUtils.getStringKeySerializer());
|
|
|
isSystem = after.isSystem;
|
|
|
timestampRange = after.timestampRange;
|
|
|
- indexWriteLoad = after.writeLoad;
|
|
|
+ stats = after.stats;
|
|
|
indexWriteLoadForecast = after.writeLoadForecast;
|
|
|
+ shardSizeInBytesForecast = after.shardSizeInBytesForecast;
|
|
|
}
|
|
|
|
|
|
private static final DiffableUtils.DiffableValueReader<String, AliasMetadata> ALIAS_METADATA_DIFF_VALUE_READER =
|
|
@@ -1499,12 +1516,14 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
isSystem = false;
|
|
|
}
|
|
|
timestampRange = IndexLongFieldRange.readFrom(in);
|
|
|
- if (in.getVersion().onOrAfter(WRITE_LOAD_ADDED)) {
|
|
|
- indexWriteLoad = in.readOptionalWriteable(IndexWriteLoad::new);
|
|
|
+ if (in.getVersion().onOrAfter(STATS_AND_FORECAST_ADDED)) {
|
|
|
+ stats = in.readOptionalWriteable(IndexMetadataStats::new);
|
|
|
indexWriteLoadForecast = in.readOptionalDouble();
|
|
|
+ shardSizeInBytesForecast = in.readOptionalLong();
|
|
|
} else {
|
|
|
- indexWriteLoad = null;
|
|
|
+ stats = null;
|
|
|
indexWriteLoadForecast = null;
|
|
|
+ shardSizeInBytesForecast = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1536,9 +1555,10 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
out.writeBoolean(isSystem);
|
|
|
}
|
|
|
timestampRange.writeTo(out);
|
|
|
- if (out.getVersion().onOrAfter(WRITE_LOAD_ADDED)) {
|
|
|
- out.writeOptionalWriteable(indexWriteLoad);
|
|
|
+ if (out.getVersion().onOrAfter(STATS_AND_FORECAST_ADDED)) {
|
|
|
+ out.writeOptionalWriteable(stats);
|
|
|
out.writeOptionalDouble(indexWriteLoadForecast);
|
|
|
+ out.writeOptionalLong(shardSizeInBytesForecast);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1566,8 +1586,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
builder.rolloverInfos.putAllFromMap(rolloverInfos.apply(part.rolloverInfos));
|
|
|
builder.system(isSystem);
|
|
|
builder.timestampRange(timestampRange);
|
|
|
- builder.indexWriteLoad(indexWriteLoad);
|
|
|
+ builder.stats(stats);
|
|
|
builder.indexWriteLoadForecast(indexWriteLoadForecast);
|
|
|
+ builder.shardSizeInBytesForecast(shardSizeInBytesForecast);
|
|
|
return builder.build();
|
|
|
}
|
|
|
}
|
|
@@ -1630,9 +1651,10 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
}
|
|
|
builder.timestampRange(IndexLongFieldRange.readFrom(in));
|
|
|
|
|
|
- if (in.getVersion().onOrAfter(WRITE_LOAD_ADDED)) {
|
|
|
- builder.indexWriteLoad(in.readOptionalWriteable(IndexWriteLoad::new));
|
|
|
+ if (in.getVersion().onOrAfter(STATS_AND_FORECAST_ADDED)) {
|
|
|
+ builder.stats(in.readOptionalWriteable(IndexMetadataStats::new));
|
|
|
builder.indexWriteLoadForecast(in.readOptionalDouble());
|
|
|
+ builder.shardSizeInBytesForecast(in.readOptionalLong());
|
|
|
}
|
|
|
return builder.build();
|
|
|
}
|
|
@@ -1675,9 +1697,10 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
out.writeBoolean(isSystem);
|
|
|
}
|
|
|
timestampRange.writeTo(out);
|
|
|
- if (out.getVersion().onOrAfter(WRITE_LOAD_ADDED)) {
|
|
|
- out.writeOptionalWriteable(writeLoad);
|
|
|
+ if (out.getVersion().onOrAfter(STATS_AND_FORECAST_ADDED)) {
|
|
|
+ out.writeOptionalWriteable(stats);
|
|
|
out.writeOptionalDouble(writeLoadForecast);
|
|
|
+ out.writeOptionalLong(shardSizeInBytesForecast);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1725,8 +1748,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
private boolean isSystem;
|
|
|
private IndexLongFieldRange timestampRange = IndexLongFieldRange.NO_SHARDS;
|
|
|
private LifecycleExecutionState lifecycleExecutionState = LifecycleExecutionState.EMPTY_STATE;
|
|
|
- private IndexWriteLoad indexWriteLoad = null;
|
|
|
+ private IndexMetadataStats stats = null;
|
|
|
private Double indexWriteLoadForecast = null;
|
|
|
+ private Long shardSizeInBytesForecast = null;
|
|
|
|
|
|
public Builder(String index) {
|
|
|
this.index = index;
|
|
@@ -1755,8 +1779,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
this.isSystem = indexMetadata.isSystem;
|
|
|
this.timestampRange = indexMetadata.timestampRange;
|
|
|
this.lifecycleExecutionState = indexMetadata.lifecycleExecutionState;
|
|
|
- this.indexWriteLoad = indexMetadata.writeLoad;
|
|
|
+ this.stats = indexMetadata.stats;
|
|
|
this.indexWriteLoadForecast = indexMetadata.writeLoadForecast;
|
|
|
+ this.shardSizeInBytesForecast = indexMetadata.shardSizeInBytesForecast;
|
|
|
}
|
|
|
|
|
|
public Builder index(String index) {
|
|
@@ -1971,8 +1996,8 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder indexWriteLoad(IndexWriteLoad indexWriteLoad) {
|
|
|
- this.indexWriteLoad = indexWriteLoad;
|
|
|
+ public Builder stats(IndexMetadataStats stats) {
|
|
|
+ this.stats = stats;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -1981,6 +2006,11 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public Builder shardSizeInBytesForecast(Long shardSizeInBytesForecast) {
|
|
|
+ this.shardSizeInBytesForecast = shardSizeInBytesForecast;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public IndexMetadata build() {
|
|
|
/*
|
|
|
* We expect that the metadata has been properly built to set the number of shards and the number of replicas, and do not rely
|
|
@@ -2096,11 +2126,11 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
lifecycleExecutionState = LifecycleExecutionState.EMPTY_STATE;
|
|
|
}
|
|
|
|
|
|
- if (indexWriteLoad != null && indexWriteLoad.numberOfShards() != numberOfShards) {
|
|
|
+ if (stats != null && stats.writeLoad().numberOfShards() != numberOfShards) {
|
|
|
assert false;
|
|
|
throw new IllegalArgumentException(
|
|
|
"The number of write load shards ["
|
|
|
- + indexWriteLoad.numberOfShards()
|
|
|
+ + stats.writeLoad().numberOfShards()
|
|
|
+ "] is different than the number of index shards ["
|
|
|
+ numberOfShards
|
|
|
+ "]"
|
|
@@ -2159,8 +2189,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
isTsdb ? IndexSettings.TIME_SERIES_START_TIME.get(settings) : null,
|
|
|
isTsdb ? IndexSettings.TIME_SERIES_END_TIME.get(settings) : null,
|
|
|
SETTING_INDEX_VERSION_COMPATIBILITY.get(settings),
|
|
|
- indexWriteLoad,
|
|
|
- indexWriteLoadForecast
|
|
|
+ stats,
|
|
|
+ indexWriteLoadForecast,
|
|
|
+ shardSizeInBytesForecast
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -2272,9 +2303,9 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
indexMetadata.timestampRange.toXContent(builder, params);
|
|
|
builder.endObject();
|
|
|
|
|
|
- if (indexMetadata.writeLoad != null) {
|
|
|
- builder.startObject(KEY_WRITE_LOAD);
|
|
|
- indexMetadata.writeLoad.toXContent(builder, params);
|
|
|
+ if (indexMetadata.stats != null) {
|
|
|
+ builder.startObject(KEY_STATS);
|
|
|
+ indexMetadata.stats.toXContent(builder, params);
|
|
|
builder.endObject();
|
|
|
}
|
|
|
|
|
@@ -2282,6 +2313,10 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
builder.field(KEY_WRITE_LOAD_FORECAST, indexMetadata.writeLoadForecast);
|
|
|
}
|
|
|
|
|
|
+ if (indexMetadata.shardSizeInBytesForecast != null) {
|
|
|
+ builder.field(KEY_SHARD_SIZE_FORECAST, indexMetadata.shardSizeInBytesForecast);
|
|
|
+ }
|
|
|
+
|
|
|
builder.endObject();
|
|
|
}
|
|
|
|
|
@@ -2356,8 +2391,8 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
case KEY_TIMESTAMP_RANGE:
|
|
|
builder.timestampRange(IndexLongFieldRange.fromXContent(parser));
|
|
|
break;
|
|
|
- case KEY_WRITE_LOAD:
|
|
|
- builder.indexWriteLoad(IndexWriteLoad.fromXContent(parser));
|
|
|
+ case KEY_STATS:
|
|
|
+ builder.stats(IndexMetadataStats.fromXContent(parser));
|
|
|
break;
|
|
|
default:
|
|
|
// assume it's custom index metadata
|
|
@@ -2416,6 +2451,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
|
builder.putMapping(mappingsByHash.get(parser.text()));
|
|
|
}
|
|
|
case KEY_WRITE_LOAD_FORECAST -> builder.indexWriteLoadForecast(parser.doubleValue());
|
|
|
+ case KEY_SHARD_SIZE_FORECAST -> builder.shardSizeInBytesForecast(parser.longValue());
|
|
|
default -> throw new IllegalArgumentException("Unexpected field [" + currentFieldName + "]");
|
|
|
}
|
|
|
} else {
|