From 237eea280e110bf84ae4b858bf514751be96b941 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 9 Nov 2023 09:14:18 -0600 Subject: [PATCH] correctly serializing UpdateSettingsRequest --- .../main/java/org/elasticsearch/TransportVersions.java | 1 + .../indices/settings/put/UpdateSettingsRequest.java | 9 ++++++++- .../put/UpdateSettingsRequestSerializationTests.java | 2 ++ .../indices/settings/put/UpdateSettingsRequestTests.java | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 0c7145730e447..a5ae22a879e2a 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -161,6 +161,7 @@ static TransportVersion def(int id) { public static final TransportVersion UNDESIRED_SHARD_ALLOCATIONS_COUNT_ADDED = def(8_530_00_0); public static final TransportVersion ML_INFERENCE_TASK_SETTINGS_OPTIONAL_ADDED = def(8_531_00_0); public static final TransportVersion DEPRECATED_COMPONENT_TEMPLATES_ADDED = def(8_532_00_0); + public static final TransportVersion UPDATE_NON_DYNAMIC_SETTINGS_ADDED = def(8_533_00_0); /* * STOP! READ THIS FIRST! No, really, diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index 6c7ff917e5a66..013e568eff7c9 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -58,6 +58,9 @@ public UpdateSettingsRequest(StreamInput in) throws IOException { if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_12_0)) { origin = in.readString(); } + if (in.getTransportVersion().onOrAfter(TransportVersions.UPDATE_NON_DYNAMIC_SETTINGS_ADDED)) { + reopen = in.readBoolean(); + } } public UpdateSettingsRequest() {} @@ -200,6 +203,9 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_12_0)) { out.writeString(origin); } + if (out.getTransportVersion().onOrAfter(TransportVersions.UPDATE_NON_DYNAMIC_SETTINGS_ADDED)) { + out.writeBoolean(reopen); + } } @Override @@ -257,12 +263,13 @@ public boolean equals(Object o) { && Objects.equals(settings, that.settings) && Objects.equals(indicesOptions, that.indicesOptions) && Objects.equals(preserveExisting, that.preserveExisting) + && Objects.equals(reopen, that.reopen) && Arrays.equals(indices, that.indices); } @Override public int hashCode() { - return Objects.hash(masterNodeTimeout, timeout, settings, indicesOptions, preserveExisting, Arrays.hashCode(indices)); + return Objects.hash(masterNodeTimeout, timeout, settings, indicesOptions, preserveExisting, reopen, Arrays.hashCode(indices)); } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestSerializationTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestSerializationTests.java index e9fa64ce0b0a3..9ff323028e2c5 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestSerializationTests.java @@ -45,6 +45,7 @@ protected UpdateSettingsRequest mutateInstance(UpdateSettingsRequest request) { ) ); mutators.add(() -> mutation.setPreserveExisting(request.isPreserveExisting() == false)); + mutators.add(() -> mutation.reopen(request.reopen() == false)); randomFrom(mutators).run(); return mutation; } @@ -67,6 +68,7 @@ public static UpdateSettingsRequest createTestItem() { request.timeout(randomTimeValue()); request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())); request.setPreserveExisting(randomBoolean()); + request.reopen(randomBoolean()); return request; } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestTests.java index b997d2a421204..48ab2b0802616 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestTests.java @@ -64,6 +64,9 @@ protected UpdateSettingsRequest createTestInstance() { private static UpdateSettingsRequest createTestInstance(boolean enclosedSettings) { UpdateSettingsRequest testRequest = UpdateSettingsRequestSerializationTests.createTestItem(); + if (randomBoolean()) { + testRequest.reopen(true); + } if (enclosedSettings) { UpdateSettingsRequest requestWithEnclosingSettings = new UpdateSettingsRequest(testRequest.settings()) { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { @@ -75,6 +78,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } }; + requestWithEnclosingSettings.reopen(testRequest.reopen()); return requestWithEnclosingSettings; } return testRequest;