@@ -102,6 +102,8 @@ public class ProjectMetadata implements Iterable<IndexMetadata>, Diffable<Projec
102
102
private volatile SortedMap <String , IndexAbstraction > indicesLookup ;
103
103
private final Map <String , MappingMetadata > mappingsByHash ;
104
104
105
+ private final Settings settings ;
106
+
105
107
private final IndexVersion oldestIndexVersion ;
106
108
107
109
@ SuppressWarnings ("this-escape" )
@@ -122,6 +124,7 @@ private ProjectMetadata(
122
124
String [] visibleClosedIndices ,
123
125
SortedMap <String , IndexAbstraction > indicesLookup ,
124
126
Map <String , MappingMetadata > mappingsByHash ,
127
+ Settings settings ,
125
128
IndexVersion oldestIndexVersion
126
129
) {
127
130
this .id = id ;
@@ -140,6 +143,7 @@ private ProjectMetadata(
140
143
this .visibleClosedIndices = visibleClosedIndices ;
141
144
this .indicesLookup = indicesLookup ;
142
145
this .mappingsByHash = mappingsByHash ;
146
+ this .settings = settings ;
143
147
this .oldestIndexVersion = oldestIndexVersion ;
144
148
assert assertConsistent ();
145
149
}
@@ -221,6 +225,7 @@ public ProjectMetadata withLifecycleState(Index index, LifecycleExecutionState l
221
225
visibleClosedIndices ,
222
226
indicesLookup ,
223
227
mappingsByHash ,
228
+ settings ,
224
229
oldestIndexVersion
225
230
);
226
231
}
@@ -254,6 +259,7 @@ public ProjectMetadata withIndexSettingsUpdates(Map<Index, Settings> updates) {
254
259
visibleClosedIndices ,
255
260
indicesLookup ,
256
261
mappingsByHash ,
262
+ settings ,
257
263
oldestIndexVersion
258
264
);
259
265
}
@@ -288,6 +294,7 @@ public ProjectMetadata withAllocationAndTermUpdatesOnly(Map<String, IndexMetadat
288
294
visibleClosedIndices ,
289
295
indicesLookup ,
290
296
mappingsByHash ,
297
+ settings ,
291
298
oldestIndexVersion
292
299
);
293
300
}
@@ -376,6 +383,7 @@ public ProjectMetadata withAddedIndex(IndexMetadata index) {
376
383
updatedVisibleClosedIndices ,
377
384
null ,
378
385
updatedMappingsByHash ,
386
+ settings ,
379
387
IndexVersion .min (index .getCompatibilityVersion (), oldestIndexVersion )
380
388
);
381
389
}
@@ -727,6 +735,10 @@ public Map<String, IndexTemplateMetadata> templates() {
727
735
return templates ;
728
736
}
729
737
738
+ public Settings settings () {
739
+ return settings ;
740
+ }
741
+
730
742
/**
731
743
* Checks whether the provided index is a data stream.
732
744
*/
@@ -1097,6 +1109,9 @@ public boolean isIndexManagedByILM(IndexMetadata indexMetadata) {
1097
1109
}
1098
1110
1099
1111
static boolean isStateEquals (ProjectMetadata project1 , ProjectMetadata project2 ) {
1112
+ if (project1 .settings ().equals (project2 .settings ()) == false ) {
1113
+ return false ;
1114
+ }
1100
1115
if (project1 .templates ().equals (project2 .templates ()) == false ) {
1101
1116
return false ;
1102
1117
}
@@ -1130,6 +1145,7 @@ public static class Builder {
1130
1145
private final ImmutableOpenMap .Builder <String , IndexTemplateMetadata > templates ;
1131
1146
private final ImmutableOpenMap .Builder <String , Metadata .ProjectCustom > customs ;
1132
1147
private final ImmutableOpenMap .Builder <String , ReservedStateMetadata > reservedStateMetadata ;
1148
+ private Settings settings = Settings .EMPTY ;
1133
1149
1134
1150
private SortedMap <String , IndexAbstraction > previousIndicesLookup ;
1135
1151
@@ -1147,6 +1163,7 @@ public static class Builder {
1147
1163
this .templates = ImmutableOpenMap .builder (projectMetadata .templates );
1148
1164
this .customs = ImmutableOpenMap .builder (projectMetadata .customs );
1149
1165
this .reservedStateMetadata = ImmutableOpenMap .builder (projectMetadata .reservedStateMetadata );
1166
+ this .settings = projectMetadata .settings ;
1150
1167
this .previousIndicesLookup = projectMetadata .indicesLookup ;
1151
1168
this .mappingsByHash = new HashMap <>(projectMetadata .mappingsByHash );
1152
1169
this .checkForUnusedMappings = false ;
@@ -1525,6 +1542,11 @@ public Builder removeReservedState(ReservedStateMetadata metadata) {
1525
1542
return this ;
1526
1543
}
1527
1544
1545
+ public Builder settings (Settings settings ) {
1546
+ this .settings = settings ;
1547
+ return this ;
1548
+ }
1549
+
1528
1550
public Builder indexGraveyard (final IndexGraveyard indexGraveyard ) {
1529
1551
return putCustom (IndexGraveyard .TYPE , indexGraveyard );
1530
1552
}
@@ -1684,6 +1706,7 @@ public ProjectMetadata build(boolean skipNameCollisionChecks) {
1684
1706
visibleClosedIndicesArray ,
1685
1707
indicesLookup ,
1686
1708
Collections .unmodifiableMap (mappingsByHash ),
1709
+ settings ,
1687
1710
IndexVersion .fromId (oldestIndexVersionId )
1688
1711
);
1689
1712
}
@@ -2110,6 +2133,9 @@ public static ProjectMetadata fromXContent(XContentParser parser) throws IOExcep
2110
2133
projectBuilder .put (IndexTemplateMetadata .Builder .fromXContent (parser , parser .currentName ()));
2111
2134
}
2112
2135
}
2136
+ case "settings" -> {
2137
+ projectBuilder .settings (Settings .fromXContent (parser ));
2138
+ }
2113
2139
default -> Metadata .Builder .parseCustomObject (
2114
2140
parser ,
2115
2141
currentFieldName ,
@@ -2155,6 +2181,11 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) {
2155
2181
),
2156
2182
indices ,
2157
2183
customs ,
2184
+ multiProject ? Iterators .single ((builder , params ) -> {
2185
+ builder .startObject ("settings" );
2186
+ settings .toXContent (builder , new ToXContent .MapParams (Collections .singletonMap ("flat_settings" , "true" )));
2187
+ return builder .endObject ();
2188
+ }) : Collections .emptyIterator (),
2158
2189
multiProject
2159
2190
? ChunkedToXContentHelper .object ("reserved_state" , reservedStateMetadata ().values ().iterator ())
2160
2191
: Collections .emptyIterator ()
@@ -2189,6 +2220,10 @@ public static ProjectMetadata readFrom(StreamInput in) throws IOException {
2189
2220
builder .put (ReservedStateMetadata .readFrom (in ));
2190
2221
}
2191
2222
2223
+ if (in .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_METADATA_SETTINGS )) {
2224
+ builder .settings (Settings .readSettingsFromStream (in ));
2225
+ }
2226
+
2192
2227
return builder .build ();
2193
2228
}
2194
2229
@@ -2229,6 +2264,10 @@ public void writeTo(StreamOutput out) throws IOException {
2229
2264
}
2230
2265
VersionedNamedWriteable .writeVersionedWriteables (out , filteredCustoms );
2231
2266
out .writeCollection (reservedStateMetadata .values ());
2267
+
2268
+ if (out .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_METADATA_SETTINGS )) {
2269
+ settings .writeTo (out );
2270
+ }
2232
2271
}
2233
2272
2234
2273
// this needs to be package accessible for bwc serialization in Metadata.java
@@ -2248,13 +2287,15 @@ static class ProjectMetadataDiff implements Diff<ProjectMetadata> {
2248
2287
String ,
2249
2288
ReservedStateMetadata ,
2250
2289
ImmutableOpenMap <String , ReservedStateMetadata >> reservedStateMetadata ;
2290
+ private final Diff <Settings > settingsDiff ;
2251
2291
2252
2292
private ProjectMetadataDiff (ProjectMetadata before , ProjectMetadata after ) {
2253
2293
if (before == after ) {
2254
2294
indices = DiffableUtils .emptyDiff ();
2255
2295
templates = DiffableUtils .emptyDiff ();
2256
2296
customs = DiffableUtils .emptyDiff ();
2257
2297
reservedStateMetadata = DiffableUtils .emptyDiff ();
2298
+ settingsDiff = Settings .EMPTY_DIFF ;
2258
2299
} else {
2259
2300
indices = DiffableUtils .diff (before .indices , after .indices , DiffableUtils .getStringKeySerializer ());
2260
2301
templates = DiffableUtils .diff (before .templates , after .templates , DiffableUtils .getStringKeySerializer ());
@@ -2269,19 +2310,22 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) {
2269
2310
after .reservedStateMetadata ,
2270
2311
DiffableUtils .getStringKeySerializer ()
2271
2312
);
2313
+ settingsDiff = after .settings .diff (before .settings );
2272
2314
}
2273
2315
}
2274
2316
2275
2317
ProjectMetadataDiff (
2276
2318
DiffableUtils .MapDiff <String , IndexMetadata , ImmutableOpenMap <String , IndexMetadata >> indices ,
2277
2319
DiffableUtils .MapDiff <String , IndexTemplateMetadata , ImmutableOpenMap <String , IndexTemplateMetadata >> templates ,
2278
2320
DiffableUtils .MapDiff <String , Metadata .ProjectCustom , ImmutableOpenMap <String , Metadata .ProjectCustom >> customs ,
2279
- DiffableUtils .MapDiff <String , ReservedStateMetadata , ImmutableOpenMap <String , ReservedStateMetadata >> reservedStateMetadata
2321
+ DiffableUtils .MapDiff <String , ReservedStateMetadata , ImmutableOpenMap <String , ReservedStateMetadata >> reservedStateMetadata ,
2322
+ Diff <Settings > settingsDiff
2280
2323
) {
2281
2324
this .indices = indices ;
2282
2325
this .templates = templates ;
2283
2326
this .customs = customs ;
2284
2327
this .reservedStateMetadata = reservedStateMetadata ;
2328
+ this .settingsDiff = settingsDiff ;
2285
2329
}
2286
2330
2287
2331
ProjectMetadataDiff (StreamInput in ) throws IOException {
@@ -2293,6 +2337,11 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) {
2293
2337
DiffableUtils .getStringKeySerializer (),
2294
2338
RESERVED_DIFF_VALUE_READER
2295
2339
);
2340
+ if (in .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_METADATA_SETTINGS )) {
2341
+ settingsDiff = Settings .readSettingsDiffFromStream (in );
2342
+ } else {
2343
+ settingsDiff = Settings .EMPTY_DIFF ;
2344
+ }
2296
2345
}
2297
2346
2298
2347
Diff <ImmutableOpenMap <String , IndexMetadata >> indices () {
@@ -2317,11 +2366,18 @@ public void writeTo(StreamOutput out) throws IOException {
2317
2366
templates .writeTo (out );
2318
2367
customs .writeTo (out );
2319
2368
reservedStateMetadata .writeTo (out );
2369
+ if (out .getTransportVersion ().onOrAfter (TransportVersions .PROJECT_METADATA_SETTINGS )) {
2370
+ settingsDiff .writeTo (out );
2371
+ }
2320
2372
}
2321
2373
2322
2374
@ Override
2323
2375
public ProjectMetadata apply (ProjectMetadata part ) {
2324
- if (indices .isEmpty () && templates .isEmpty () && customs .isEmpty () && reservedStateMetadata .isEmpty ()) {
2376
+ if (indices .isEmpty ()
2377
+ && templates .isEmpty ()
2378
+ && customs .isEmpty ()
2379
+ && reservedStateMetadata .isEmpty ()
2380
+ && settingsDiff == Settings .EMPTY_DIFF ) {
2325
2381
// nothing to do
2326
2382
return part ;
2327
2383
}
@@ -2336,13 +2392,14 @@ public ProjectMetadata apply(ProjectMetadata part) {
2336
2392
&& builder .dataStreamMetadata () == part .custom (DataStreamMetadata .TYPE , DataStreamMetadata .EMPTY )) {
2337
2393
builder .previousIndicesLookup = part .indicesLookup ;
2338
2394
}
2395
+ builder .settings = settingsDiff .apply (part .settings );
2339
2396
return builder .build (true );
2340
2397
}
2341
2398
2342
2399
ProjectMetadataDiff withCustoms (
2343
2400
DiffableUtils .MapDiff <String , Metadata .ProjectCustom , ImmutableOpenMap <String , Metadata .ProjectCustom >> customs
2344
2401
) {
2345
- return new ProjectMetadataDiff (indices , templates , customs , reservedStateMetadata );
2402
+ return new ProjectMetadataDiff (indices , templates , customs , reservedStateMetadata , settingsDiff );
2346
2403
}
2347
2404
}
2348
2405
0 commit comments