From 0b5735298d6a4dea33b9747921119ec740b36a3e Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 17 Dec 2018 16:19:27 +0100 Subject: [PATCH 1/6] rest layers --- .../resources/rest-api-spec/api/delete.json | 8 +++ .../resources/rest-api-spec/api/index.json | 8 +++ .../rest-api-spec/test/index/30_cas.yml | 50 +++++++++++++++++++ .../action/document/RestDeleteAction.java | 3 ++ .../rest/action/document/RestIndexAction.java | 3 ++ 5 files changed, 72 insertions(+) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json index bbe30d3a8484c..b731c3fe6d10c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json @@ -43,6 +43,14 @@ "type" : "time", "description" : "Explicit operation timeout" }, + "if_seq_no_match" : { + "type" : "number", + "description" : "only perform the delete operation if the last operation to have changed the document has the specified sequence number" + }, + "if_primary_term_match" : { + "type" : "number", + "description" : "only perform the delete operation if the last operation to have changed the document has the specified primary term" + }, "version" : { "type" : "number", "description" : "Explicit version number for concurrency control" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json index 574206a0dc3ed..f0c58ae6ade45 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json @@ -57,6 +57,14 @@ "options" : ["internal", "external", "external_gte", "force"], "description" : "Specific version type" }, + "if_seq_no_match" : { + "type" : "number", + "description" : "only perform the index operation if the last operation to have changed the document has the specified sequence number" + }, + "if_primary_term_match" : { + "type" : "number", + "description" : "only perform the index operation if the last operation to have changed the document has the specified primary term" + }, "pipeline" : { "type" : "string", "description" : "The pipeline id to preprocess incoming documents with" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml new file mode 100644 index 0000000000000..b8c60e5a7cf8b --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml @@ -0,0 +1,50 @@ +--- +"Compare And Swap Sequence Numbers": + + - skip: + version: " - 6.99.99" + reason: cas ops are introduced in 7.0.0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + - match: { _version: 1} + - set: { _seq_no: seqno } + - set: { _primary_term: primary_term } + + - do: + get: + index: test_1 + id: 1 + - match: { _seq_no: $seqno } + - match: { _primary_term: $primary_term } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + if_seq_no_match: 10000 + if_primary_term_match: $primary_term + body: { foo: bar2 } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + if_seq_no_match: $seqno + if_primary_term_match: 1000 + body: { foo: bar2 } + + - do: + index: + index: test_1 + id: 1 + if_seq_no_match: $seqno + if_primary_term_match: $primary_term + body: { foo: bar2 } + + - match: { _version: 2 } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index 87cc7a0fb41a4..aea1362590a69 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -66,6 +67,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC deleteRequest.setRefreshPolicy(request.param("refresh")); deleteRequest.version(RestActions.parseVersion(request)); deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType())); + deleteRequest.setIfMatch( + request.paramAsLong("if_seq_no_match", SequenceNumbers.UNASSIGNED_SEQ_NO), request.paramAsLong("if_primary_term_match", 0)); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 619fd811e6a7c..2c1e7d56db4e8 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -93,6 +94,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC indexRequest.setRefreshPolicy(request.param("refresh")); indexRequest.version(RestActions.parseVersion(request)); indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType())); + indexRequest.ifMatch( + request.paramAsLong("if_seq_no_match", SequenceNumbers.UNASSIGNED_SEQ_NO), request.paramAsLong("if_primary_term_match", 0)); String sOpType = request.param("op_type"); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { From aaf9da1c9a8ae3e476d821fba6cd27509660548a Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 17 Dec 2018 16:37:09 +0100 Subject: [PATCH 2/6] /have/has --- .../src/main/resources/rest-api-spec/api/delete.json | 4 ++-- rest-api-spec/src/main/resources/rest-api-spec/api/index.json | 4 ++-- .../main/java/org/elasticsearch/action/get/GetResponse.java | 2 +- .../src/main/java/org/elasticsearch/index/get/GetResult.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json index b731c3fe6d10c..2e75465bf601e 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json @@ -45,11 +45,11 @@ }, "if_seq_no_match" : { "type" : "number", - "description" : "only perform the delete operation if the last operation to have changed the document has the specified sequence number" + "description" : "only perform the delete operation if the last operation that has changed the document has the specified sequence number" }, "if_primary_term_match" : { "type" : "number", - "description" : "only perform the delete operation if the last operation to have changed the document has the specified primary term" + "description" : "only perform the delete operation if the last operation that has changed the document has the specified primary term" }, "version" : { "type" : "number", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json index f0c58ae6ade45..155707bbdcf14 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json @@ -59,11 +59,11 @@ }, "if_seq_no_match" : { "type" : "number", - "description" : "only perform the index operation if the last operation to have changed the document has the specified sequence number" + "description" : "only perform the index operation if the last operation that has changed the document has the specified sequence number" }, "if_primary_term_match" : { "type" : "number", - "description" : "only perform the index operation if the last operation to have changed the document has the specified primary term" + "description" : "only perform the index operation if the last operation that has changed the document has the specified primary term" }, "pipeline" : { "type" : "string", diff --git a/server/src/main/java/org/elasticsearch/action/get/GetResponse.java b/server/src/main/java/org/elasticsearch/action/get/GetResponse.java index fbcb47b5fad36..b9383785678b7 100644 --- a/server/src/main/java/org/elasticsearch/action/get/GetResponse.java +++ b/server/src/main/java/org/elasticsearch/action/get/GetResponse.java @@ -91,7 +91,7 @@ public long getVersion() { } /** - * The sequence number assigned to the last operation to have changed this document, if found. + * The sequence number assigned to the last operation that has changed this document, if found. */ public long getSeqNo() { return getResult.getSeqNo(); diff --git a/server/src/main/java/org/elasticsearch/index/get/GetResult.java b/server/src/main/java/org/elasticsearch/index/get/GetResult.java index b98d766dd4e3f..2b3b1b8f4f231 100644 --- a/server/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/server/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -131,7 +131,7 @@ public long getVersion() { } /** - * The sequence number assigned to the last operation to have changed this document, if found. + * The sequence number assigned to the last operation that has changed this document, if found. */ public long getSeqNo() { return seqNo; From e988265c5d3bb28b3ceff6ce18f9d4234020131a Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 17 Dec 2018 16:52:12 +0100 Subject: [PATCH 3/6] use current requests values --- .../elasticsearch/rest/action/document/RestDeleteAction.java | 4 +++- .../elasticsearch/rest/action/document/RestIndexAction.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index aea1362590a69..2139edee81080 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -68,7 +68,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC deleteRequest.version(RestActions.parseVersion(request)); deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType())); deleteRequest.setIfMatch( - request.paramAsLong("if_seq_no_match", SequenceNumbers.UNASSIGNED_SEQ_NO), request.paramAsLong("if_primary_term_match", 0)); + request.paramAsLong("if_seq_no_match", deleteRequest.ifSeqNoMatch()), + request.paramAsLong("if_primary_term_match", deleteRequest.ifPrimaryTermMatch()) + ); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 2c1e7d56db4e8..942a6329671d9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -95,7 +95,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC indexRequest.version(RestActions.parseVersion(request)); indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType())); indexRequest.ifMatch( - request.paramAsLong("if_seq_no_match", SequenceNumbers.UNASSIGNED_SEQ_NO), request.paramAsLong("if_primary_term_match", 0)); + request.paramAsLong("if_seq_no_match", indexRequest.ifSeqNoMatch()), + request.paramAsLong("if_primary_term_match", indexRequest.ifPrimaryTermMatch()) + ); String sOpType = request.param("op_type"); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { From b9283e1ec35c18565c12a09f8f8a7ae30a67db8b Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 17 Dec 2018 18:15:15 +0100 Subject: [PATCH 4/6] linting --- .../org/elasticsearch/rest/action/document/RestDeleteAction.java | 1 - .../org/elasticsearch/rest/action/document/RestIndexAction.java | 1 - 2 files changed, 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index 2139edee81080..1891b29d175c9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 942a6329671d9..2a072560272bf 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; From 50c52efdaca9e70e2712c43cca771eeb8ec138b5 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Tue, 18 Dec 2018 09:08:31 +0100 Subject: [PATCH 5/6] renames --- .../resources/rest-api-spec/api/delete.json | 4 +- .../resources/rest-api-spec/api/index.json | 4 +- .../rest-api-spec/test/index/30_cas.yml | 12 ++-- .../action/bulk/BulkRequest.java | 25 ++++---- .../action/bulk/TransportShardBulkAction.java | 4 +- .../action/delete/DeleteRequest.java | 55 +++++++++-------- .../action/delete/DeleteRequestBuilder.java | 15 ++++- .../action/index/IndexRequest.java | 60 ++++++++++--------- .../action/index/IndexRequestBuilder.java | 15 ++++- .../elasticsearch/index/engine/Engine.java | 52 ++++++++-------- .../index/engine/InternalEngine.java | 24 ++++---- .../elasticsearch/index/shard/IndexShard.java | 26 ++++---- .../action/document/RestDeleteAction.java | 6 +- .../rest/action/document/RestIndexAction.java | 6 +- .../versioning/SimpleVersioningIT.java | 22 +++---- .../index/engine/FollowingEngineTests.java | 4 +- 16 files changed, 180 insertions(+), 154 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json index 2e75465bf601e..4b698b371a16d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/delete.json @@ -43,11 +43,11 @@ "type" : "time", "description" : "Explicit operation timeout" }, - "if_seq_no_match" : { + "if_seq_no" : { "type" : "number", "description" : "only perform the delete operation if the last operation that has changed the document has the specified sequence number" }, - "if_primary_term_match" : { + "if_primary_term" : { "type" : "number", "description" : "only perform the delete operation if the last operation that has changed the document has the specified primary term" }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json index 155707bbdcf14..67df565867975 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json @@ -57,11 +57,11 @@ "options" : ["internal", "external", "external_gte", "force"], "description" : "Specific version type" }, - "if_seq_no_match" : { + "if_seq_no" : { "type" : "number", "description" : "only perform the index operation if the last operation that has changed the document has the specified sequence number" }, - "if_primary_term_match" : { + "if_primary_term" : { "type" : "number", "description" : "only perform the index operation if the last operation that has changed the document has the specified primary term" }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml index b8c60e5a7cf8b..a43ec1437a50b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/30_cas.yml @@ -26,8 +26,8 @@ index: index: test_1 id: 1 - if_seq_no_match: 10000 - if_primary_term_match: $primary_term + if_seq_no: 10000 + if_primary_term: $primary_term body: { foo: bar2 } - do: @@ -35,16 +35,16 @@ index: index: test_1 id: 1 - if_seq_no_match: $seqno - if_primary_term_match: 1000 + if_seq_no: $seqno + if_primary_term: 1000 body: { foo: bar2 } - do: index: index: test_1 id: 1 - if_seq_no_match: $seqno - if_primary_term_match: $primary_term + if_seq_no: $seqno + if_primary_term: $primary_term body: { foo: bar2 } - match: { _version: 2 } diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 1eb60263843ea..fd11b5866664c 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -78,8 +78,8 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques private static final ParseField RETRY_ON_CONFLICT = new ParseField("retry_on_conflict"); private static final ParseField PIPELINE = new ParseField("pipeline"); private static final ParseField SOURCE = new ParseField("_source"); - private static final ParseField IF_SEQ_NO_MATCH = new ParseField("if_seq_no_match"); - private static final ParseField IF_PRIMARY_TERM_MATCH = new ParseField("if_primary_term_match"); + private static final ParseField IF_SEQ_NO = new ParseField("if_seq_no"); + private static final ParseField IF_PRIMARY_TERM = new ParseField("if_primary_term"); /** * Requests that are part of this request. It is only possible to add things that are both {@link ActionRequest}s and @@ -350,8 +350,8 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null String opType = null; long version = Versions.MATCH_ANY; VersionType versionType = VersionType.INTERNAL; - long ifSeqNoMatch = SequenceNumbers.UNASSIGNED_SEQ_NO; - long ifPrimaryTermMatch = 0; + long ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO; + long ifPrimaryTerm = 0; int retryOnConflict = 0; String pipeline = valueOrDefault(defaultPipeline, globalPipeline); @@ -382,10 +382,10 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null version = parser.longValue(); } else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) { versionType = VersionType.fromString(parser.text()); - } else if (IF_SEQ_NO_MATCH.match(currentFieldName, parser.getDeprecationHandler())) { - ifSeqNoMatch = parser.longValue(); - } else if (IF_PRIMARY_TERM_MATCH.match(currentFieldName, parser.getDeprecationHandler())) { - ifPrimaryTermMatch = parser.longValue(); + } else if (IF_SEQ_NO.match(currentFieldName, parser.getDeprecationHandler())) { + ifSeqNo = parser.longValue(); + } else if (IF_PRIMARY_TERM.match(currentFieldName, parser.getDeprecationHandler())) { + ifPrimaryTerm = parser.longValue(); } else if (RETRY_ON_CONFLICT.match(currentFieldName, parser.getDeprecationHandler())) { retryOnConflict = parser.intValue(); } else if (PIPELINE.match(currentFieldName, parser.getDeprecationHandler())) { @@ -414,7 +414,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null if ("delete".equals(action)) { add(new DeleteRequest(index, type, id).routing(routing) - .version(version).versionType(versionType).setIfMatch(ifSeqNoMatch, ifPrimaryTermMatch), payload); + .version(version).versionType(versionType).setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm), payload); } else { nextMarker = findNextMarker(marker, from, data, length); if (nextMarker == -1) { @@ -427,16 +427,17 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null if ("index".equals(action)) { if (opType == null) { internalAdd(new IndexRequest(index, type, id).routing(routing).version(version).versionType(versionType) - .setPipeline(pipeline).ifMatch(ifSeqNoMatch, ifPrimaryTermMatch) + .setPipeline(pipeline).setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm) .source(sliceTrimmingCarriageReturn(data, from, nextMarker,xContentType), xContentType), payload); } else { internalAdd(new IndexRequest(index, type, id).routing(routing).version(version).versionType(versionType) - .create("create".equals(opType)).setPipeline(pipeline).ifMatch(ifSeqNoMatch, ifPrimaryTermMatch) + .create("create".equals(opType)).setPipeline(pipeline) + .setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm) .source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType), payload); } } else if ("create".equals(action)) { internalAdd(new IndexRequest(index, type, id).routing(routing).version(version).versionType(versionType) - .create(true).setPipeline(pipeline).ifMatch(ifSeqNoMatch, ifPrimaryTermMatch) + .create(true).setPipeline(pipeline).setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm) .source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType), payload); } else if ("update".equals(action)) { UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).retryOnConflict(retryOnConflict) diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index b2d6fb518f88a..e04da71749f09 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -462,7 +462,7 @@ private static void executeIndexRequestOnPrimary(BulkPrimaryExecutionContext con executeOnPrimaryWhileHandlingMappingUpdates(context, () -> primary.applyIndexOperationOnPrimary(request.version(), request.versionType(), sourceToParse, - request.ifSeqNoMatch(), request.ifPrimaryTermMatch(), request.getAutoGeneratedTimestamp(), request.isRetry()), + request.ifSeqNo(), request.ifPrimaryTerm(), request.getAutoGeneratedTimestamp(), request.isRetry()), e -> primary.getFailedIndexResult(e, request.version()), context::markOperationAsExecuted, mapping -> mappingUpdater.updateMappings(mapping, primary.shardId(), request.type())); @@ -474,7 +474,7 @@ private static void executeDeleteRequestOnPrimary(BulkPrimaryExecutionContext co final IndexShard primary = context.getPrimary(); executeOnPrimaryWhileHandlingMappingUpdates(context, () -> primary.applyDeleteOperationOnPrimary(request.version(), request.type(), request.id(), request.versionType(), - request.ifSeqNoMatch(), request.ifPrimaryTermMatch()), + request.ifSeqNo(), request.ifPrimaryTerm()), e -> primary.getFailedDeleteResult(e, request.version()), context::markOperationAsExecuted, mapping -> mappingUpdater.updateMappings(mapping, primary.shardId(), request.type())); diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java index c9f2df5633351..f14065f04a880 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java @@ -58,8 +58,8 @@ public class DeleteRequest extends ReplicatedWriteRequest private String routing; private long version = Versions.MATCH_ANY; private VersionType versionType = VersionType.INTERNAL; - private long ifSeqNoMatch = SequenceNumbers.UNASSIGNED_SEQ_NO; - private long ifPrimaryTermMatch = 0; + private long ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO; + private long ifPrimaryTerm = 0; public DeleteRequest() { } @@ -116,11 +116,20 @@ public ActionRequestValidationException validate() { validationException = addValidationError("version type [force] may no longer be used", validationException); } - if (ifSeqNoMatch != SequenceNumbers.UNASSIGNED_SEQ_NO && ( + if (ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO && ( versionType != VersionType.INTERNAL || version != Versions.MATCH_ANY )) { validationException = addValidationError("compare and write operations can not use versioning", validationException); } + + if (ifPrimaryTerm == 0 && ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { + validationException = addValidationError("ifSeqNo is set, but primary term is [0]", validationException); + } + if (ifPrimaryTerm != 0 && ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) { + validationException = + addValidationError("ifSeqNo is unassigned, but primary term is [" + ifPrimaryTerm + "]", validationException); + } + return validationException; } @@ -203,29 +212,27 @@ public DeleteRequest versionType(VersionType versionType) { return this; } - public long ifSeqNoMatch() { - return ifSeqNoMatch; + public long ifSeqNo() { + return ifSeqNo; } - public long ifPrimaryTermMatch() { - return ifPrimaryTermMatch; + public long ifPrimaryTerm() { + return ifPrimaryTerm; } - public DeleteRequest setIfMatch(long seqNo, long term) { - if (term == 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { - throw new IllegalArgumentException("seqNo is set, but primary term is [0]"); - } - if (term != 0 && seqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) { - throw new IllegalArgumentException("seqNo is unassigned, but primary term is [" + term + "]"); - } + public DeleteRequest setIfSeqNo(long seqNo) { if (seqNo < 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { throw new IllegalArgumentException("sequence numbers must be non negative. got [" + seqNo + "]."); } + ifSeqNo = seqNo; + return this; + } + + public DeleteRequest setIfPrimaryTerm(long term) { if (term < 0) { throw new IllegalArgumentException("primary term must be non negative. got [" + term + "]"); } - ifSeqNoMatch = seqNo; - ifPrimaryTermMatch = term; + ifPrimaryTerm = term; return this; } @@ -251,11 +258,11 @@ public void readFrom(StreamInput in) throws IOException { version = in.readLong(); versionType = VersionType.fromValue(in.readByte()); if (in.getVersion().onOrAfter(Version.V_7_0_0)) { - ifSeqNoMatch = in.readZLong(); - ifPrimaryTermMatch = in.readVLong(); + ifSeqNo = in.readZLong(); + ifPrimaryTerm = in.readVLong(); } else { - ifSeqNoMatch = SequenceNumbers.UNASSIGNED_SEQ_NO; - ifPrimaryTermMatch = 0; + ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO; + ifPrimaryTerm = 0; } } @@ -271,10 +278,10 @@ public void writeTo(StreamOutput out) throws IOException { out.writeLong(version); out.writeByte(versionType.getValue()); if (out.getVersion().onOrAfter(Version.V_7_0_0)) { - out.writeZLong(ifSeqNoMatch); - out.writeVLong(ifPrimaryTermMatch); - } else if (ifSeqNoMatch != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTermMatch != 0) { - assert false : "setIfMatch [" + ifSeqNoMatch + "], currentDocTem [" + ifPrimaryTermMatch + "]"; + out.writeZLong(ifSeqNo); + out.writeVLong(ifPrimaryTerm); + } else if (ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTerm != 0) { + assert false : "setIfMatch [" + ifSeqNo + "], currentDocTem [" + ifPrimaryTerm + "]"; throw new IllegalStateException( "sequence number based compare and write is not supported until all nodes are on version 7.0 or higher. " + "Stream version [" + out.getVersion() + "]"); diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java index f0df2d3558bca..fede9f1da39ca 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java @@ -83,10 +83,19 @@ public DeleteRequestBuilder setVersionType(VersionType versionType) { /** * only performs this delete request if the document was last modification was assigned the given - * sequence number and primary term + * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} */ - public DeleteRequestBuilder setIfMatch(long seqNo, long term) { - request.setIfMatch(seqNo, term); + public DeleteRequestBuilder setIfSeqNo(long seqNo) { + request.setIfSeqNo(seqNo); + return this; + } + + /** + * only performs this delete request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} (long)} + */ + public DeleteRequestBuilder setIfPrimaryTerm(long term) { + request.setIfPrimaryTerm(term); return this; } diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index fd80139d5ce85..e0a6a54c3918b 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -105,8 +105,8 @@ public class IndexRequest extends ReplicatedWriteRequest implement private long autoGeneratedTimestamp = UNSET_AUTO_GENERATED_TIMESTAMP; private boolean isRetry = false; - private long ifSeqNoMatch = SequenceNumbers.UNASSIGNED_SEQ_NO; - private long ifPrimaryTermMatch = 0; + private long ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO; + private long ifPrimaryTerm = 0; public IndexRequest() { @@ -168,7 +168,7 @@ public ActionRequestValidationException validate() { return validationException; } - if (ifSeqNoMatch != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTermMatch != 0) { + if (ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTerm != 0) { validationException = addValidationError("create operations do not support compare and set. use index instead", validationException); return validationException; @@ -201,11 +201,18 @@ public ActionRequestValidationException validate() { validationException = addValidationError("pipeline cannot be an empty string", validationException); } - if (ifSeqNoMatch != SequenceNumbers.UNASSIGNED_SEQ_NO && ( + if (ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO && ( versionType != VersionType.INTERNAL || version != Versions.MATCH_ANY )) { validationException = addValidationError("compare and write operations can not use versioning", validationException); } + if (ifPrimaryTerm == 0 && ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { + validationException = addValidationError("ifSeqNo is set, but primary term is [0]", validationException); + } + if (ifPrimaryTerm != 0 && ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) { + validationException = + addValidationError("ifSeqNo is unassigned, but primary term is [" + ifPrimaryTerm + "]", validationException); + } return validationException; } @@ -486,31 +493,28 @@ public IndexRequest versionType(VersionType versionType) { return this; } - public IndexRequest ifMatch(long seqNo, long term) { - if (term == 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { - throw new IllegalArgumentException("seqNo is set, but primary term is [0]"); - } - - if (term != 0 && seqNo == SequenceNumbers.UNASSIGNED_SEQ_NO) { - throw new IllegalArgumentException("seqNo is unassigned, but primary term is [" + term + "]"); - } + public IndexRequest setIfSeqNo(long seqNo) { if (seqNo < 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { throw new IllegalArgumentException("sequence numbers must be non negative. got [" + seqNo + "]."); } + ifSeqNo = seqNo; + return this; + } + + public IndexRequest setIfPrimaryTerm(long term) { if (term < 0) { throw new IllegalArgumentException("primary term must be non negative. got [" + term + "]"); } - ifSeqNoMatch = seqNo; - ifPrimaryTermMatch = term; + ifPrimaryTerm = term; return this; } - public long ifSeqNoMatch() { - return ifSeqNoMatch; + public long ifSeqNo() { + return ifSeqNo; } - public long ifPrimaryTermMatch() { - return ifPrimaryTermMatch; + public long ifPrimaryTerm() { + return ifPrimaryTerm; } @Override @@ -534,8 +538,8 @@ public void process(Version indexCreatedVersion, @Nullable MappingMetaData mappi // generate id if not already provided if (id == null) { assert autoGeneratedTimestamp == -1 : "timestamp has already been generated!"; - assert ifSeqNoMatch == SequenceNumbers.UNASSIGNED_SEQ_NO; - assert ifPrimaryTermMatch == 0; + assert ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO; + assert ifPrimaryTerm == 0; autoGeneratedTimestamp = Math.max(0, System.currentTimeMillis()); // extra paranoia String uid; if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_beta1)) { @@ -578,11 +582,11 @@ public void readFrom(StreamInput in) throws IOException { contentType = null; } if (in.getVersion().onOrAfter(Version.V_7_0_0)) { - ifSeqNoMatch = in.readZLong(); - ifPrimaryTermMatch = in.readVLong(); + ifSeqNo = in.readZLong(); + ifPrimaryTerm = in.readVLong(); } else { - ifSeqNoMatch = SequenceNumbers.UNASSIGNED_SEQ_NO; - ifPrimaryTermMatch = 0; + ifSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO; + ifPrimaryTerm = 0; } } @@ -616,10 +620,10 @@ public void writeTo(StreamOutput out) throws IOException { out.writeBoolean(false); } if (out.getVersion().onOrAfter(Version.V_7_0_0)) { - out.writeZLong(ifSeqNoMatch); - out.writeVLong(ifPrimaryTermMatch); - } else if (ifSeqNoMatch != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTermMatch != 0) { - assert false : "setIfMatch [" + ifSeqNoMatch + "], currentDocTem [" + ifPrimaryTermMatch + "]"; + out.writeZLong(ifSeqNo); + out.writeVLong(ifPrimaryTerm); + } else if (ifSeqNo != SequenceNumbers.UNASSIGNED_SEQ_NO || ifPrimaryTerm != 0) { + assert false : "setIfMatch [" + ifSeqNo + "], currentDocTem [" + ifPrimaryTerm + "]"; throw new IllegalStateException( "sequence number based compare and write is not supported until all nodes are on version 7.0 or higher. " + "Stream version [" + out.getVersion() + "]"); diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java index 8ca32d40e8c8c..02381f8528f8b 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java @@ -201,10 +201,19 @@ public IndexRequestBuilder setVersionType(VersionType versionType) { /** * only performs this indexing request if the document was last modification was assigned the given - * sequence number and primary term + * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} */ - public IndexRequestBuilder setIfMatch(long seqNo, long term) { - request.ifMatch(seqNo, term); + public IndexRequestBuilder setIfSeqNo(long seqNo) { + request.setIfSeqNo(seqNo); + return this; + } + + /** + * only performs this indexing request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} (long)} + */ + public IndexRequestBuilder setIfPrimaryTerm(long term) { + request.setIfPrimaryTerm(term); return this; } diff --git a/server/src/main/java/org/elasticsearch/index/engine/Engine.java b/server/src/main/java/org/elasticsearch/index/engine/Engine.java index d0d10986fd8ed..f0d0157476649 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -1345,23 +1345,23 @@ public static class Index extends Operation { private final ParsedDocument doc; private final long autoGeneratedIdTimestamp; private final boolean isRetry; - private final long ifSeqNoMatch; - private final long ifPrimaryTermMatch; + private final long ifSeqNo; + private final long ifPrimaryTerm; public Index(Term uid, ParsedDocument doc, long seqNo, long primaryTerm, long version, VersionType versionType, Origin origin, - long startTime, long autoGeneratedIdTimestamp, boolean isRetry, long ifSeqNoMatch, long ifPrimaryTermMatch) { + long startTime, long autoGeneratedIdTimestamp, boolean isRetry, long ifSeqNo, long ifPrimaryTerm) { super(uid, seqNo, primaryTerm, version, versionType, origin, startTime); assert (origin == Origin.PRIMARY) == (versionType != null) : "invalid version_type=" + versionType + " for origin=" + origin; - assert ifPrimaryTermMatch >= 0 : "ifPrimaryTermMatch [" + ifPrimaryTermMatch + "] must be non negative"; - assert ifSeqNoMatch == SequenceNumbers.UNASSIGNED_SEQ_NO || ifSeqNoMatch >=0 : - "ifSeqNoMatch [" + ifSeqNoMatch + "] must be non negative or unset"; - assert (origin == Origin.PRIMARY) || (ifSeqNoMatch == SequenceNumbers.UNASSIGNED_SEQ_NO && ifPrimaryTermMatch == 0) : + assert ifPrimaryTerm >= 0 : "ifPrimaryTerm [" + ifPrimaryTerm + "] must be non negative"; + assert ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || ifSeqNo >=0 : + "ifSeqNo [" + ifSeqNo + "] must be non negative or unset"; + assert (origin == Origin.PRIMARY) || (ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO && ifPrimaryTerm == 0) : "cas operations are only allowed if origin is primary. get [" + origin + "]"; this.doc = doc; this.isRetry = isRetry; this.autoGeneratedIdTimestamp = autoGeneratedIdTimestamp; - this.ifSeqNoMatch = ifSeqNoMatch; - this.ifPrimaryTermMatch = ifPrimaryTermMatch; + this.ifSeqNo = ifSeqNo; + this.ifPrimaryTerm = ifPrimaryTerm; } public Index(Term uid, long primaryTerm, ParsedDocument doc) { @@ -1426,12 +1426,12 @@ public boolean isRetry() { return isRetry; } - public long getIfSeqNoMatch() { - return ifSeqNoMatch; + public long getIfSeqNo() { + return ifSeqNo; } - public long getIfPrimaryTermMatch() { - return ifPrimaryTermMatch; + public long getIfPrimaryTerm() { + return ifPrimaryTerm; } } @@ -1439,22 +1439,22 @@ public static class Delete extends Operation { private final String type; private final String id; - private final long ifSeqNoMatch; - private final long ifPrimaryTermMatch; + private final long ifSeqNo; + private final long ifPrimaryTerm; public Delete(String type, String id, Term uid, long seqNo, long primaryTerm, long version, VersionType versionType, - Origin origin, long startTime, long ifSeqNoMatch, long ifPrimaryTermMatch) { + Origin origin, long startTime, long ifSeqNo, long ifPrimaryTerm) { super(uid, seqNo, primaryTerm, version, versionType, origin, startTime); assert (origin == Origin.PRIMARY) == (versionType != null) : "invalid version_type=" + versionType + " for origin=" + origin; - assert ifPrimaryTermMatch >= 0 : "ifPrimaryTermMatch [" + ifPrimaryTermMatch + "] must be non negative"; - assert ifSeqNoMatch == SequenceNumbers.UNASSIGNED_SEQ_NO || ifSeqNoMatch >=0 : - "ifSeqNoMatch [" + ifSeqNoMatch + "] must be non negative or unset"; - assert (origin == Origin.PRIMARY) || (ifSeqNoMatch == SequenceNumbers.UNASSIGNED_SEQ_NO && ifPrimaryTermMatch == 0) : + assert ifPrimaryTerm >= 0 : "ifPrimaryTerm [" + ifPrimaryTerm + "] must be non negative"; + assert ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || ifSeqNo >=0 : + "ifSeqNo [" + ifSeqNo + "] must be non negative or unset"; + assert (origin == Origin.PRIMARY) || (ifSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO && ifPrimaryTerm == 0) : "cas operations are only allowed if origin is primary. get [" + origin + "]"; this.type = Objects.requireNonNull(type); this.id = Objects.requireNonNull(id); - this.ifSeqNoMatch = ifSeqNoMatch; - this.ifPrimaryTermMatch = ifPrimaryTermMatch; + this.ifSeqNo = ifSeqNo; + this.ifPrimaryTerm = ifPrimaryTerm; } public Delete(String type, String id, Term uid, long primaryTerm) { @@ -1487,12 +1487,12 @@ public int estimatedSizeInBytes() { return (uid().field().length() + uid().text().length()) * 2 + 20; } - public long getIfSeqNoMatch() { - return ifSeqNoMatch; + public long getIfSeqNo() { + return ifSeqNo; } - public long getIfPrimaryTermMatch() { - return ifPrimaryTermMatch; + public long getIfPrimaryTerm() { + return ifPrimaryTerm; } } diff --git a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index b2c446b3a8658..a295fbf3336b1 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -965,7 +965,7 @@ protected final IndexingStrategy planIndexingAsPrimary(Index index) throws IOExc versionMap.enforceSafeAccess(); // resolves incoming version final VersionValue versionValue = - resolveDocVersion(index, index.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO); + resolveDocVersion(index, index.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO); final long currentVersion; final boolean currentNotFoundOrDeleted; if (versionValue == null) { @@ -975,15 +975,15 @@ protected final IndexingStrategy planIndexingAsPrimary(Index index) throws IOExc currentVersion = versionValue.version; currentNotFoundOrDeleted = versionValue.isDelete(); } - if (index.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO && versionValue == null) { + if (index.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO && versionValue == null) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, index.type(), index.id(), - index.getIfSeqNoMatch(), index.getIfPrimaryTermMatch(), SequenceNumbers.UNASSIGNED_SEQ_NO, 0); + index.getIfSeqNo(), index.getIfPrimaryTerm(), SequenceNumbers.UNASSIGNED_SEQ_NO, 0); plan = IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion, getPrimaryTerm()); - } else if (index.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO && ( - versionValue.seqNo != index.getIfSeqNoMatch() || versionValue.term != index.getIfPrimaryTermMatch() + } else if (index.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO && ( + versionValue.seqNo != index.getIfSeqNo() || versionValue.term != index.getIfPrimaryTerm() )) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, index.type(), index.id(), - index.getIfSeqNoMatch(), index.getIfPrimaryTermMatch(), versionValue.seqNo, versionValue.term); + index.getIfSeqNo(), index.getIfPrimaryTerm(), versionValue.seqNo, versionValue.term); plan = IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion, getPrimaryTerm()); } else if (index.versionType().isVersionConflictForWrites( currentVersion, index.version(), currentNotFoundOrDeleted)) { @@ -1302,7 +1302,7 @@ protected final DeletionStrategy planDeletionAsPrimary(Delete delete) throws IOE assert delete.origin() == Operation.Origin.PRIMARY : "planing as primary but got " + delete.origin(); assert getMaxSeqNoOfUpdatesOrDeletes() != SequenceNumbers.UNASSIGNED_SEQ_NO : "max_seq_no_of_updates is not initialized"; // resolve operation from external to internal - final VersionValue versionValue = resolveDocVersion(delete, delete.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO); + final VersionValue versionValue = resolveDocVersion(delete, delete.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO); assert incrementVersionLookup(); final long currentVersion; final boolean currentlyDeleted; @@ -1314,15 +1314,15 @@ protected final DeletionStrategy planDeletionAsPrimary(Delete delete) throws IOE currentlyDeleted = versionValue.isDelete(); } final DeletionStrategy plan; - if (delete.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO && versionValue == null) { + if (delete.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO && versionValue == null) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, delete.type(), delete.id(), - delete.getIfSeqNoMatch(), delete.getIfPrimaryTermMatch(), SequenceNumbers.UNASSIGNED_SEQ_NO, 0); + delete.getIfSeqNo(), delete.getIfPrimaryTerm(), SequenceNumbers.UNASSIGNED_SEQ_NO, 0); plan = DeletionStrategy.skipDueToVersionConflict(e, currentVersion, getPrimaryTerm(), currentlyDeleted); - } else if (delete.getIfSeqNoMatch() != SequenceNumbers.UNASSIGNED_SEQ_NO && ( - versionValue.seqNo != delete.getIfSeqNoMatch() || versionValue.term != delete.getIfPrimaryTermMatch() + } else if (delete.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO && ( + versionValue.seqNo != delete.getIfSeqNo() || versionValue.term != delete.getIfPrimaryTerm() )) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, delete.type(), delete.id(), - delete.getIfSeqNoMatch(), delete.getIfPrimaryTermMatch(), versionValue.seqNo, versionValue.term); + delete.getIfSeqNo(), delete.getIfPrimaryTerm(), versionValue.seqNo, versionValue.term); plan = DeletionStrategy.skipDueToVersionConflict(e, currentVersion, getPrimaryTerm(), currentlyDeleted); } else if (delete.versionType().isVersionConflictForWrites(currentVersion, delete.version(), currentlyDeleted)) { final VersionConflictEngineException e = new VersionConflictEngineException(shardId, delete, currentVersion, currentlyDeleted); diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 217c2b70f8d77..d5537ececc385 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -686,12 +686,12 @@ private IndexShardState changeState(IndexShardState newState, String reason) { } public Engine.IndexResult applyIndexOperationOnPrimary(long version, VersionType versionType, SourceToParse sourceToParse, - long ifSeqNoMatch, long ifPrimaryTermMatch, long autoGeneratedTimestamp, + long ifSeqNo, long ifPrimaryTerm, long autoGeneratedTimestamp, boolean isRetry) throws IOException { assert versionType.validateVersionForWrites(version); - return applyIndexOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, versionType, ifSeqNoMatch, - ifPrimaryTermMatch, autoGeneratedTimestamp, isRetry, Engine.Operation.Origin.PRIMARY, sourceToParse); + return applyIndexOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, versionType, ifSeqNo, + ifPrimaryTerm, autoGeneratedTimestamp, isRetry, Engine.Operation.Origin.PRIMARY, sourceToParse); } public Engine.IndexResult applyIndexOperationOnReplica(long seqNo, long version, long autoGeneratedTimeStamp, @@ -702,7 +702,7 @@ public Engine.IndexResult applyIndexOperationOnReplica(long seqNo, long version, } private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, - @Nullable VersionType versionType, long ifSeqNoMatch, long ifPrimaryTermMatch, + @Nullable VersionType versionType, long ifSeqNo, long ifPrimaryTerm, long autoGeneratedTimeStamp, boolean isRetry, Engine.Operation.Origin origin, SourceToParse sourceToParse) throws IOException { assert opPrimaryTerm <= this.operationPrimaryTerm: "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm @@ -712,7 +712,7 @@ private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long o try { operation = prepareIndex(docMapper(sourceToParse.type()), indexSettings.getIndexVersionCreated(), sourceToParse, seqNo, opPrimaryTerm, version, versionType, origin, autoGeneratedTimeStamp, isRetry, - ifSeqNoMatch, ifPrimaryTermMatch); + ifSeqNo, ifPrimaryTerm); Mapping update = operation.parsedDoc().dynamicMappingsUpdate(); if (update != null) { return new Engine.IndexResult(update); @@ -732,7 +732,7 @@ private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long o public static Engine.Index prepareIndex(DocumentMapperForType docMapper, Version indexCreatedVersion, SourceToParse source, long seqNo, long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin, long autoGeneratedIdTimestamp, boolean isRetry, - long ifSeqNoMatch, long ifPrimaryTermMatch) { + long ifSeqNo, long ifPrimaryTerm) { long startTime = System.nanoTime(); ParsedDocument doc = docMapper.getDocumentMapper().parse(source); if (docMapper.getMapping() != null) { @@ -740,7 +740,7 @@ public static Engine.Index prepareIndex(DocumentMapperForType docMapper, Version } Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(doc.id())); return new Engine.Index(uid, doc, seqNo, primaryTerm, version, versionType, origin, startTime, autoGeneratedIdTimestamp, isRetry, - ifSeqNoMatch, ifPrimaryTermMatch); + ifSeqNo, ifPrimaryTerm); } private Engine.IndexResult index(Engine engine, Engine.Index index) throws IOException { @@ -792,11 +792,11 @@ public Engine.DeleteResult getFailedDeleteResult(Exception e, long version) { } public Engine.DeleteResult applyDeleteOperationOnPrimary(long version, String type, String id, VersionType versionType, - long ifSeqNoMatch, long ifPrimaryTermMatch) + long ifSeqNo, long ifPrimaryTerm) throws IOException { assert versionType.validateVersionForWrites(version); return applyDeleteOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, type, id, versionType, - ifSeqNoMatch, ifPrimaryTermMatch, Engine.Operation.Origin.PRIMARY); + ifSeqNo, ifPrimaryTerm, Engine.Operation.Origin.PRIMARY); } public Engine.DeleteResult applyDeleteOperationOnReplica(long seqNo, long version, String type, String id) throws IOException { @@ -805,7 +805,7 @@ public Engine.DeleteResult applyDeleteOperationOnReplica(long seqNo, long versio } private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, String type, String id, - @Nullable VersionType versionType, long ifSeqNoMatch, long ifPrimaryTermMatch, + @Nullable VersionType versionType, long ifSeqNo, long ifPrimaryTerm, Engine.Operation.Origin origin) throws IOException { assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm + "]"; @@ -835,16 +835,16 @@ private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long } final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id)); final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, - versionType, origin, ifSeqNoMatch, ifPrimaryTermMatch); + versionType, origin, ifSeqNo, ifPrimaryTerm); return delete(engine, delete); } private Engine.Delete prepareDelete(String type, String id, Term uid, long seqNo, long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin, - long ifSeqNoMatch, long ifPrimaryTermMatch) { + long ifSeqNo, long ifPrimaryTerm) { long startTime = System.nanoTime(); return new Engine.Delete(resolveType(type), id, uid, seqNo, primaryTerm, version, versionType, origin, startTime, - ifSeqNoMatch, ifPrimaryTermMatch); + ifSeqNo, ifPrimaryTerm); } private Engine.DeleteResult delete(Engine engine, Engine.Delete delete) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index 1891b29d175c9..b19bc371794c3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -66,10 +66,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC deleteRequest.setRefreshPolicy(request.param("refresh")); deleteRequest.version(RestActions.parseVersion(request)); deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType())); - deleteRequest.setIfMatch( - request.paramAsLong("if_seq_no_match", deleteRequest.ifSeqNoMatch()), - request.paramAsLong("if_primary_term_match", deleteRequest.ifPrimaryTermMatch()) - ); + deleteRequest.setIfSeqNo(request.paramAsLong("if_seq_no", deleteRequest.ifSeqNo())); + deleteRequest.setIfPrimaryTerm(request.paramAsLong("if_primary_term", deleteRequest.ifPrimaryTerm())); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 2a072560272bf..2a64a43500e17 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -93,10 +93,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC indexRequest.setRefreshPolicy(request.param("refresh")); indexRequest.version(RestActions.parseVersion(request)); indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType())); - indexRequest.ifMatch( - request.paramAsLong("if_seq_no_match", indexRequest.ifSeqNoMatch()), - request.paramAsLong("if_primary_term_match", indexRequest.ifPrimaryTermMatch()) - ); + indexRequest.setIfSeqNo(request.paramAsLong("if_seq_no", indexRequest.ifSeqNo())); + indexRequest.setIfPrimaryTerm(request.paramAsLong("if_primary_term", indexRequest.ifPrimaryTerm())); String sOpType = request.param("op_type"); String waitForActiveShards = request.param("wait_for_active_shards"); if (waitForActiveShards != null) { diff --git a/server/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java b/server/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java index 0c253f1446cb9..f562ace967820 100644 --- a/server/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java +++ b/server/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java @@ -295,21 +295,21 @@ public void testCompareAndSet() { assertThat(indexResponse.getPrimaryTerm(), equalTo(1L)); assertThrows( - client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfMatch(10, 1).execute(), + client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfSeqNo(10).setIfPrimaryTerm(1).execute(), VersionConflictEngineException.class); assertThrows( - client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfMatch(10, 2).execute(), + client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfSeqNo(10).setIfPrimaryTerm(2).execute(), VersionConflictEngineException.class); assertThrows( - client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfMatch(1, 2).execute(), + client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setIfSeqNo(1).setIfPrimaryTerm(2).execute(), VersionConflictEngineException.class); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(10, 1).execute(), VersionConflictEngineException.class); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(10, 2).execute(), VersionConflictEngineException.class); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(1, 2).execute(), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(10).setIfPrimaryTerm(1), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(10).setIfPrimaryTerm(2), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(1).setIfPrimaryTerm(2), VersionConflictEngineException.class); client().admin().indices().prepareRefresh().execute().actionGet(); for (int i = 0; i < 10; i++) { @@ -331,19 +331,19 @@ public void testCompareAndSet() { assertThat(searchResponse.getHits().getAt(0).getVersion(), equalTo(Versions.NOT_FOUND)); } - DeleteResponse deleteResponse = client().prepareDelete("test", "type", "1").setIfMatch(1, 1).execute().actionGet(); + DeleteResponse deleteResponse = client().prepareDelete("test", "type", "1").setIfSeqNo(1).setIfPrimaryTerm(1).get(); assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); assertThat(deleteResponse.getSeqNo(), equalTo(2L)); assertThat(deleteResponse.getPrimaryTerm(), equalTo(1L)); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(1, 1).execute(), VersionConflictEngineException.class); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(3, 2).execute(), VersionConflictEngineException.class); - assertThrows(client().prepareDelete("test", "type", "1").setIfMatch(1, 2).execute(), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(1).setIfPrimaryTerm(1), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(3).setIfPrimaryTerm(12), VersionConflictEngineException.class); + assertThrows(client().prepareDelete("test", "type", "1").setIfSeqNo(1).setIfPrimaryTerm(2), VersionConflictEngineException.class); // This is intricate - the object was deleted but a delete transaction was with the right version. We add another one // and thus the transaction is increased. - deleteResponse = client().prepareDelete("test", "type", "1").setIfMatch(2, 1).execute().actionGet(); + deleteResponse = client().prepareDelete("test", "type", "1").setIfSeqNo(2).setIfPrimaryTerm(1).get(); assertEquals(DocWriteResponse.Result.NOT_FOUND, deleteResponse.getResult()); assertThat(deleteResponse.getSeqNo(), equalTo(3L)); assertThat(deleteResponse.getPrimaryTerm(), equalTo(1L)); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java index 1b4856487afe4..99998342b11e2 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java @@ -318,11 +318,11 @@ private Engine.Result applyOperation(Engine engine, Engine.Operation op, Engine.Index index = (Engine.Index) op; result = engine.index(new Engine.Index(index.uid(), index.parsedDoc(), index.seqNo(), primaryTerm, index.version(), versionType, origin, index.startTime(), index.getAutoGeneratedIdTimestamp(), index.isRetry(), - index.getIfSeqNoMatch(), index.getIfPrimaryTermMatch())); + index.getIfSeqNo(), index.getIfPrimaryTerm())); } else if (op instanceof Engine.Delete) { Engine.Delete delete = (Engine.Delete) op; result = engine.delete(new Engine.Delete(delete.type(), delete.id(), delete.uid(), delete.seqNo(), primaryTerm, - delete.version(), versionType, origin, delete.startTime(), delete.getIfSeqNoMatch(), delete.getIfPrimaryTermMatch())); + delete.version(), versionType, origin, delete.startTime(), delete.getIfSeqNo(), delete.getIfPrimaryTerm())); } else { Engine.NoOp noOp = (Engine.NoOp) op; result = engine.noOp(new Engine.NoOp(noOp.seqNo(), primaryTerm, origin, noOp.startTime(), noOp.reason())); From dbe6bef9b39a859c9294077301ba90f9066a8ab6 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Tue, 18 Dec 2018 11:47:44 +0100 Subject: [PATCH 6/6] java docs --- .../action/delete/DeleteRequest.java | 25 +++++++++++++++++++ .../action/delete/DeleteRequestBuilder.java | 12 ++++++--- .../action/index/IndexRequest.java | 25 +++++++++++++++++++ .../action/index/IndexRequestBuilder.java | 12 ++++++--- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java index f14065f04a880..59e6c437809f6 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java @@ -212,14 +212,32 @@ public DeleteRequest versionType(VersionType versionType) { return this; } + /** + * If set, only perform this delete request if the document was last modification was assigned this sequence number. + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public long ifSeqNo() { return ifSeqNo; } + /** + * If set, only perform this delete request if the document was last modification was assigned this primary term. + * + * If the document last modification was assigned a different term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public long ifPrimaryTerm() { return ifPrimaryTerm; } + /** + * only perform this delete request if the document was last modification was assigned the given + * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} + * + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public DeleteRequest setIfSeqNo(long seqNo) { if (seqNo < 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { throw new IllegalArgumentException("sequence numbers must be non negative. got [" + seqNo + "]."); @@ -228,6 +246,13 @@ public DeleteRequest setIfSeqNo(long seqNo) { return this; } + /** + * only perform this delete request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} + * + * If the document last modification was assigned a different primary term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public DeleteRequest setIfPrimaryTerm(long term) { if (term < 0) { throw new IllegalArgumentException("primary term must be non negative. got [" + term + "]"); diff --git a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java index fede9f1da39ca..71a971111c0d7 100644 --- a/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java @@ -82,8 +82,11 @@ public DeleteRequestBuilder setVersionType(VersionType versionType) { } /** - * only performs this delete request if the document was last modification was assigned the given + * only perform this delete request if the document was last modification was assigned the given * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} + * + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. */ public DeleteRequestBuilder setIfSeqNo(long seqNo) { request.setIfSeqNo(seqNo); @@ -91,8 +94,11 @@ public DeleteRequestBuilder setIfSeqNo(long seqNo) { } /** - * only performs this delete request if the document was last modification was assigned the given - * primary term. Must be used in combination with {@link #setIfSeqNo(long)} (long)} + * only perform this delete request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} + * + * If the document last modification was assigned a different term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. */ public DeleteRequestBuilder setIfPrimaryTerm(long term) { request.setIfPrimaryTerm(term); diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index e0a6a54c3918b..95473bf2ff2ea 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -493,6 +493,13 @@ public IndexRequest versionType(VersionType versionType) { return this; } + /** + * only perform this indexing request if the document was last modification was assigned the given + * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} + * + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public IndexRequest setIfSeqNo(long seqNo) { if (seqNo < 0 && seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { throw new IllegalArgumentException("sequence numbers must be non negative. got [" + seqNo + "]."); @@ -501,6 +508,13 @@ public IndexRequest setIfSeqNo(long seqNo) { return this; } + /** + * only performs this indexing request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} + * + * If the document last modification was assigned a different term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public IndexRequest setIfPrimaryTerm(long term) { if (term < 0) { throw new IllegalArgumentException("primary term must be non negative. got [" + term + "]"); @@ -509,10 +523,21 @@ public IndexRequest setIfPrimaryTerm(long term) { return this; } + /** + * If set, only perform this indexing request if the document was last modification was assigned this sequence number. + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public long ifSeqNo() { return ifSeqNo; } + /** + * If set, only perform this indexing request if the document was last modification was assigned this primary term. + * + * If the document last modification was assigned a different term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. + */ public long ifPrimaryTerm() { return ifPrimaryTerm; } diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java index 02381f8528f8b..19074bbd92eb7 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java @@ -200,8 +200,11 @@ public IndexRequestBuilder setVersionType(VersionType versionType) { } /** - * only performs this indexing request if the document was last modification was assigned the given + * only perform this indexing request if the document was last modification was assigned the given * sequence number. Must be used in combination with {@link #setIfPrimaryTerm(long)} + * + * If the document last modification was assigned a different sequence number a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. */ public IndexRequestBuilder setIfSeqNo(long seqNo) { request.setIfSeqNo(seqNo); @@ -209,8 +212,11 @@ public IndexRequestBuilder setIfSeqNo(long seqNo) { } /** - * only performs this indexing request if the document was last modification was assigned the given - * primary term. Must be used in combination with {@link #setIfSeqNo(long)} (long)} + * only perform this indexing request if the document was last modification was assigned the given + * primary term. Must be used in combination with {@link #setIfSeqNo(long)} + * + * If the document last modification was assigned a different term a + * {@link org.elasticsearch.index.engine.VersionConflictEngineException} will be thrown. */ public IndexRequestBuilder setIfPrimaryTerm(long term) { request.setIfPrimaryTerm(term);