Skip to content

Commit

Permalink
Support external versioning for deletes arriving before initial update,
Browse files Browse the repository at this point in the history
closes #1351.
  • Loading branch information
kimchy committed Sep 22, 2011
1 parent 8d7aaa7 commit d76d7d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -634,7 +634,8 @@ private void innerDelete(Delete delete, IndexWriter writer) throws IOException {
updatedVersion = currentVersion < 0 ? 1 : currentVersion + 1;
} else { // External
if (currentVersion == -1) {
throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version());
// its an external version, that's fine, we allow it to be set
//throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), -1, delete.version());
} else if (currentVersion >= delete.version()) {
throw new VersionConflictEngineException(shardId, delete.type(), delete.id(), currentVersion, delete.version());
}
Expand Down
Expand Up @@ -61,6 +61,24 @@ public class SimpleVersioningTests extends AbstractNodesTests {
closeAllNodes();
}

@Test public void testExternalVersioningInitialDelete() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();

client.admin().indices().prepareCreate("test").execute().actionGet();
client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();

DeleteResponse deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(17).setVersionType(VersionType.EXTERNAL).execute().actionGet();
assertThat(deleteResponse.notFound(), equalTo(true));

try {
client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(13).setVersionType(VersionType.EXTERNAL).execute().actionGet();
} catch (ElasticSearchException e) {
assertThat(e.unwrapCause(), instanceOf(VersionConflictEngineException.class));
}

client.prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(18).setVersionType(VersionType.EXTERNAL).execute().actionGet();
}

@Test public void testExternalVersioning() throws Exception {
try {
client.admin().indices().prepareDelete("test").execute().actionGet();
Expand Down

0 comments on commit d76d7d4

Please sign in to comment.