Skip to content

Commit

Permalink
Adapt minimum versions for seq# powered operations in Watch related r…
Browse files Browse the repository at this point in the history
…equests and UpdateRequest (#38231)

After backporting #37977, #37857 and #37872
  • Loading branch information
bleskes authored and jasontedor committed Feb 2, 2019
1 parent 783c9ed commit f6e06a2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 54 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ task verifyVersions {
* the enabled state of every bwc task. It should be set back to true
* after the backport of the backcompat code is complete.
*/
final boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/37951" /* place a PR link here when committing bwc changes */
final boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Update with if_seq_no":

- skip:
version: " - 6.99.99"
reason: if_seq_no was added in 7.0
version: " - 6.6.99"
reason: if_seq_no was added in 6.7.0

- do:
catch: missing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,8 @@ public void readFrom(StreamInput in) throws IOException {
docAsUpsert = in.readBoolean();
version = in.readLong();
versionType = VersionType.fromValue(in.readByte());
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
ifSeqNo = in.readZLong();
ifPrimaryTerm = in.readVLong();
}
ifSeqNo = in.readZLong();
ifPrimaryTerm = in.readVLong();
detectNoop = in.readBoolean();
scriptedUpsert = in.readBoolean();
}
Expand Down Expand Up @@ -934,10 +932,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(docAsUpsert);
out.writeLong(version);
out.writeByte(versionType.getValue());
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeZLong(ifSeqNo);
out.writeVLong(ifPrimaryTerm);
}
out.writeZLong(ifSeqNo);
out.writeVLong(ifPrimaryTerm);
out.writeBoolean(detectNoop);
out.writeBoolean(scriptedUpsert);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.protocol.xpack.watcher;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -60,13 +59,8 @@ public void readFrom(StreamInput in) throws IOException {
active = in.readBoolean();
xContentType = in.readEnum(XContentType.class);
version = in.readZLong();
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
ifSeqNo = in.readZLong();
ifPrimaryTerm = in.readVLong();
} else {
ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
ifPrimaryTerm = UNASSIGNED_PRIMARY_TERM;
}
ifSeqNo = in.readZLong();
ifPrimaryTerm = in.readVLong();
}

@Override
Expand All @@ -77,10 +71,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(active);
out.writeEnum(xContentType);
out.writeZLong(version);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeZLong(ifSeqNo);
out.writeVLong(ifPrimaryTerm);
}
out.writeZLong(ifSeqNo);
out.writeVLong(ifPrimaryTerm);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.protocol.xpack.watcher;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -110,10 +109,8 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeVLong(version);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeZLong(seqNo);
out.writeVLong(primaryTerm);
}
out.writeZLong(seqNo);
out.writeVLong(primaryTerm);
out.writeBoolean(created);
}

Expand All @@ -122,13 +119,8 @@ public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
version = in.readVLong();
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
seqNo = in.readZLong();
primaryTerm = in.readVLong();
} else {
seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM;
}
seqNo = in.readZLong();
primaryTerm = in.readVLong();
created = in.readBoolean();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.watcher.transport.actions.get;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -96,10 +95,8 @@ public void readFrom(StreamInput in) throws IOException {
status = WatchStatus.read(in);
source = XContentSource.readFrom(in);
version = in.readZLong();
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
seqNo = in.readZLong();
primaryTerm = in.readVLong();
}
seqNo = in.readZLong();
primaryTerm = in.readVLong();
} else {
status = null;
source = null;
Expand All @@ -118,10 +115,8 @@ public void writeTo(StreamOutput out) throws IOException {
status.writeTo(out);
XContentSource.writeTo(source, out);
out.writeZLong(version);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeZLong(seqNo);
out.writeVLong(primaryTerm);
}
out.writeZLong(seqNo);
out.writeVLong(primaryTerm);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ setup:
---
"Test putting a watch with a redacted password with old seq no returns an error":
- skip:
version: " - 6.99.99"
reason: seq no powered concurrency was added in 7.0.0
version: " - 6.6.99"
reason: seq no powered concurrency was added in 6.7.0

# version 1
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
Expand Down Expand Up @@ -102,12 +101,8 @@ protected void doExecute(AckWatchRequest request, ActionListener<AckWatchRespons

UpdateRequest updateRequest = new UpdateRequest(Watch.INDEX, Watch.DOC_TYPE, request.getWatchId());
// this may reject this action, but prevents concurrent updates from a watch execution
if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_7_0_0)) {
updateRequest.setIfSeqNo(getResponse.getSeqNo());
updateRequest.setIfPrimaryTerm(getResponse.getPrimaryTerm());
} else {
updateRequest.version(getResponse.getVersion());
}
updateRequest.setIfSeqNo(getResponse.getSeqNo());
updateRequest.setIfPrimaryTerm(getResponse.getPrimaryTerm());
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
XContentBuilder builder = jsonBuilder();
builder.startObject()
Expand Down

0 comments on commit f6e06a2

Please sign in to comment.