Skip to content

Commit

Permalink
Rename failure store field and methods (#107399)
Browse files Browse the repository at this point in the history
This name better reflects that the field is a boolean.
  • Loading branch information
nielsbauman committed Apr 12, 2024
1 parent 5ebb14a commit beed68d
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static GetDataStreamAction.Response innerOperation(
Map<Index, IndexProperties> backingIndicesSettingsValues = new HashMap<>();
Metadata metadata = state.getMetadata();
collectIndexSettingsValues(dataStream, backingIndicesSettingsValues, metadata, dataStream.getIndices());
if (DataStream.isFailureStoreEnabled() && dataStream.getFailureIndices().isEmpty() == false) {
if (DataStream.isFailureStoreFeatureFlagEnabled() && dataStream.getFailureIndices().isEmpty() == false) {
collectIndexSettingsValues(dataStream, backingIndicesSettingsValues, metadata, dataStream.getFailureIndices());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testDeleteDataStream() {
}

public void testDeleteDataStreamWithFailureStore() {
Assume.assumeTrue(DataStream.isFailureStoreEnabled());
Assume.assumeTrue(DataStream.isFailureStoreFeatureFlagEnabled());

final String dataStreamName = "my-data-stream";
final List<String> otherIndices = randomSubsetOf(List.of("foo", "bar", "baz"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
.setAllowCustomRouting(true)
.setIndexMode(IndexMode.STANDARD)
.setLifecycle(new DataStreamLifecycle())
.setFailureStore(true)
.setFailureStoreEnabled(true)
.setFailureIndices(failureStores)
.build();

Expand Down Expand Up @@ -158,7 +158,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
is(ManagedBy.LIFECYCLE.displayValue)
);

if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
List<Object> failureStoresRepresentation = (List<Object>) dataStreamMap.get(
DataStream.FAILURE_INDICES_FIELD.getPreferredName()
);
Expand All @@ -184,7 +184,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
.setAllowCustomRouting(true)
.setIndexMode(IndexMode.STANDARD)
.setLifecycle(new DataStreamLifecycle(null, null, false))
.setFailureStore(true)
.setFailureStoreEnabled(true)
.setFailureIndices(failureStores)
.build();

Expand Down Expand Up @@ -250,7 +250,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
is(ManagedBy.UNMANAGED.displayValue)
);

if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
List<Object> failureStoresRepresentation = (List<Object>) dataStreamMap.get(
DataStream.FAILURE_INDICES_FIELD.getPreferredName()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Feature[] fromRequest(RestRequest request) {

public GetIndexRequest() {
super(
DataStream.isFailureStoreEnabled()
DataStream.isFailureStoreFeatureFlagEnabled()
? IndicesOptions.builder(IndicesOptions.strictExpandOpen())
.failureStoreOptions(
IndicesOptions.FailureStoreOptions.builder().includeRegularIndices(true).includeFailureIndices(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ static void validate(
);
}
var dataStream = (DataStream) indexAbstraction;
if (isFailureStoreRollover && dataStream.isFailureStore() == false) {
if (isFailureStoreRollover && dataStream.isFailureStoreEnabled() == false) {
throw new IllegalArgumentException(
"unable to roll over failure store because [" + indexAbstraction.getName() + "] does not have the failure store enabled"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void executeBulkRequestsByShard(
}

private void redirectFailuresOrCompleteBulkOperation() {
if (DataStream.isFailureStoreEnabled() && failureStoreRedirects.isEmpty() == false) {
if (DataStream.isFailureStoreFeatureFlagEnabled() && failureStoreRedirects.isEmpty() == false) {
doRedirectFailures();
} else {
completeBulkOperation();
Expand Down Expand Up @@ -412,7 +412,7 @@ private void completeShardOperation() {
*/
private static String getRedirectTarget(DocWriteRequest<?> docWriteRequest, Metadata metadata) {
// Feature flag guard
if (DataStream.isFailureStoreEnabled() == false) {
if (DataStream.isFailureStoreFeatureFlagEnabled() == false) {
return null;
}
// Do not resolve a failure store for documents that were already headed to one
Expand All @@ -431,7 +431,7 @@ private static String getRedirectTarget(DocWriteRequest<?> docWriteRequest, Meta
Index concreteIndex = ia.getWriteIndex();
IndexAbstraction writeIndexAbstraction = metadata.getIndicesLookup().get(concreteIndex.getName());
DataStream parentDataStream = writeIndexAbstraction.getParentDataStream();
if (parentDataStream != null && parentDataStream.isFailureStore()) {
if (parentDataStream != null && parentDataStream.isFailureStoreEnabled()) {
// Keep the data stream name around to resolve the redirect to failure store if the shard level request fails.
return parentDataStream.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ synchronized void markItemAsDropped(int slot) {
* @param e the failure encountered.
*/
public void markItemForFailureStore(int slot, String targetIndexName, Exception e) {
if (DataStream.isFailureStoreEnabled() == false) {
if (DataStream.isFailureStoreFeatureFlagEnabled() == false) {
// Assert false for development, but if we somehow find ourselves here, default to failure logic.
assert false
: "Attempting to route a failed write request type to a failure store but the failure store is not enabled! "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public boolean isForceExecution() {
* or if it matches a template that has a data stream failure store enabled.
*/
static boolean shouldStoreFailure(String indexName, Metadata metadata, long epochMillis) {
return DataStream.isFailureStoreEnabled()
return DataStream.isFailureStoreFeatureFlagEnabled()
&& resolveFailureStoreFromMetadata(indexName, metadata, epochMillis).or(
() -> resolveFailureStoreFromTemplate(indexName, metadata)
).orElse(false);
Expand Down Expand Up @@ -774,7 +774,7 @@ private static Optional<Boolean> resolveFailureStoreFromMetadata(String indexNam
DataStream targetDataStream = writeAbstraction.getParentDataStream();

// We will store the failure if the write target belongs to a data stream with a failure store.
return Optional.of(targetDataStream != null && targetDataStream.isFailureStore());
return Optional.of(targetDataStream != null && targetDataStream.isFailureStoreEnabled());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public XContentBuilder toXContent(
builder.endArray();
}
builder.field(DataStream.GENERATION_FIELD.getPreferredName(), dataStream.getGeneration());
if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
builder.field(DataStream.FAILURE_INDICES_FIELD.getPreferredName());
builder.startArray();
for (Index failureStore : dataStream.getFailureIndices()) {
Expand Down Expand Up @@ -358,8 +358,8 @@ public XContentBuilder toXContent(
builder.field(ALLOW_CUSTOM_ROUTING.getPreferredName(), dataStream.isAllowCustomRouting());
builder.field(REPLICATED.getPreferredName(), dataStream.isReplicated());
builder.field(ROLLOVER_ON_WRITE.getPreferredName(), dataStream.rolloverOnWrite());
if (DataStream.isFailureStoreEnabled()) {
builder.field(DataStream.FAILURE_STORE_FIELD.getPreferredName(), dataStream.isFailureStore());
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
builder.field(DataStream.FAILURE_STORE_FIELD.getPreferredName(), dataStream.isFailureStoreEnabled());
}
if (dataStream.getAutoShardingEvent() != null) {
DataStreamAutoShardingEvent autoShardingEvent = dataStream.getAutoShardingEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public IndexRequest setRequireDataStream(boolean requireDataStream) {

@Override
public Index getConcreteWriteIndex(IndexAbstraction ia, Metadata metadata) {
if (DataStream.isFailureStoreEnabled() && writeToFailureStore) {
if (DataStream.isFailureStoreFeatureFlagEnabled() && writeToFailureStore) {
if (ia.isDataStreamRelated() == false) {
throw new ElasticsearchException(
"Attempting to write a document to a failure store but the targeted index is not a data stream"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,15 +1109,15 @@ public static IndicesOptions fromRequest(RestRequest request, IndicesOptions def
request.param(ConcreteTargetOptions.IGNORE_UNAVAILABLE),
request.param(WildcardOptions.ALLOW_NO_INDICES),
request.param(GatekeeperOptions.IGNORE_THROTTLED),
DataStream.isFailureStoreEnabled()
DataStream.isFailureStoreFeatureFlagEnabled()
? request.param(FailureStoreOptions.FAILURE_STORE)
: FailureStoreOptions.INCLUDE_ONLY_REGULAR_INDICES,
defaultSettings
);
}

public static IndicesOptions fromMap(Map<String, Object> map, IndicesOptions defaultSettings) {
if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
return fromParameters(
map.containsKey(WildcardOptions.EXPAND_WILDCARDS) ? map.get(WildcardOptions.EXPAND_WILDCARDS) : map.get("expandWildcards"),
map.containsKey(ConcreteTargetOptions.IGNORE_UNAVAILABLE)
Expand Down Expand Up @@ -1155,8 +1155,8 @@ public static boolean isIndicesOptions(String name) {
|| "ignoreThrottled".equals(name)
|| WildcardOptions.ALLOW_NO_INDICES.equals(name)
|| "allowNoIndices".equals(name)
|| (DataStream.isFailureStoreEnabled() && FailureStoreOptions.FAILURE_STORE.equals(name))
|| (DataStream.isFailureStoreEnabled() && "failureStore".equals(name));
|| (DataStream.isFailureStoreFeatureFlagEnabled() && FailureStoreOptions.FAILURE_STORE.equals(name))
|| (DataStream.isFailureStoreFeatureFlagEnabled() && "failureStore".equals(name));
}

public static IndicesOptions fromParameters(
Expand Down Expand Up @@ -1187,7 +1187,7 @@ public static IndicesOptions fromParameters(

WildcardOptions wildcards = WildcardOptions.parseParameters(wildcardsString, allowNoIndicesString, defaultSettings.wildcardOptions);
GatekeeperOptions gatekeeperOptions = GatekeeperOptions.parseParameter(ignoreThrottled, defaultSettings.gatekeeperOptions);
FailureStoreOptions failureStoreOptions = DataStream.isFailureStoreEnabled()
FailureStoreOptions failureStoreOptions = DataStream.isFailureStoreFeatureFlagEnabled()
? FailureStoreOptions.parseParameters(failureStoreString, defaultSettings.failureStoreOptions)
: FailureStoreOptions.DEFAULT;

Expand All @@ -1205,7 +1205,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
concreteTargetOptions.toXContent(builder, params);
wildcardOptions.toXContent(builder, params);
gatekeeperOptions.toXContent(builder, params);
if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
failureStoreOptions.toXContent(builder, params);
}
return builder;
Expand Down Expand Up @@ -1276,7 +1276,7 @@ public static IndicesOptions fromXContent(XContentParser parser, @Nullable Indic
allowNoIndices = parser.booleanValue();
} else if (IGNORE_THROTTLED_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
generalOptions.ignoreThrottled(parser.booleanValue());
} else if (DataStream.isFailureStoreEnabled()
} else if (DataStream.isFailureStoreFeatureFlagEnabled()
&& FAILURE_STORE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
failureStoreOptions = FailureStoreOptions.parseParameters(parser.text(), failureStoreOptions);
} else {
Expand Down Expand Up @@ -1423,7 +1423,7 @@ public String toString() {
+ ignoreAliases()
+ ", ignore_throttled="
+ ignoreThrottled()
+ (DataStream.isFailureStoreEnabled()
+ (DataStream.isFailureStoreFeatureFlagEnabled()
? ", include_regular_indices="
+ includeRegularIndices()
+ ", include_failure_indices="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ public static class DataStreamTemplate implements Writeable, ToXContentObject {
args -> new DataStreamTemplate(
args[0] != null && (boolean) args[0],
args[1] != null && (boolean) args[1],
DataStream.isFailureStoreEnabled() && args[2] != null && (boolean) args[2]
DataStream.isFailureStoreFeatureFlagEnabled() && args[2] != null && (boolean) args[2]
)
);

static {
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), HIDDEN);
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), ALLOW_CUSTOM_ROUTING);
if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), FAILURE_STORE);
}
}
Expand Down Expand Up @@ -478,7 +478,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
builder.field("hidden", hidden);
builder.field(ALLOW_CUSTOM_ROUTING.getPreferredName(), allowCustomRouting);
if (DataStream.isFailureStoreEnabled()) {
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
builder.field(FAILURE_STORE.getPreferredName(), failureStore);
}
builder.endObject();
Expand Down
Loading

0 comments on commit beed68d

Please sign in to comment.