Versioning: Delete on an already deleted document should still affect versioning, closes #1341.
This commit is contained in:
parent
bdfa07934e
commit
5ba6ec5a69
|
@ -654,11 +654,15 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentVersion == -1) {
|
if (currentVersion == -1) {
|
||||||
// if the doc does not exists, just update with doc 0
|
// doc does not exists and no prior deletes
|
||||||
delete.version(0).notFound(true);
|
delete.version(updatedVersion).notFound(true);
|
||||||
|
Translog.Location translogLocation = translog.add(new Translog.Delete(delete));
|
||||||
|
versionMap.put(delete.uid().text(), new VersionValue(updatedVersion, true, threadPool.estimatedTimeInMillis(), translogLocation));
|
||||||
} else if (versionValue != null && versionValue.delete()) {
|
} else if (versionValue != null && versionValue.delete()) {
|
||||||
// if its a delete on delete and we have the current delete version, return it
|
// a "delete on delete", in this case, we still increment the version, log it, and return that version
|
||||||
delete.version(versionValue.version()).notFound(true);
|
delete.version(updatedVersion).notFound(true);
|
||||||
|
Translog.Location translogLocation = translog.add(new Translog.Delete(delete));
|
||||||
|
versionMap.put(delete.uid().text(), new VersionValue(updatedVersion, true, threadPool.estimatedTimeInMillis(), translogLocation));
|
||||||
} else {
|
} else {
|
||||||
delete.version(updatedVersion);
|
delete.version(updatedVersion);
|
||||||
writer.deleteDocuments(delete.uid());
|
writer.deleteDocuments(delete.uid());
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.versioning;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
import org.elasticsearch.action.bulk.BulkResponse;
|
import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
|
import org.elasticsearch.action.delete.DeleteResponse;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
|
@ -85,6 +86,20 @@ public class SimpleVersioningTests extends AbstractNodesTests {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assertThat(client.prepareGet("test", "type", "1").execute().actionGet().version(), equalTo(14l));
|
assertThat(client.prepareGet("test", "type", "1").execute().actionGet().version(), equalTo(14l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteResponse deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(17).setVersionType(VersionType.EXTERNAL).execute().actionGet();
|
||||||
|
assertThat(deleteResponse.notFound(), equalTo(false));
|
||||||
|
assertThat(deleteResponse.version(), equalTo(17l));
|
||||||
|
|
||||||
|
try {
|
||||||
|
client2.prepareDelete("test", "type", "1").setVersion(2).setVersionType(VersionType.EXTERNAL).execute().actionGet();
|
||||||
|
} catch (ElasticSearchException e) {
|
||||||
|
assertThat(e.unwrapCause(), instanceOf(VersionConflictEngineException.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(18).setVersionType(VersionType.EXTERNAL).execute().actionGet();
|
||||||
|
assertThat(deleteResponse.notFound(), equalTo(true));
|
||||||
|
assertThat(deleteResponse.version(), equalTo(18l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testSimpleVersioning() throws Exception {
|
@Test public void testSimpleVersioning() throws Exception {
|
||||||
|
@ -154,6 +169,20 @@ public class SimpleVersioningTests extends AbstractNodesTests {
|
||||||
SearchResponse searchResponse = client.prepareSearch().setQuery(matchAllQuery()).execute().actionGet();
|
SearchResponse searchResponse = client.prepareSearch().setQuery(matchAllQuery()).execute().actionGet();
|
||||||
assertThat(searchResponse.hits().getAt(0).version(), equalTo(-1l));
|
assertThat(searchResponse.hits().getAt(0).version(), equalTo(-1l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteResponse deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(2).execute().actionGet();
|
||||||
|
assertThat(deleteResponse.notFound(), equalTo(false));
|
||||||
|
assertThat(deleteResponse.version(), equalTo(3l));
|
||||||
|
|
||||||
|
try {
|
||||||
|
client2.prepareDelete("test", "type", "1").setVersion(2).execute().actionGet();
|
||||||
|
} catch (ElasticSearchException e) {
|
||||||
|
assertThat(e.unwrapCause(), instanceOf(VersionConflictEngineException.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteResponse = client2.prepareDelete("test", "type", "1").setVersion(3).execute().actionGet();
|
||||||
|
assertThat(deleteResponse.notFound(), equalTo(true));
|
||||||
|
assertThat(deleteResponse.version(), equalTo(4l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testSimpleVersioningWithFlush() throws Exception {
|
@Test public void testSimpleVersioningWithFlush() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue