Skip to content

Commit

Permalink
Update supported version for the primary_only parameter in force-merg…
Browse files Browse the repository at this point in the history
…e API (opensearch-project#12657)

* Update supported version for adding primary_only parameter to force-merge API

Signed-off-by: Gao Binlong <[email protected]>

* Modify change log

Signed-off-by: Gao Binlong <[email protected]>

* Remove some unused code

Signed-off-by: Gao Binlong <[email protected]>

* Remove change log

Signed-off-by: Gao Binlong <[email protected]>

* Fix test issue

Signed-off-by: Gao Binlong <[email protected]>

---------

Signed-off-by: Gao Binlong <[email protected]>
  • Loading branch information
gaobinlong authored Mar 20, 2024
1 parent f4a8d2b commit 1b4c76d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
# will return a task immediately and the merge process will run in background.

- skip:
version: " - 2.99.99"
reason: "only available in 3.0+"
features: allowed_warnings
version: " - 2.6.99, 2.13.0 - "
reason: "wait_for_completion was introduced in 2.7.0 and task description was changed in 2.13.0"
features: allowed_warnings, node_selector

- do:
indices.create:
index: test_index

- do:
node_selector:
version: " 2.7.0 - 2.12.99"
indices.forcemerge:
index: test_index
wait_for_completion: false
Expand All @@ -25,8 +27,31 @@
wait_for_completion: true
task_id: $taskId
- match: { task.action: "indices:admin/forcemerge" }
- match: { task.description: "Force-merge indices [test_index], maxSegments[1], onlyExpungeDeletes[false], flush[true], primaryOnly[false]" }
- match: { task.description: "Force-merge indices [test_index], maxSegments[1], onlyExpungeDeletes[false], flush[true]" }

---
"Force merge index with wait_for_completion after task description changed":
- skip:
version: " - 2.12.99 "
reason: "task description was changed in 2.13.0"
features: allowed_warnings, node_selector

- do:
node_selector:
version: " 2.13.0 - "
indices.forcemerge:
index: test_index
wait_for_completion: false
max_num_segments: 1
- match: { task: /^.+$/ }
- set: { task: taskId }

- do:
tasks.get:
wait_for_completion: true
task_id: $taskId
- match: { task.action: "indices:admin/forcemerge" }
- match: { task.description: "Force-merge indices [test_index], maxSegments[1], onlyExpungeDeletes[false], flush[true], primaryOnly[false]" }
# .tasks index is created when the force-merge operation completes, so we should delete .tasks index finally,
# if not, the .tasks index may introduce unexpected warnings and then cause other test cases to fail.
# Delete the .tasks index directly will also introduce warning, but currently we don't have such APIs which can delete one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public ForceMergeRequest(StreamInput in) throws IOException {
maxNumSegments = in.readInt();
onlyExpungeDeletes = in.readBoolean();
flush = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_13_0)) {
primaryOnly = in.readBoolean();
}
if (in.getVersion().onOrAfter(FORCE_MERGE_UUID_VERSION)) {
Expand Down Expand Up @@ -219,7 +219,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(maxNumSegments);
out.writeBoolean(onlyExpungeDeletes);
out.writeBoolean(flush);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_13_0)) {
out.writeBoolean(primaryOnly);
}
if (out.getVersion().onOrAfter(FORCE_MERGE_UUID_VERSION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
package org.opensearch.action.admin.indices.forcemerge;

import org.opensearch.Version;
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.tasks.TaskId;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.VersionUtils;

Expand Down Expand Up @@ -95,61 +97,64 @@ public void testSerialization() throws Exception {
public void testBwcSerialization() throws Exception {
{
final ForceMergeRequest sample = randomRequest();
final Version compatibleVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(compatibleVersion);
out.setVersion(version);
sample.writeTo(out);

final ForceMergeRequest deserializedRequest;
try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(Version.CURRENT);
deserializedRequest = new ForceMergeRequest(in);
}

assertEquals(sample.maxNumSegments(), deserializedRequest.maxNumSegments());
assertEquals(sample.onlyExpungeDeletes(), deserializedRequest.onlyExpungeDeletes());
assertEquals(sample.flush(), deserializedRequest.flush());
if (compatibleVersion.onOrAfter(Version.V_3_0_0)) {
assertEquals(sample.primaryOnly(), deserializedRequest.primaryOnly());
assertEquals(sample.forceMergeUUID(), deserializedRequest.forceMergeUUID());
in.setVersion(version);
TaskId.readFromStream(in);
in.readStringArray();
IndicesOptions.readIndicesOptions(in);
int maxNumSegments = in.readInt();
boolean onlyExpungeDeletes = in.readBoolean();
boolean flush = in.readBoolean();
boolean primaryOnly = in.readBoolean();
String forceMergeUUID;
if (version.onOrAfter(Version.V_3_0_0)) {
forceMergeUUID = in.readString();
} else {
forceMergeUUID = in.readOptionalString();
}
assertEquals(sample.maxNumSegments(), maxNumSegments);
assertEquals(sample.onlyExpungeDeletes(), onlyExpungeDeletes);
assertEquals(sample.flush(), flush);
assertEquals(sample.primaryOnly(), primaryOnly);
assertEquals(sample.forceMergeUUID(), forceMergeUUID);
}
}
}

{
final ForceMergeRequest sample = randomRequest();
final Version compatibleVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(Version.CURRENT);
out.setVersion(version);
sample.getParentTask().writeTo(out);
out.writeStringArray(sample.indices());
sample.indicesOptions().writeIndicesOptions(out);
out.writeInt(sample.maxNumSegments());
out.writeBoolean(sample.onlyExpungeDeletes());
out.writeBoolean(sample.flush());
if (compatibleVersion.onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(sample.primaryOnly());
}
if (compatibleVersion.onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(sample.primaryOnly());
if (version.onOrAfter(Version.V_3_0_0)) {
out.writeString(sample.forceMergeUUID());
} else {
out.writeOptionalString(sample.forceMergeUUID());
}

final ForceMergeRequest deserializedRequest;
try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(compatibleVersion);
in.setVersion(version);
deserializedRequest = new ForceMergeRequest(in);
}

assertEquals(sample.maxNumSegments(), deserializedRequest.maxNumSegments());
assertEquals(sample.onlyExpungeDeletes(), deserializedRequest.onlyExpungeDeletes());
assertEquals(sample.flush(), deserializedRequest.flush());
if (compatibleVersion.onOrAfter(Version.V_3_0_0)) {
assertEquals(sample.primaryOnly(), deserializedRequest.primaryOnly());
}
assertEquals(sample.primaryOnly(), deserializedRequest.primaryOnly());
assertEquals(sample.forceMergeUUID(), deserializedRequest.forceMergeUUID());

}
}
}
Expand Down

0 comments on commit 1b4c76d

Please sign in to comment.