Skip to content

Commit 077b585

Browse files
authored
Introduce data stream options and failure store configuration classes (elastic#109515)
In order to facilitate enabling and disabling the failure store & component template composition, we introduce new metadata classes that can support a more extensible failure store configuration. We would like to introduce **data stream options**. Data stream options capture the configuration of data stream level (smaller and larger) features, such the failure store and in the future data stream lifecycle. They are different than settings because they are applied on a data stream level and not per backing index. This PR is only setting the basic classes to enable follow up PRs that will actually use them. Examples, these are not final, they are only used to help visualise a potential direction: ``` GET _data_stream/my-*/_options { "data_streams": [ { "name": "my-non-opinionated-ds", "options": { } }, { "name": "my-fs", "options": { "failure_store": { "enabled": true } } }, { "name": "my-no-fs", "options": { "failure_store": { "enabled": false } } } ] } // If we decide to add lifecycle here too: PUT _data_stream/my-fs/_options { "failure_store": { "enabled": true }, "lifecycle": { } } ``` What we see above are 3 data streams: - `my-fs` with the failure store explicitly enabled - `my-no-fs` with the failure store explicitly disabled, and - `my-non-opinionated-ds` which does not specify what to do with the failure store, so for now it means failure store disabled but that could change in the future. Template composition examples pending
1 parent 3d7c7cf commit 077b585

File tree

4 files changed

+255
-0
lines changed

4 files changed

+255
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.cluster.metadata;
10+
11+
import org.elasticsearch.cluster.Diff;
12+
import org.elasticsearch.cluster.SimpleDiffable;
13+
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.common.io.stream.StreamInput;
15+
import org.elasticsearch.common.io.stream.StreamOutput;
16+
import org.elasticsearch.xcontent.ConstructingObjectParser;
17+
import org.elasticsearch.xcontent.ParseField;
18+
import org.elasticsearch.xcontent.ToXContentObject;
19+
import org.elasticsearch.xcontent.XContentBuilder;
20+
import org.elasticsearch.xcontent.XContentParser;
21+
22+
import java.io.IOException;
23+
24+
/**
25+
* Holds the data stream failure store metadata that enable or disable the failure store of a data stream. Currently, it
26+
* supports the following configurations:
27+
* - enabled
28+
*/
29+
public record DataStreamFailureStore(boolean enabled) implements SimpleDiffable<DataStreamFailureStore>, ToXContentObject {
30+
31+
public static final ParseField ENABLED_FIELD = new ParseField("enabled");
32+
33+
public static final ConstructingObjectParser<DataStreamFailureStore, Void> PARSER = new ConstructingObjectParser<>(
34+
"failure_store",
35+
false,
36+
(args, unused) -> new DataStreamFailureStore(args[0] == null || (Boolean) args[0])
37+
);
38+
39+
static {
40+
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ENABLED_FIELD);
41+
}
42+
43+
public DataStreamFailureStore() {
44+
this(true);
45+
}
46+
47+
public DataStreamFailureStore(StreamInput in) throws IOException {
48+
this(in.readBoolean());
49+
}
50+
51+
public static Diff<DataStreamFailureStore> readDiffFrom(StreamInput in) throws IOException {
52+
return SimpleDiffable.readDiffFrom(DataStreamFailureStore::new, in);
53+
}
54+
55+
@Override
56+
public void writeTo(StreamOutput out) throws IOException {
57+
out.writeBoolean(enabled);
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return Strings.toString(this, true, true);
63+
}
64+
65+
@Override
66+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
67+
builder.startObject();
68+
builder.field(ENABLED_FIELD.getPreferredName(), enabled);
69+
builder.endObject();
70+
return builder;
71+
}
72+
73+
public static DataStreamFailureStore fromXContent(XContentParser parser) throws IOException {
74+
return PARSER.parse(parser, null);
75+
}
76+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.cluster.metadata;
10+
11+
import org.elasticsearch.cluster.Diff;
12+
import org.elasticsearch.cluster.SimpleDiffable;
13+
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.common.io.stream.StreamInput;
15+
import org.elasticsearch.common.io.stream.StreamOutput;
16+
import org.elasticsearch.core.Nullable;
17+
import org.elasticsearch.xcontent.ConstructingObjectParser;
18+
import org.elasticsearch.xcontent.ObjectParser;
19+
import org.elasticsearch.xcontent.ParseField;
20+
import org.elasticsearch.xcontent.ToXContentObject;
21+
import org.elasticsearch.xcontent.XContentBuilder;
22+
import org.elasticsearch.xcontent.XContentParser;
23+
24+
import java.io.IOException;
25+
26+
/**
27+
* Holds data stream dedicated configuration options such as failure store, (in the future lifecycle). Currently, it
28+
* supports the following configurations:
29+
* - failure store
30+
*/
31+
public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore)
32+
implements
33+
SimpleDiffable<DataStreamOptions>,
34+
ToXContentObject {
35+
36+
public static final ParseField FAILURE_STORE_FIELD = new ParseField("failure_store");
37+
38+
public static final ConstructingObjectParser<DataStreamOptions, Void> PARSER = new ConstructingObjectParser<>(
39+
"options",
40+
false,
41+
(args, unused) -> new DataStreamOptions((DataStreamFailureStore) args[0])
42+
);
43+
44+
static {
45+
PARSER.declareField(
46+
ConstructingObjectParser.optionalConstructorArg(),
47+
(p, c) -> DataStreamFailureStore.fromXContent(p),
48+
FAILURE_STORE_FIELD,
49+
ObjectParser.ValueType.OBJECT_OR_NULL
50+
);
51+
}
52+
53+
public DataStreamOptions() {
54+
this(null);
55+
}
56+
57+
public static DataStreamOptions read(StreamInput in) throws IOException {
58+
return new DataStreamOptions(in.readOptionalWriteable(DataStreamFailureStore::new));
59+
}
60+
61+
@Nullable
62+
public DataStreamFailureStore getFailureStore() {
63+
return failureStore;
64+
}
65+
66+
public static Diff<DataStreamOptions> readDiffFrom(StreamInput in) throws IOException {
67+
return SimpleDiffable.readDiffFrom(DataStreamOptions::read, in);
68+
}
69+
70+
@Override
71+
public void writeTo(StreamOutput out) throws IOException {
72+
out.writeOptionalWriteable(failureStore);
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return Strings.toString(this, true, true);
78+
}
79+
80+
@Override
81+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
82+
builder.startObject();
83+
if (failureStore != null) {
84+
builder.field(FAILURE_STORE_FIELD.getPreferredName(), failureStore);
85+
}
86+
builder.endObject();
87+
return builder;
88+
}
89+
90+
public static DataStreamOptions fromXContent(XContentParser parser) throws IOException {
91+
return PARSER.parse(parser, null);
92+
}
93+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.cluster.metadata;
10+
11+
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.test.AbstractXContentSerializingTestCase;
13+
import org.elasticsearch.xcontent.XContentParser;
14+
15+
import java.io.IOException;
16+
17+
public class DataStreamFailureStoreTests extends AbstractXContentSerializingTestCase<DataStreamFailureStore> {
18+
19+
@Override
20+
protected Writeable.Reader<DataStreamFailureStore> instanceReader() {
21+
return DataStreamFailureStore::new;
22+
}
23+
24+
@Override
25+
protected DataStreamFailureStore createTestInstance() {
26+
return randomFailureStore();
27+
}
28+
29+
@Override
30+
protected DataStreamFailureStore mutateInstance(DataStreamFailureStore instance) throws IOException {
31+
return new DataStreamFailureStore(instance.enabled() == false);
32+
}
33+
34+
@Override
35+
protected DataStreamFailureStore doParseInstance(XContentParser parser) throws IOException {
36+
return DataStreamFailureStore.fromXContent(parser);
37+
}
38+
39+
static DataStreamFailureStore randomFailureStore() {
40+
return new DataStreamFailureStore(randomBoolean());
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.cluster.metadata;
10+
11+
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.test.AbstractXContentSerializingTestCase;
13+
import org.elasticsearch.xcontent.XContentParser;
14+
15+
import java.io.IOException;
16+
17+
public class DataStreamOptionsTests extends AbstractXContentSerializingTestCase<DataStreamOptions> {
18+
19+
@Override
20+
protected Writeable.Reader<DataStreamOptions> instanceReader() {
21+
return DataStreamOptions::read;
22+
}
23+
24+
@Override
25+
protected DataStreamOptions createTestInstance() {
26+
return new DataStreamOptions(randomBoolean() ? null : DataStreamFailureStoreTests.randomFailureStore());
27+
}
28+
29+
@Override
30+
protected DataStreamOptions mutateInstance(DataStreamOptions instance) throws IOException {
31+
var failureStore = instance.getFailureStore();
32+
if (failureStore == null) {
33+
failureStore = DataStreamFailureStoreTests.randomFailureStore();
34+
} else {
35+
failureStore = randomBoolean() ? null : new DataStreamFailureStore(failureStore.enabled() == false);
36+
}
37+
return new DataStreamOptions(failureStore);
38+
}
39+
40+
@Override
41+
protected DataStreamOptions doParseInstance(XContentParser parser) throws IOException {
42+
return DataStreamOptions.fromXContent(parser);
43+
}
44+
}

0 commit comments

Comments
 (0)