Use external version type for history ops from Lucene (#31568)
Today we use INTERNAL version type for the history operations from Lucene index. However, this does not cover the case in which the original operation has the version type EXTERNAL and version number 0. Semantically all operations from translog or Lucene should always use EXTERNAL version type.
This commit is contained in:
parent
a55f614b85
commit
e4315cc710
|
@ -249,13 +249,13 @@ final class LuceneChangesSnapshot implements Translog.Snapshot {
|
|||
final String type = fields.uid().type();
|
||||
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
|
||||
if (isTombstone) {
|
||||
op = new Translog.Delete(type, id, uid, seqNo, primaryTerm, version, VersionType.INTERNAL);
|
||||
op = new Translog.Delete(type, id, uid, seqNo, primaryTerm, version, VersionType.EXTERNAL);
|
||||
assert assertDocSoftDeleted(leaf.reader(), segmentDocID) : "Delete op but soft_deletes field is not set [" + op + "]";
|
||||
} else {
|
||||
final BytesReference source = fields.source();
|
||||
// TODO: pass the latest timestamp from engine.
|
||||
final long autoGeneratedIdTimestamp = -1;
|
||||
op = new Translog.Index(type, id, seqNo, primaryTerm, version, VersionType.INTERNAL,
|
||||
op = new Translog.Index(type, id, seqNo, primaryTerm, version, VersionType.EXTERNAL,
|
||||
source == null ? null : source.toBytesRef().bytes, fields.routing(), autoGeneratedIdTimestamp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1196,6 +1196,9 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
", type='" + type + '\'' +
|
||||
", seqNo=" + seqNo +
|
||||
", primaryTerm=" + primaryTerm +
|
||||
", version=" + version +
|
||||
", versionType=" + versionType +
|
||||
", autoGeneratedIdTimestamp=" + autoGeneratedIdTimestamp +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -1340,6 +1343,8 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
"uid=" + uid +
|
||||
", seqNo=" + seqNo +
|
||||
", primaryTerm=" + primaryTerm +
|
||||
", version=" + version +
|
||||
", versionType=" + versionType +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.action.bulk.BulkResponse;
|
|||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
|
@ -785,4 +786,23 @@ public class SimpleVersioningIT extends ESIntegTestCase {
|
|||
.getVersion(),
|
||||
equalTo(-1L));
|
||||
}
|
||||
|
||||
public void testSpecialVersioning() {
|
||||
internalCluster().ensureAtLeastNumDataNodes(2);
|
||||
createIndex("test", Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build());
|
||||
IndexResponse doc1 = client().prepareIndex("test", "type", "1").setSource("field", "value1")
|
||||
.setVersion(0).setVersionType(VersionType.EXTERNAL).execute().actionGet();
|
||||
assertThat(doc1.getVersion(), equalTo(0L));
|
||||
IndexResponse doc2 = client().prepareIndex("test", "type", "1").setSource("field", "value2")
|
||||
.setVersion(Versions.MATCH_ANY).setVersionType(VersionType.INTERNAL).execute().actionGet();
|
||||
assertThat(doc2.getVersion(), equalTo(1L));
|
||||
client().prepareDelete("test", "type", "1").get(); //v2
|
||||
IndexResponse doc3 = client().prepareIndex("test", "type", "1").setSource("field", "value3")
|
||||
.setVersion(Versions.MATCH_DELETED).setVersionType(VersionType.INTERNAL).execute().actionGet();
|
||||
assertThat(doc3.getVersion(), equalTo(3L));
|
||||
// Make sure that these versions are replicated correctly
|
||||
client().admin().indices().prepareUpdateSettings("test")
|
||||
.setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)).get();
|
||||
ensureGreen("test");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue