Skip to content

Commit a102ef9

Browse files
committed
Distinguish between operation and cluster state term
1 parent 9396f53 commit a102ef9

File tree

16 files changed

+116
-100
lines changed

16 files changed

+116
-100
lines changed

server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static BulkItemResultHolder executeIndexRequest(final IndexRequest index
144144
switch (indexResult.getResultType()) {
145145
case SUCCESS:
146146
IndexResponse response = new IndexResponse(primary.shardId(), indexRequest.type(), indexRequest.id(),
147-
indexResult.getSeqNo(), primary.getPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
147+
indexResult.getSeqNo(), primary.getOperationPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
148148
return new BulkItemResultHolder(response, indexResult, bulkItemRequest);
149149
case FAILURE:
150150
return new BulkItemResultHolder(null, indexResult, bulkItemRequest);
@@ -161,7 +161,7 @@ private static BulkItemResultHolder executeDeleteRequest(final DeleteRequest del
161161
switch (deleteResult.getResultType()) {
162162
case SUCCESS:
163163
DeleteResponse response = new DeleteResponse(primary.shardId(), deleteRequest.type(), deleteRequest.id(),
164-
deleteResult.getSeqNo(), primary.getPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
164+
deleteResult.getSeqNo(), primary.getOperationPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
165165
return new BulkItemResultHolder(response, deleteResult, bulkItemRequest);
166166
case FAILURE:
167167
return new BulkItemResultHolder(null, deleteResult, bulkItemRequest);
@@ -300,7 +300,7 @@ static BulkItemResultHolder processUpdateResponse(final UpdateRequest updateRequ
300300
assert result instanceof Engine.IndexResult : result.getClass();
301301
final IndexRequest updateIndexRequest = translate.action();
302302
final IndexResponse indexResponse = new IndexResponse(primary.shardId(), updateIndexRequest.type(), updateIndexRequest.id(),
303-
result.getSeqNo(), primary.getPrimaryTerm(), result.getVersion(), ((Engine.IndexResult) result).isCreated());
303+
result.getSeqNo(), primary.getOperationPrimaryTerm(), result.getVersion(), ((Engine.IndexResult) result).isCreated());
304304
updateResponse = new UpdateResponse(indexResponse.getShardInfo(), indexResponse.getShardId(), indexResponse.getType(),
305305
indexResponse.getId(), indexResponse.getSeqNo(), indexResponse.getPrimaryTerm(), indexResponse.getVersion(),
306306
indexResponse.getResult());
@@ -320,7 +320,7 @@ static BulkItemResultHolder processUpdateResponse(final UpdateRequest updateRequ
320320
final DeleteRequest updateDeleteRequest = translate.action();
321321

322322
final DeleteResponse deleteResponse = new DeleteResponse(primary.shardId(), updateDeleteRequest.type(), updateDeleteRequest.id(),
323-
result.getSeqNo(), primary.getPrimaryTerm(), result.getVersion(), ((Engine.DeleteResult) result).isFound());
323+
result.getSeqNo(), primary.getOperationPrimaryTerm(), result.getVersion(), ((Engine.DeleteResult) result).isFound());
324324

325325
updateResponse = new UpdateResponse(deleteResponse.getShardInfo(), deleteResponse.getShardId(),
326326
deleteResponse.getType(), deleteResponse.getId(), deleteResponse.getSeqNo(), deleteResponse.getPrimaryTerm(),
@@ -490,6 +490,7 @@ public static Translog.Location performOnReplica(BulkShardRequest request, Index
490490
switch (replicaItemExecutionMode(item, i)) {
491491
case NORMAL:
492492
final DocWriteResponse primaryResponse = item.getPrimaryResponse().getResponse();
493+
assert replica.getOperationPrimaryTerm() == primaryResponse.getPrimaryTerm();
493494
operationResult = performOpOnReplica(primaryResponse, docWriteRequest, replica);
494495
assert operationResult != null : "operation result must never be null when primary response has no failure";
495496
location = syncOperationResultOrThrow(operationResult, location);

server/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ private void acquirePrimaryShardReference(ShardId shardId, String allocationId,
929929
if (actualAllocationId.equals(allocationId) == false) {
930930
throw new ShardNotFoundException(shardId, "expected aID [{}] but found [{}]", allocationId, actualAllocationId);
931931
}
932-
final long actualTerm = indexShard.getPrimaryTerm();
932+
final long actualTerm = indexShard.getClusterStatePrimaryTerm();
933933
if (actualTerm != primaryTerm) {
934934
throw new ShardNotFoundException(shardId, "expected aID [{}] with term [{}] but found [{}]", allocationId,
935935
primaryTerm, actualTerm);

0 commit comments

Comments
 (0)