Skip to content

Commit 3d53398

Browse files
committed
Support external versioning for deletes arriving before initial update, closes elastic#1351.
1 parent 38a3c77 commit 3d53398

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ private void innerDelete(Delete delete, IndexWriter writer) throws IOException {
635635
updatedVersion = currentVersion < 0 ? 1 : currentVersion + 1;
636636
} else { // External
637637
if (currentVersion == -1) {
638-
throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version());
638+
// its an external version, that's fine, we allow it to be set
639+
//throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version());
639640
} else if (currentVersion >= delete.version()) {
640641
throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), currentVersion, delete.version());
641642
}

modules/test/integration/src/test/java/org/elasticsearch/test/integration/versioning/SimpleVersioningTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ public class SimpleVersioningTests extends AbstractNodesTests {
6161
closeAllNodes();
6262
}
6363

64+
@Test public void testExternalVersioningInitialDelete() throws Exception {
65+
client.admin().indices().prepareDelete().execute().actionGet();
66+
67+
client.admin().indices().prepareCreate("test").execute().actionGet();
68+
client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
69+
70+
DeleteResponse deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(17).setVersionType(VersionType.EXTERNAL).execute().actionGet();
71+
assertThat(deleteResponse.notFound(), equalTo(true));
72+
73+
try {
74+
client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(13).setVersionType(VersionType.EXTERNAL).execute().actionGet();
75+
} catch (ElasticSearchException e) {
76+
assertThat(e.unwrapCause(), instanceOf(VersionConflictEngineException.class));
77+
}
78+
79+
client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(18).setVersionType(VersionType.EXTERNAL).execute().actionGet();
80+
}
81+
6482
@Test public void testExternalVersioning() throws Exception {
6583
try {
6684
client.admin().indices().prepareDelete("test").execute().actionGet();

0 commit comments

Comments
 (0)