|
@@ -510,7 +510,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
* the reverted operations on this shard by replaying the translog to avoid losing acknowledged writes.
|
|
|
*/
|
|
|
final Engine engine = getEngine();
|
|
|
- if (getMaxSeqNoOfUpdatesOrDeletes() == SequenceNumbers.UNASSIGNED_SEQ_NO) {
|
|
|
+ if (getMaxSeqNoOfUpdatesOrDeletes() == UNASSIGNED_SEQ_NO) {
|
|
|
// If the old primary was on an old version that did not replicate the msu,
|
|
|
// we need to bootstrap it manually from its local history.
|
|
|
assert indexSettings.getIndexVersionCreated().before(Version.V_6_5_0);
|
|
@@ -686,30 +686,33 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
}
|
|
|
|
|
|
public Engine.IndexResult applyIndexOperationOnPrimary(long version, VersionType versionType, SourceToParse sourceToParse,
|
|
|
- long autoGeneratedTimestamp, boolean isRetry) throws IOException {
|
|
|
+ long ifSeqNoMatch, long ifPrimaryTermMatch, long autoGeneratedTimestamp,
|
|
|
+ boolean isRetry)
|
|
|
+ throws IOException {
|
|
|
assert versionType.validateVersionForWrites(version);
|
|
|
- return applyIndexOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, versionType, autoGeneratedTimestamp,
|
|
|
- isRetry, Engine.Operation.Origin.PRIMARY, sourceToParse);
|
|
|
+ return applyIndexOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, versionType, ifSeqNoMatch,
|
|
|
+ ifPrimaryTermMatch, autoGeneratedTimestamp, isRetry, Engine.Operation.Origin.PRIMARY, sourceToParse);
|
|
|
}
|
|
|
|
|
|
public Engine.IndexResult applyIndexOperationOnReplica(long seqNo, long version, long autoGeneratedTimeStamp,
|
|
|
boolean isRetry, SourceToParse sourceToParse)
|
|
|
throws IOException {
|
|
|
- return applyIndexOperation(getEngine(), seqNo, operationPrimaryTerm, version, null, autoGeneratedTimeStamp, isRetry,
|
|
|
- Engine.Operation.Origin.REPLICA, sourceToParse);
|
|
|
+ return applyIndexOperation(getEngine(), seqNo, operationPrimaryTerm, version, null, UNASSIGNED_SEQ_NO, 0,
|
|
|
+ autoGeneratedTimeStamp, isRetry, Engine.Operation.Origin.REPLICA, sourceToParse);
|
|
|
}
|
|
|
|
|
|
private Engine.IndexResult applyIndexOperation(Engine engine, long seqNo, long opPrimaryTerm, long version,
|
|
|
- @Nullable VersionType versionType, long autoGeneratedTimeStamp, boolean isRetry,
|
|
|
- Engine.Operation.Origin origin, SourceToParse sourceToParse) throws IOException {
|
|
|
+ @Nullable VersionType versionType, long ifSeqNoMatch, long ifPrimaryTermMatch,
|
|
|
+ long autoGeneratedTimeStamp, boolean isRetry, Engine.Operation.Origin origin,
|
|
|
+ SourceToParse sourceToParse) throws IOException {
|
|
|
assert opPrimaryTerm <= this.operationPrimaryTerm: "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm
|
|
|
+ "]";
|
|
|
ensureWriteAllowed(origin);
|
|
|
Engine.Index operation;
|
|
|
try {
|
|
|
operation = prepareIndex(docMapper(sourceToParse.type()), indexSettings.getIndexVersionCreated(), sourceToParse, seqNo,
|
|
|
- opPrimaryTerm, version, versionType, origin,
|
|
|
- autoGeneratedTimeStamp, isRetry);
|
|
|
+ opPrimaryTerm, version, versionType, origin, autoGeneratedTimeStamp, isRetry,
|
|
|
+ ifSeqNoMatch, ifPrimaryTermMatch);
|
|
|
Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
|
|
|
if (update != null) {
|
|
|
return new Engine.IndexResult(update);
|
|
@@ -727,8 +730,9 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
}
|
|
|
|
|
|
public static Engine.Index prepareIndex(DocumentMapperForType docMapper, Version indexCreatedVersion, SourceToParse source, long seqNo,
|
|
|
- long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin, long autoGeneratedIdTimestamp,
|
|
|
- boolean isRetry) {
|
|
|
+ long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin,
|
|
|
+ long autoGeneratedIdTimestamp, boolean isRetry,
|
|
|
+ long ifSeqNoMatch, long ifPrimaryTermMatch) {
|
|
|
long startTime = System.nanoTime();
|
|
|
ParsedDocument doc = docMapper.getDocumentMapper().parse(source);
|
|
|
if (docMapper.getMapping() != null) {
|
|
@@ -736,7 +740,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
}
|
|
|
Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(doc.id()));
|
|
|
return new Engine.Index(uid, doc, seqNo, primaryTerm, version, versionType, origin, startTime, autoGeneratedIdTimestamp, isRetry,
|
|
|
- UNASSIGNED_SEQ_NO, 0);
|
|
|
+ ifSeqNoMatch, ifPrimaryTermMatch);
|
|
|
}
|
|
|
|
|
|
private Engine.IndexResult index(Engine engine, Engine.Index index) throws IOException {
|
|
@@ -787,19 +791,22 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
return new Engine.DeleteResult(e, version, operationPrimaryTerm);
|
|
|
}
|
|
|
|
|
|
- public Engine.DeleteResult applyDeleteOperationOnPrimary(long version, String type, String id, VersionType versionType)
|
|
|
+ public Engine.DeleteResult applyDeleteOperationOnPrimary(long version, String type, String id, VersionType versionType,
|
|
|
+ long ifSeqNoMatch, long ifPrimaryTermMatch)
|
|
|
throws IOException {
|
|
|
assert versionType.validateVersionForWrites(version);
|
|
|
return applyDeleteOperation(getEngine(), UNASSIGNED_SEQ_NO, operationPrimaryTerm, version, type, id, versionType,
|
|
|
- Engine.Operation.Origin.PRIMARY);
|
|
|
+ ifSeqNoMatch, ifPrimaryTermMatch, Engine.Operation.Origin.PRIMARY);
|
|
|
}
|
|
|
|
|
|
public Engine.DeleteResult applyDeleteOperationOnReplica(long seqNo, long version, String type, String id) throws IOException {
|
|
|
- return applyDeleteOperation(getEngine(), seqNo, operationPrimaryTerm, version, type, id, null, Engine.Operation.Origin.REPLICA);
|
|
|
+ return applyDeleteOperation(
|
|
|
+ getEngine(), seqNo, operationPrimaryTerm, version, type, id, null, UNASSIGNED_SEQ_NO, 0, Engine.Operation.Origin.REPLICA);
|
|
|
}
|
|
|
|
|
|
private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, String type, String id,
|
|
|
- @Nullable VersionType versionType, Engine.Operation.Origin origin) throws IOException {
|
|
|
+ @Nullable VersionType versionType, long ifSeqNoMatch, long ifPrimaryTermMatch,
|
|
|
+ Engine.Operation.Origin origin) throws IOException {
|
|
|
assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm
|
|
|
+ "]";
|
|
|
ensureWriteAllowed(origin);
|
|
@@ -828,15 +835,16 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
}
|
|
|
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
|
|
|
final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version,
|
|
|
- versionType, origin);
|
|
|
+ versionType, origin, ifSeqNoMatch, ifPrimaryTermMatch);
|
|
|
return delete(engine, delete);
|
|
|
}
|
|
|
|
|
|
private Engine.Delete prepareDelete(String type, String id, Term uid, long seqNo, long primaryTerm, long version,
|
|
|
- VersionType versionType, Engine.Operation.Origin origin) {
|
|
|
+ VersionType versionType, Engine.Operation.Origin origin,
|
|
|
+ long ifSeqNoMatch, long ifPrimaryTermMatch) {
|
|
|
long startTime = System.nanoTime();
|
|
|
return new Engine.Delete(resolveType(type), id, uid, seqNo, primaryTerm, version, versionType, origin, startTime,
|
|
|
- UNASSIGNED_SEQ_NO, 0);
|
|
|
+ ifSeqNoMatch, ifPrimaryTermMatch);
|
|
|
}
|
|
|
|
|
|
private Engine.DeleteResult delete(Engine engine, Engine.Delete delete) throws IOException {
|
|
@@ -1283,14 +1291,14 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
// we set canHaveDuplicates to true all the time such that we de-optimze the translog case and ensure that all
|
|
|
// autoGeneratedID docs that are coming from the primary are updated correctly.
|
|
|
result = applyIndexOperation(engine, index.seqNo(), index.primaryTerm(), index.version(),
|
|
|
- versionType, index.getAutoGeneratedIdTimestamp(), true, origin,
|
|
|
+ versionType, UNASSIGNED_SEQ_NO, 0, index.getAutoGeneratedIdTimestamp(), true, origin,
|
|
|
source(shardId.getIndexName(), index.type(), index.id(), index.source(),
|
|
|
XContentHelper.xContentType(index.source())).routing(index.routing()));
|
|
|
break;
|
|
|
case DELETE:
|
|
|
final Translog.Delete delete = (Translog.Delete) operation;
|
|
|
result = applyDeleteOperation(engine, delete.seqNo(), delete.primaryTerm(), delete.version(), delete.type(), delete.id(),
|
|
|
- versionType, origin);
|
|
|
+ versionType, UNASSIGNED_SEQ_NO, 0, origin);
|
|
|
break;
|
|
|
case NO_OP:
|
|
|
final Translog.NoOp noOp = (Translog.NoOp) operation;
|
|
@@ -1997,7 +2005,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
getLocalCheckpoint() == primaryContext.getCheckpointStates().get(routingEntry().allocationId().getId()).getLocalCheckpoint();
|
|
|
synchronized (mutex) {
|
|
|
replicationTracker.activateWithPrimaryContext(primaryContext); // make changes to primaryMode flag only under mutex
|
|
|
- if (getMaxSeqNoOfUpdatesOrDeletes() == SequenceNumbers.UNASSIGNED_SEQ_NO) {
|
|
|
+ if (getMaxSeqNoOfUpdatesOrDeletes() == UNASSIGNED_SEQ_NO) {
|
|
|
// If the old primary was on an old version that did not replicate the msu,
|
|
|
// we need to bootstrap it manually from its local history.
|
|
|
assert indexSettings.getIndexVersionCreated().before(Version.V_6_5_0);
|
|
@@ -2916,8 +2924,8 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl
|
|
|
* @see org.elasticsearch.indices.recovery.RecoveryTarget#indexTranslogOperations(List, int, long, long)
|
|
|
*/
|
|
|
public void advanceMaxSeqNoOfUpdatesOrDeletes(long seqNo) {
|
|
|
- assert seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO
|
|
|
- || getMaxSeqNoOfUpdatesOrDeletes() == SequenceNumbers.UNASSIGNED_SEQ_NO :
|
|
|
+ assert seqNo != UNASSIGNED_SEQ_NO
|
|
|
+ || getMaxSeqNoOfUpdatesOrDeletes() == UNASSIGNED_SEQ_NO :
|
|
|
"replica has max_seq_no_of_updates=" + getMaxSeqNoOfUpdatesOrDeletes() + " but primary does not";
|
|
|
getEngine().advanceMaxSeqNoOfUpdatesOrDeletes(seqNo);
|
|
|
assert seqNo <= getMaxSeqNoOfUpdatesOrDeletes() : getMaxSeqNoOfUpdatesOrDeletes() + " < " + seqNo;
|