Skip to content

Conversation

@bleskes
Copy link
Contributor

@bleskes bleskes commented Jul 3, 2017

This is a companion PR to #25511 . See there for more explanation and background.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a suggestion

request = DocWriteRequest.readDocumentRequest(in);
if (in.readBoolean()) {
primaryResponse = BulkItemResponse.readBulkItem(in);
if (in.getVersion().onOrAfter(Version.V_5_6_0_UNRELEASED)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we should mix onOrAfter and before in the same file, it's confusing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - I wanted to add a 6.0.0 here and keep the wire level logic symmetrical. The 6.0.0 constant is not available on 5.x, which I wanted to discuss / understand why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this via another channel, @bleskes will work on removing this guard and obviating the need for even considering adding a 6.0.0 version constant.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment about assert placement

DocWriteRequest.writeDocumentRequest(out, request);
out.writeOptionalStreamable(primaryResponse);
out.writeBoolean(ignoreOnReplica);
assert ignoreOnReplica ==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird to place this assert here, rather than where ignoreOnReplica is actually set, it also would make debugging more difficult, because instead of a stacktrace letting you know where it was incorrectly set, it only manifests once serialized.

How would you feel about combining setPrimaryResponse and setIgnoreOnReplica so they are entangled and an exception is thrown if an invalid state is configured when the primary response is set? Perhaps something like:

void setPrimaryResponse(BulkItemResponse primaryResponse, boolean ignoreOnReplica) {
    assert ignoreOnReplica ==
        (primaryResponse != null &&
            (primaryResponse.isFailed() || primaryResponse.getResponse().getResult() == DocWriteResponse.Result.NOOP)
        ) :
        "unexpected ignoreOnReplica value. primaryResponse [" + primaryResponse + "], primaryResponse ["
            + (primaryResponse == null ? "null" : XContentHelper.toString(primaryResponse)) + "]";
    this.primaryResponse = primaryResponse;
    this.ignoreOnReplica = ignoreOnReplica;
}

It could also be configured as a regular exception there also, instead of an assert (IllegalArgumentException). It would also have the benefit of not leaving the object in an illegal state when an exception was thrown (nice to be clean)

@bleskes bleskes added v6.0.0 and removed v6.0.0 labels Jul 6, 2017
@bleskes
Copy link
Contributor Author

bleskes commented Jul 6, 2017

@dakrone thanks for your suggestion. Instead of changing the API, I went ahead and removed the ignore on replicas field completely. can you take another look?

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a super minor nit

primaryResponse = BulkItemResponse.readBulkItem(in);
// This is a bwc layer for 6.0 which no longer mutates the requests with these
// Since 5.x still requires it we do it here. Note that these are harmless
// as both operations are idempotent. This is something we rely for and assert on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: "for" -> "on"

@bleskes bleskes merged commit f597c11 into elastic:5.x Jul 8, 2017
@bleskes bleskes deleted the index_req_bwc_5.x branch July 8, 2017 09:54
@bleskes
Copy link
Contributor Author

bleskes commented Jul 8, 2017

Thx @jasontedor @dakrone

bleskes added a commit that referenced this pull request Jul 8, 2017
#25512 & #25511 have been merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants