1919
2020package org .elasticsearch .action .bulk ;
2121
22+ import org .elasticsearch .Version ;
2223import org .elasticsearch .action .DocWriteRequest ;
24+ import org .elasticsearch .action .DocWriteResponse ;
2325import org .elasticsearch .action .IndicesRequest ;
24- import org .elasticsearch .action .delete .DeleteRequest ;
25- import org .elasticsearch .action .index .IndexRequest ;
26- import org .elasticsearch .action .update .UpdateRequest ;
2726import org .elasticsearch .common .io .stream .StreamInput ;
2827import org .elasticsearch .common .io .stream .StreamOutput ;
2928import org .elasticsearch .common .io .stream .Streamable ;
@@ -38,7 +37,6 @@ public class BulkItemRequest implements Streamable {
3837 private int id ;
3938 private DocWriteRequest request ;
4039 private volatile BulkItemResponse primaryResponse ;
41- private volatile boolean ignoreOnReplica ;
4240
4341 BulkItemRequest () {
4442
@@ -71,15 +69,9 @@ void setPrimaryResponse(BulkItemResponse primaryResponse) {
7169 this .primaryResponse = primaryResponse ;
7270 }
7371
74- /**
75- * Marks this request to be ignored and *not* execute on a replica.
76- */
77- void setIgnoreOnReplica () {
78- this .ignoreOnReplica = true ;
79- }
80-
8172 boolean isIgnoreOnReplica () {
82- return ignoreOnReplica ;
73+ return primaryResponse != null &&
74+ (primaryResponse .isFailed () || primaryResponse .getResponse ().getResult () == DocWriteResponse .Result .NOOP );
8375 }
8476
8577 public static BulkItemRequest readBulkItem (StreamInput in ) throws IOException {
@@ -94,15 +86,27 @@ public void readFrom(StreamInput in) throws IOException {
9486 request = DocWriteRequest .readDocumentRequest (in );
9587 if (in .readBoolean ()) {
9688 primaryResponse = BulkItemResponse .readBulkItem (in );
89+ // This is a bwc layer for 6.0 which no longer mutates the requests with these
90+ // Since 5.x still requires it we do it here. Note that these are harmless
91+ // as both operations are idempotent. This is something we rely on and assert on
92+ // in InternalEngine.planIndexingAsNonPrimary()
93+ request .version (primaryResponse .getVersion ());
94+ request .versionType (request .versionType ().versionTypeForReplicationAndRecovery ());
95+ }
96+ if (in .getVersion ().before (Version .V_5_6_0_UNRELEASED )) {
97+ boolean ignoreOnReplica = in .readBoolean ();
98+ assert ignoreOnReplica == isIgnoreOnReplica () :
99+ "ignoreOnReplica mismatch. wire [" + ignoreOnReplica + "], ours [" + isIgnoreOnReplica () + "]" ;
97100 }
98- ignoreOnReplica = in .readBoolean ();
99101 }
100102
101103 @ Override
102104 public void writeTo (StreamOutput out ) throws IOException {
103105 out .writeVInt (id );
104106 DocWriteRequest .writeDocumentRequest (out , request );
105107 out .writeOptionalStreamable (primaryResponse );
106- out .writeBoolean (ignoreOnReplica );
108+ if (out .getVersion ().before (Version .V_5_6_0_UNRELEASED )) {
109+ out .writeBoolean (isIgnoreOnReplica ());
110+ }
107111 }
108112}
0 commit comments