From b5bd8ce59e6916d83d1415911daaacf7c520aeff Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Fri, 20 Sep 2019 09:31:32 +0200 Subject: [PATCH 1/4] Allow optype CREATE for append-only indexing operation --- .../elasticsearch/upgrades/IndexingIT.java | 39 +++++++++++++++++ .../rest-api-spec/test/bulk/10_basic.yml | 39 +++++++++++++++++ .../test/bulk/11_basic_with_types.yml | 42 +++++++++++++++++++ .../action/bulk/TransportBulkAction.java | 5 +++ .../action/index/IndexRequest.java | 24 +++++++---- .../index/engine/InternalEngine.java | 3 +- .../document/DocumentActionsIT.java | 17 +++++--- .../index/engine/InternalEngineTests.java | 40 +++++++++++------- .../RecoveryDuringReplicationTests.java | 2 +- .../shard/PrimaryReplicaSyncerTests.java | 2 +- .../SourceOnlySnapshotShardTests.java | 4 +- 11 files changed, 185 insertions(+), 32 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 96ebaedadce93..93aee0d1e4658 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -21,6 +21,7 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; +import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.Booleans; import org.elasticsearch.rest.action.document.RestBulkAction; @@ -28,6 +29,8 @@ import java.nio.charset.StandardCharsets; import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.either; /** * Basic test that indexed documents survive the rolling restart. See @@ -120,6 +123,42 @@ public void testIndexing() throws IOException { } } + public void testAutoIdWithOpTypeCreate() throws IOException { + final String indexName = "auto_id_and_op_type_create_index"; + StringBuilder b = new StringBuilder(); + b.append("{\"create\": {\"_index\": \"").append(indexName).append("\"}}\n"); + b.append("{\"f1\": \"v\"}\n"); + Request bulk = new Request("POST", "/_bulk"); + bulk.addParameter("refresh", "true"); + bulk.setJsonEntity(b.toString()); + + switch (CLUSTER_TYPE) { + case OLD: + Request createTestIndex = new Request("PUT", "/" + indexName); + createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}"); + client().performRequest(createTestIndex); + break; + case MIXED: + Request waitForGreen = new Request("GET", "/_cluster/health"); + waitForGreen.addParameter("wait_for_nodes", "3"); + client().performRequest(waitForGreen); + ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(bulk)); + assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); + assertThat(e.getMessage(), + // if request goes to 8.0+ node + either(containsString("optype create not supported for indexing requests without explicit id until")) + // if request goes to 7.x node + .or(containsString("an id must be provided if version type or value are set") + )); + break; + case UPGRADED: + client().performRequest(bulk); + break; + default: + throw new UnsupportedOperationException("Unknown cluster type [" + CLUSTER_TYPE + "]"); + } + } + private void bulk(String index, String valueSuffix, int count) throws IOException { StringBuilder b = new StringBuilder(); for (int i = 0; i < count; i++) { diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml index 591cb057ede4c..10f63971b6a0d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml @@ -57,6 +57,45 @@ - match: { count: 2 } +--- +"Empty _id with op_type create": + - skip: + version: " - 7.99.99" + reason: "auto id + op type create only supported since 8.0" + + - do: + bulk: + refresh: true + body: + - index: + _index: test + _id: '' + - f: 1 + - index: + _index: test + _id: id + - f: 2 + - index: + _index: test + - f: 3 + - create: + _index: test + - f: 4 + - match: { errors: true } + - match: { items.0.index.status: 400 } + - match: { items.0.index.error.type: illegal_argument_exception } + - match: { items.0.index.error.reason: if _id is specified it must not be empty } + - match: { items.1.index.result: created } + - match: { items.2.index.result: created } + - match: { items.3.create.result: created } + + - do: + count: + index: test + + - match: { count: 3 } + + --- "empty action": diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml index 7e763cded3185..c3fe4cbabb503 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml @@ -56,6 +56,48 @@ - match: { count: 2 } +--- +"Empty _id with op_type create": + - skip: + version: " - 7.99.99" + reason: "auto id + op type create only supported since 8.0" + + - do: + bulk: + refresh: true + body: + - index: + _index: test + _type: type + _id: '' + - f: 1 + - index: + _index: test + _type: type + _id: id + - f: 2 + - index: + _index: test + _type: type + - f: 3 + - create: + _index: test + _type: type + - f: 4 + - match: { errors: true } + - match: { items.0.index.status: 400 } + - match: { items.0.index.error.type: illegal_argument_exception } + - match: { items.0.index.error.reason: if _id is specified it must not be empty } + - match: { items.1.index.result: created } + - match: { items.2.index.result: created } + - match: { items.3.create.result: created } + + - do: + count: + index: test + + - match: { count: 3 } + --- "empty action": - skip: diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 8b305bc980bd5..097eec494c9da 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -158,6 +158,7 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener actionRequest : bulkRequest.requests) { IndexRequest indexRequest = getIndexWriteRequest(actionRequest); if (indexRequest != null) { @@ -165,6 +166,10 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener 0 ? randomIntBetween(0, numDocs - 1) : 0; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java index a80f6010b026d..4d83325328f95 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotShardTests.java @@ -21,6 +21,7 @@ import org.apache.lucene.util.Bits; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; +import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; @@ -308,7 +309,8 @@ public IndexShard reindex(DirectoryReader reader, MappingMetaData mapping) throw assert source != null : "_source is null but should have been filtered out at snapshot time"; Engine.Result result = targetShard.applyIndexOperationOnPrimary(Versions.MATCH_ANY, VersionType.INTERNAL, new SourceToParse(index, uid.type(), uid.id(), source, XContentHelper.xContentType(source), - rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, 1, false); + rootFieldsVisitor.routing()), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, + IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false); if (result.getResultType() != Engine.Result.Type.SUCCESS) { throw new IllegalStateException("failed applying post restore operation result: " + result .getResultType(), result.getFailure()); From c902ff67072a2d7b92c19bc7aa4eea3b58e8327d Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 26 Sep 2019 16:05:05 +0200 Subject: [PATCH 2/4] test fixes --- .../elasticsearch/upgrades/IndexingIT.java | 28 ++++++++++++++++--- ...ActionIndicesThatCannotBeCreatedTests.java | 5 ++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 93aee0d1e4658..291b261f61e98 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.upgrades; import org.apache.http.util.EntityUtils; +import org.elasticsearch.Version; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; @@ -27,6 +28,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Map; import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM; import static org.hamcrest.Matchers.containsString; @@ -142,14 +144,32 @@ public void testAutoIdWithOpTypeCreate() throws IOException { Request waitForGreen = new Request("GET", "/_cluster/health"); waitForGreen.addParameter("wait_for_nodes", "3"); client().performRequest(waitForGreen); - ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(bulk)); - assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); - assertThat(e.getMessage(), + + Version minNodeVersion = null; + Map response = entityAsMap(client().performRequest(new Request("GET", "_nodes/plugins"))); + Map nodes = (Map) response.get("nodes"); + for (Map.Entry node : nodes.entrySet()) { + Map nodeInfo = (Map) node.getValue(); + Version nodeVersion = Version.fromString(nodeInfo.get("version").toString()); + if (minNodeVersion == null) { + minNodeVersion = nodeVersion; + } else if (nodeVersion.before(minNodeVersion)) { + minNodeVersion = nodeVersion; + } + } + + if (minNodeVersion.before(Version.V_8_0_0)) { + ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(bulk)); + assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); + assertThat(e.getMessage(), // if request goes to 8.0+ node either(containsString("optype create not supported for indexing requests without explicit id until")) // if request goes to 7.x node .or(containsString("an id must be provided if version type or value are set") - )); + )); + } else { + client().performRequest(bulk); + } break; case UPGRADED: client().performRequest(bulk); diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java index fb71d33aa564f..7b2030e78a2bc 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.bulk; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.delete.DeleteRequest; @@ -28,6 +29,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AtomicArray; @@ -107,6 +109,9 @@ private void indicesThatCannotBeCreatedTestCase(Set expected, ClusterState state = mock(ClusterState.class); when(state.getMetaData()).thenReturn(MetaData.EMPTY_META_DATA); when(clusterService.state()).thenReturn(state); + DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class); + when(state.nodes()).thenReturn(discoveryNodes); + when(discoveryNodes.getMinNodeVersion()).thenReturn(Version.CURRENT); DiscoveryNode localNode = mock(DiscoveryNode.class); when(clusterService.localNode()).thenReturn(localNode); when(localNode.isIngestNode()).thenReturn(randomBoolean()); From 9b2ffac9e764b4cc09d029af6b309ea196f03359 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 26 Sep 2019 16:50:41 +0200 Subject: [PATCH 3/4] fix test --- .../java/org/elasticsearch/action/bulk/TransportBulkAction.java | 2 +- .../TransportBulkActionIndicesThatCannotBeCreatedTests.java | 2 +- .../action/bulk/TransportBulkActionIngestTests.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 097eec494c9da..96c6673e58ad2 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -158,7 +158,7 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener actionRequest : bulkRequest.requests) { IndexRequest indexRequest = getIndexWriteRequest(actionRequest); if (indexRequest != null) { diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java index 7b2030e78a2bc..fe47eaf54546c 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java @@ -110,7 +110,7 @@ private void indicesThatCannotBeCreatedTestCase(Set expected, when(state.getMetaData()).thenReturn(MetaData.EMPTY_META_DATA); when(clusterService.state()).thenReturn(state); DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class); - when(state.nodes()).thenReturn(discoveryNodes); + when(state.getNodes()).thenReturn(discoveryNodes); when(discoveryNodes.getMinNodeVersion()).thenReturn(Version.CURRENT); DiscoveryNode localNode = mock(DiscoveryNode.class); when(clusterService.localNode()).thenReturn(localNode); diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java index 2690b5200d19a..56793f1c9d10c 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java @@ -190,6 +190,7 @@ public void setupAction() { ImmutableOpenMap ingestNodes = ImmutableOpenMap.builder(2) .fPut("node1", remoteNode1).fPut("node2", remoteNode2).build(); when(nodes.getIngestNodes()).thenReturn(ingestNodes); + when(nodes.getMinNodeVersion()).thenReturn(Version.CURRENT); ClusterState state = mock(ClusterState.class); when(state.getNodes()).thenReturn(nodes); MetaData metaData = MetaData.builder().indices(ImmutableOpenMap.builder() From 3a310408562e6630935ffade7378e135fc2b0cad Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Mon, 30 Sep 2019 15:45:34 +0200 Subject: [PATCH 4/4] review comments --- .../elasticsearch/upgrades/IndexingIT.java | 2 +- .../rest-api-spec/test/bulk/10_basic.yml | 7 ++++++- .../test/bulk/11_basic_with_types.yml | 7 ++++++- .../action/index/IndexRequest.java | 4 +--- .../document/DocumentActionsIT.java | 6 +++++- .../index/engine/InternalEngineTests.java | 19 +++++++++---------- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index 291b261f61e98..4c7415d25b462 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -146,7 +146,7 @@ public void testAutoIdWithOpTypeCreate() throws IOException { client().performRequest(waitForGreen); Version minNodeVersion = null; - Map response = entityAsMap(client().performRequest(new Request("GET", "_nodes/plugins"))); + Map response = entityAsMap(client().performRequest(new Request("GET", "_nodes"))); Map nodes = (Map) response.get("nodes"); for (Map.Entry node : nodes.entrySet()) { Map nodeInfo = (Map) node.getValue(); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml index 10f63971b6a0d..cab77d0bcf22b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml @@ -81,6 +81,10 @@ - create: _index: test - f: 4 + - index: + _index: test + op_type: create + - f: 5 - match: { errors: true } - match: { items.0.index.status: 400 } - match: { items.0.index.error.type: illegal_argument_exception } @@ -88,12 +92,13 @@ - match: { items.1.index.result: created } - match: { items.2.index.result: created } - match: { items.3.create.result: created } + - match: { items.4.create.result: created } - do: count: index: test - - match: { count: 3 } + - match: { count: 4 } --- diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml index c3fe4cbabb503..43f1a78b34e09 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/11_basic_with_types.yml @@ -84,6 +84,10 @@ _index: test _type: type - f: 4 + - index: + _index: test + op_type: create + - f: 5 - match: { errors: true } - match: { items.0.index.status: 400 } - match: { items.0.index.error.type: illegal_argument_exception } @@ -91,12 +95,13 @@ - match: { items.1.index.result: created } - match: { items.2.index.result: created } - match: { items.3.create.result: created } + - match: { items.4.create.result: created } - do: count: index: test - - match: { count: 3 } + - match: { count: 4 } --- "empty action": 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 889cd4c922883..3155a32fc7fcd 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -194,6 +194,7 @@ public ActionRequestValidationException validate() { if (contentType == null) { validationException = addValidationError("content type is missing", validationException); } + assert opType == OpType.INDEX || opType == OpType.CREATE : "unexpected op-type: " + opType; final long resolvedVersion = resolveVersionDefaults(); if (opType == OpType.CREATE) { if (versionType != VersionType.INTERNAL) { @@ -216,9 +217,6 @@ public ActionRequestValidationException validate() { } if (id == null) { - if (opType != OpType.INDEX && opType != OpType.CREATE) { - addValidationError("an id is required for a " + opType + " operation", validationException); - } if (versionType != VersionType.INTERNAL || (resolvedVersion != Versions.MATCH_DELETED && resolvedVersion != Versions.MATCH_ANY)) { validationException = addValidationError("an id must be provided if version type or value are set", validationException); diff --git a/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java b/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java index 33f6ae855f9da..03a503ecf593a 100644 --- a/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java +++ b/server/src/test/java/org/elasticsearch/document/DocumentActionsIT.java @@ -189,7 +189,7 @@ public void testBulk() throws Exception { .add(client().prepareIndex().setIndex("test").setType("type1").setId("1").setSource(source("1", "test"))) .add(client().prepareIndex().setIndex("test").setType("type1").setId("2").setSource(source("2", "test")).setCreate(true)) .add(client().prepareIndex().setIndex("test").setType("type1").setSource(source("3", "test"))) - .add(client().prepareIndex().setIndex("test").setType("type1").setCreate(true).setSource(source("3", "test"))) + .add(client().prepareIndex().setIndex("test").setType("type1").setCreate(true).setSource(source("4", "test"))) .add(client().prepareDelete().setIndex("test").setType("type1").setId("1")) .add(client().prepareIndex().setIndex("test").setType("type1").setSource("{ xxx }", XContentType.JSON)) // failure .execute().actionGet(); @@ -250,6 +250,10 @@ public void testBulk() throws Exception { getResult = client().get(getRequest("test").id(generatedId3)).actionGet(); assertThat("cycle #" + i, getResult.getSourceAsString(), equalTo(Strings.toString(source("3", "test")))); assertThat(getResult.getIndex(), equalTo(getConcreteIndexName())); + + getResult = client().get(getRequest("test").id(generatedId4)).actionGet(); + assertThat("cycle #" + i, getResult.getSourceAsString(), equalTo(Strings.toString(source("4", "test")))); + assertThat(getResult.getIndex(), equalTo(getConcreteIndexName())); } } diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 90bd8278c475e..d69cb8cac8eb4 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -760,14 +760,13 @@ public void testTranslogMultipleOperationsSameDocument() throws IOException { final ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(), SOURCE, null); if (randomBoolean()) { final Engine.Index operation = new Engine.Index(newUid(doc), doc, UNASSIGNED_SEQ_NO, - 0, i, VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, -1, false, - UNASSIGNED_SEQ_NO, 0); + 0, i, VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), + IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false, UNASSIGNED_SEQ_NO, 0); operations.add(operation); initialEngine.index(operation); } else { final Engine.Delete operation = new Engine.Delete("test", "1", newUid(doc), UNASSIGNED_SEQ_NO, 0, i, - VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, - UNASSIGNED_SEQ_NO, 0); + VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), UNASSIGNED_SEQ_NO, 0); operations.add(operation); initialEngine.delete(operation); } @@ -3640,8 +3639,8 @@ public void testRetryWithAutogeneratedIdWorksAndNoDuplicateDocs() throws IOExcep long autoGeneratedIdTimestamp = 0; Engine.Index index = new Engine.Index(newUid(doc), doc, UNASSIGNED_SEQ_NO, 0, - Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, System.nanoTime(), autoGeneratedIdTimestamp, isRetry, - UNASSIGNED_SEQ_NO, 0); + randomBoolean() ? Versions.MATCH_DELETED : Versions.MATCH_ANY, VersionType.INTERNAL, PRIMARY, System.nanoTime(), + autoGeneratedIdTimestamp, isRetry, UNASSIGNED_SEQ_NO, 0); Engine.IndexResult indexResult = engine.index(index); assertThat(indexResult.getVersion(), equalTo(1L)); @@ -3680,8 +3679,8 @@ public void testRetryWithAutogeneratedIdsAndWrongOrderWorksAndNoDuplicateDocs() long autoGeneratedIdTimestamp = 0; Engine.Index firstIndexRequest = new Engine.Index(newUid(doc), doc, UNASSIGNED_SEQ_NO, 0, - Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, System.nanoTime(), autoGeneratedIdTimestamp, isRetry, UNASSIGNED_SEQ_NO, - 0); + randomBoolean() ? Versions.MATCH_DELETED : Versions.MATCH_ANY, VersionType.INTERNAL, PRIMARY, System.nanoTime(), + autoGeneratedIdTimestamp, isRetry, UNASSIGNED_SEQ_NO, 0); Engine.IndexResult result = engine.index(firstIndexRequest); assertThat(result.getVersion(), equalTo(1L)); @@ -4774,7 +4773,7 @@ public void testSeqNoGenerator() throws IOException { Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, - System.currentTimeMillis(), + System.nanoTime(), IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, randomBoolean(), UNASSIGNED_SEQ_NO, 0); final Engine.IndexResult indexResult = e.index(index); @@ -4790,7 +4789,7 @@ public void testSeqNoGenerator() throws IOException { Versions.MATCH_ANY, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, - IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, UNASSIGNED_SEQ_NO, 0); + System.nanoTime(), UNASSIGNED_SEQ_NO, 0); final Engine.DeleteResult deleteResult = e.delete(delete); assertThat(deleteResult.getSeqNo(), equalTo(seqNo + 1)); assertThat(seqNoGenerator.get(), equalTo(seqNo + 2));