Skip to content

Commit f6e06a2

Browse files
bleskesjasontedor
authored andcommitted
Adapt minimum versions for seq# powered operations in Watch related requests and UpdateRequest (#38231)
After backporting #37977, #37857 and #37872
1 parent 783c9ed commit f6e06a2

File tree

8 files changed

+24
-54
lines changed

8 files changed

+24
-54
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ task verifyVersions {
159159
* the enabled state of every bwc task. It should be set back to true
160160
* after the backport of the backcompat code is complete.
161161
*/
162-
final boolean bwc_tests_enabled = false
163-
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/37951" /* place a PR link here when committing bwc changes */
162+
final boolean bwc_tests_enabled = true
163+
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
164164
if (bwc_tests_enabled == false) {
165165
if (bwc_tests_disabled_issue.isEmpty()) {
166166
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

rest-api-spec/src/main/resources/rest-api-spec/test/update/35_if_seq_no.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Update with if_seq_no":
33

44
- skip:
5-
version: " - 6.99.99"
6-
reason: if_seq_no was added in 7.0
5+
version: " - 6.6.99"
6+
reason: if_seq_no was added in 6.7.0
77

88
- do:
99
catch: missing

server/src/main/java/org/elasticsearch/action/update/UpdateRequest.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,8 @@ public void readFrom(StreamInput in) throws IOException {
879879
docAsUpsert = in.readBoolean();
880880
version = in.readLong();
881881
versionType = VersionType.fromValue(in.readByte());
882-
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
883-
ifSeqNo = in.readZLong();
884-
ifPrimaryTerm = in.readVLong();
885-
}
882+
ifSeqNo = in.readZLong();
883+
ifPrimaryTerm = in.readVLong();
886884
detectNoop = in.readBoolean();
887885
scriptedUpsert = in.readBoolean();
888886
}
@@ -934,10 +932,8 @@ public void writeTo(StreamOutput out) throws IOException {
934932
out.writeBoolean(docAsUpsert);
935933
out.writeLong(version);
936934
out.writeByte(versionType.getValue());
937-
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
938-
out.writeZLong(ifSeqNo);
939-
out.writeVLong(ifPrimaryTerm);
940-
}
935+
out.writeZLong(ifSeqNo);
936+
out.writeVLong(ifPrimaryTerm);
941937
out.writeBoolean(detectNoop);
942938
out.writeBoolean(scriptedUpsert);
943939
}

x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/watcher/PutWatchRequest.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.protocol.xpack.watcher;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionRequest;
109
import org.elasticsearch.action.ActionRequestValidationException;
1110
import org.elasticsearch.common.Strings;
@@ -60,13 +59,8 @@ public void readFrom(StreamInput in) throws IOException {
6059
active = in.readBoolean();
6160
xContentType = in.readEnum(XContentType.class);
6261
version = in.readZLong();
63-
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
64-
ifSeqNo = in.readZLong();
65-
ifPrimaryTerm = in.readVLong();
66-
} else {
67-
ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
68-
ifPrimaryTerm = UNASSIGNED_PRIMARY_TERM;
69-
}
62+
ifSeqNo = in.readZLong();
63+
ifPrimaryTerm = in.readVLong();
7064
}
7165

7266
@Override
@@ -77,10 +71,8 @@ public void writeTo(StreamOutput out) throws IOException {
7771
out.writeBoolean(active);
7872
out.writeEnum(xContentType);
7973
out.writeZLong(version);
80-
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
81-
out.writeZLong(ifSeqNo);
82-
out.writeVLong(ifPrimaryTerm);
83-
}
74+
out.writeZLong(ifSeqNo);
75+
out.writeVLong(ifPrimaryTerm);
8476
}
8577

