Support external versioning for deletes arriving before initial update, closes #1351.

This commit is contained in:
Shay Banon 2011-09-23 00:56:02 +03:00
parent 8d7aaa704a
commit d76d7d4a56
2 changed files with 20 additions and 1 deletions

View File

@ -634,7 +634,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
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());
}

View File

@ -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();