8678
/**

x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/watcher/PutWatchResponse.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.protocol.xpack.watcher;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionResponse;
109
import org.elasticsearch.common.ParseField;
1110
import org.elasticsearch.common.io.stream.StreamInput;
@@ -110,10 +109,8 @@ public void writeTo(StreamOutput out) throws IOException {
110109
super.writeTo(out);
111110
out.writeString(id);
112111
out.writeVLong(version);
113-
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
114-
out.writeZLong(seqNo);
115-
out.writeVLong(primaryTerm);
116-
}
112+
out.writeZLong(seqNo);
113+
out.writeVLong(primaryTerm);
117114
out.writeBoolean(created);
118115
}
119116

@@ -122,13 +119,8 @@ public void readFrom(StreamInput in) throws IOException {
122119
super.readFrom(in);
123120
id = in.readString();
124121
version = in.readVLong();
125-
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
126-
seqNo = in.readZLong();
127-
primaryTerm = in.readVLong();
128-
} else {
129-
seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
130-
primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM;
131-
}
122+
seqNo = in.readZLong();
123+
primaryTerm = in.readVLong();
132124
created = in.readBoolean();
133125
}
134126

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.watcher.transport.actions.get;
77

8-
import org.elasticsearch.Version;
98
import org.elasticsearch.action.ActionResponse;
109
import org.elasticsearch.common.Strings;
1110
import org.elasticsearch.common.io.stream.StreamInput;
@@ -96,10 +95,8 @@ public void readFrom(StreamInput in) throws IOException {
9695
status = WatchStatus.read(in);
9796
source = XContentSource.readFrom(in);
9897
version = in.readZLong();
99-
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
100-
seqNo = in.readZLong();
101-
primaryTerm = in.readVLong();
102-
}
98+
seqNo = in.readZLong();
99+
primaryTerm = in.readVLong();
103100
} else {
104101
status = null;
105102
source = null;
@@ -118,10 +115,8 @@ public void writeTo(StreamOutput out) throws IOException {
118115
status.writeTo(out);
119116
XContentSource.writeTo(source, out);
120117
out.writeZLong(version);
121-
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
122-
out.writeZLong(seqNo);
123-
out.writeVLong(primaryTerm);
124-
}
118+
out.writeZLong(seqNo);
119+
out.writeVLong(primaryTerm);
125120
}
126121
}
127122

x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/80_put_get_watch_with_passwords.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ setup:
224224
---
225225
"Test putting a watch with a redacted password with old seq no returns an error":
226226
- skip:
227-
version: " - 6.99.99"
228-
reason: seq no powered concurrency was added in 7.0.0
227+
version: " - 6.6.99"
228+
reason: seq no powered concurrency was added in 6.7.0
229229

230230
# version 1
231231
- do:

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/ack/TransportAckWatchAction.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import org.elasticsearch.ElasticsearchStatusException;
99
import org.elasticsearch.ResourceNotFoundException;
10-
import org.elasticsearch.Version;
1110
import org.elasticsearch.action.ActionListener;
1211
import org.elasticsearch.action.get.GetRequest;
1312
import org.elasticsearch.action.get.GetResponse;
@@ -102,12 +101,8 @@ protected void doExecute(AckWatchRequest request, ActionListener<AckWatchRespons
102101

103102
UpdateRequest updateRequest = new UpdateRequest(Watch.INDEX, Watch.DOC_TYPE, request.getWatchId());
104103
// this may reject this action, but prevents concurrent updates from a watch execution
105-
if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_7_0_0)) {
106-
updateRequest.setIfSeqNo(getResponse.getSeqNo());
107-
updateRequest.setIfPrimaryTerm(getResponse.getPrimaryTerm());
108-
} else {
109-
updateRequest.version(getResponse.getVersion());
110-
}
104+
updateRequest.setIfSeqNo(getResponse.getSeqNo());
105+
updateRequest.setIfPrimaryTerm(getResponse.getPrimaryTerm());
111106
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
112107
XContentBuilder builder = jsonBuilder();
113108
builder.startObject()

0 commit comments

Comments
 (0)