Skip to content

Commit d4bbfcd

Browse files
committed
Remove primary term from result
1 parent 4c6b35c commit d4bbfcd

File tree

6 files changed

+29
-40
lines changed

6 files changed

+29
-40
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static BulkItemResultHolder executeIndexRequest(final IndexRequest index
139139
return new BulkItemResultHolder(null, indexResult, bulkItemRequest);
140140
} else {
141141
IndexResponse response = new IndexResponse(primary.shardId(), indexRequest.type(), indexRequest.id(),
142-
indexResult.getSeqNo(), indexResult.getPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
142+
indexResult.getSeqNo(), primary.getPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
143143
return new BulkItemResultHolder(response, indexResult, bulkItemRequest);
144144
}
145145
}
@@ -152,7 +152,7 @@ private static BulkItemResultHolder executeDeleteRequest(final DeleteRequest del
152152
return new BulkItemResultHolder(null, deleteResult, bulkItemRequest);
153153
} else {
154154
DeleteResponse response = new DeleteResponse(primary.shardId(), deleteRequest.type(), deleteRequest.id(),
155-
deleteResult.getSeqNo(), deleteResult.getPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
155+
deleteResult.getSeqNo(), primary.getPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
156156
return new BulkItemResultHolder(response, deleteResult, bulkItemRequest);
157157
}
158158
}
@@ -317,7 +317,7 @@ private static BulkItemResultHolder executeUpdateRequest(UpdateRequest updateReq
317317
assert result instanceof Engine.IndexResult : result.getClass();
318318
IndexRequest updateIndexRequest = translate.action();
319319
final IndexResponse indexResponse =
320-
new IndexResponse(primary.shardId(), updateIndexRequest.type(), updateIndexRequest.id(), result.getSeqNo(), result.getPrimaryTerm(),
320+
new IndexResponse(primary.shardId(), updateIndexRequest.type(), updateIndexRequest.id(), result.getSeqNo(), primary.getPrimaryTerm(),
321321
result.getVersion(), ((Engine.IndexResult) result).isCreated());
322322
BytesReference indexSourceAsBytes = updateIndexRequest.source();
323323
updateResponse = new UpdateResponse(
@@ -343,7 +343,7 @@ private static BulkItemResultHolder executeUpdateRequest(UpdateRequest updateReq
343343
assert result instanceof Engine.DeleteResult : result.getClass();
344344
DeleteRequest updateDeleteRequest = translate.action();
345345
DeleteResponse deleteResponse = new DeleteResponse(primary.shardId(),
346-
updateDeleteRequest.type(), updateDeleteRequest.id(), result.getSeqNo(), result.getPrimaryTerm(),
346+
updateDeleteRequest.type(), updateDeleteRequest.id(), result.getSeqNo(), primary.getPrimaryTerm(),
347347
result.getVersion(), ((Engine.DeleteResult) result).isFound());
348348
updateResponse = new UpdateResponse(
349349
deleteResponse.getShardInfo(),

core/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,20 @@ public abstract static class Result {
307307
private final Operation.TYPE operationType;
308308
private final long version;
309309
private final long seqNo;
310-
private final long primaryTerm;
311310
private final Exception failure;
312311
private final SetOnce<Boolean> freeze = new SetOnce<>();
313312
private Translog.Location translogLocation;
314313
private long took;
315314

316-
protected Result(Operation.TYPE operationType, Exception failure, long version, long seqNo, long primaryTerm) {
315+
protected Result(Operation.TYPE operationType, Exception failure, long version, long seqNo) {
317316
this.operationType = operationType;
318317
this.failure = failure;
319318
this.version = version;
320319
this.seqNo = seqNo;
321-
this.primaryTerm = primaryTerm;
322320
}
323321

324-
protected Result(Operation.TYPE operationType, long version, long seqNo, long primaryTerm) {
325-
this(operationType, null, version, seqNo, primaryTerm);
322+
protected Result(Operation.TYPE operationType, long version, long seqNo) {
323+
this(operationType, null, version, seqNo);
326324
}
327325

328326
/** whether the operation had failure */
@@ -344,15 +342,6 @@ public long getSeqNo() {
344342
return seqNo;
345343
}
346344

347-
/**
348-
* Get the primary term.
349-
*
350-
* @return the primary term
351-
*/
352-
public long getPrimaryTerm() {
353-
return primaryTerm;
354-
}
355-
356345
/** get the translog location after executing the operation */
357346
public Translog.Location getTranslogLocation() {
358347
return translogLocation;
@@ -400,20 +389,20 @@ public static class IndexResult extends Result {
400389
private final boolean created;
401390

402391
public IndexResult(long version, long seqNo, long primaryTerm, boolean created) {
403-
super(Operation.TYPE.INDEX, version, seqNo, primaryTerm);
392+
super(Operation.TYPE.INDEX, version, seqNo);
404393
this.created = created;
405394
}
406395

407396
/**
408397
* use in case of index operation failed before getting to internal engine
409398
* (e.g while preparing operation or updating mappings)
410399
* */
411-
public IndexResult(Exception failure, long version, long primaryTerm) {
412-
this(failure, version, SequenceNumbersService.UNASSIGNED_SEQ_NO, primaryTerm);
400+
public IndexResult(Exception failure, long version) {
401+
this(failure, version, SequenceNumbersService.UNASSIGNED_SEQ_NO);
413402
}
414403

415-
public IndexResult(Exception failure, long version, long seqNo, long primaryTerm) {
416-
super(Operation.TYPE.INDEX, failure, version, seqNo, primaryTerm);
404+
public IndexResult(Exception failure, long version, long seqNo) {
405+
super(Operation.TYPE.INDEX, failure, version, seqNo);
417406
this.created = false;
418407
}
419408

@@ -427,13 +416,13 @@ public static class DeleteResult extends Result {
427416

428417
private final boolean found;
429418

430-
public DeleteResult(long version, long seqNo, long primaryTerm, boolean found) {
431-
super(Operation.TYPE.DELETE, version, seqNo, primaryTerm);
419+
public DeleteResult(long version, long seqNo, boolean found) {
420+
super(Operation.TYPE.DELETE, version, seqNo);
432421
this.found = found;
433422
}
434423

435-
public DeleteResult(Exception failure, long version, long seqNo, long primaryTerm, boolean found) {
436-
super(Operation.TYPE.DELETE, failure, version, seqNo, primaryTerm);
424+
public DeleteResult(Exception failure, long version, long seqNo, boolean found) {
425+
super(Operation.TYPE.DELETE, failure, version, seqNo);
437426
this.found = found;
438427
}
439428

@@ -445,12 +434,12 @@ public boolean isFound() {
445434

446435
static class NoOpResult extends Result {
447436

448-
NoOpResult(long seqNo, long primaryTerm) {
449-
super(Operation.TYPE.NO_OP, 0, seqNo, primaryTerm);
437+
NoOpResult(long seqNo) {
438+
super(Operation.TYPE.NO_OP, 0, seqNo);
450439
}
451440

452-
NoOpResult(long seqNo, long primaryTerm, Exception failure) {
453-
super(Operation.TYPE.NO_OP, failure, 0, seqNo, primaryTerm);
441+
NoOpResult(long seqNo, Exception failure) {
442+
super(Operation.TYPE.NO_OP, failure, 0, seqNo);
454443
}
455444

456445
}

core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ public DeleteResult delete(Delete delete) throws IOException {
896896
deleteResult = deleteInLucene(delete, plan);
897897
} else {
898898
deleteResult = new DeleteResult(
899-
plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
899+
plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
900900
}
901901
if (!deleteResult.hasFailure() &&
902902
delete.origin() != Operation.Origin.LOCAL_TRANSLOG_RECOVERY) {
@@ -990,12 +990,12 @@ private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan)
990990
new DeleteVersionValue(plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(),
991991
engineConfig.getThreadPool().relativeTimeInMillis()));
992992
return new DeleteResult(
993-
plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
993+
plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
994994
} catch (Exception ex) {
995995
if (indexWriter.getTragicException() == null) {
996996
// there is no tragic event and such it must be a document level failure
997997
return new DeleteResult(
998-
ex, plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
998+
ex, plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
999999
} else {
10001000
throw ex;
10011001
}
@@ -1028,7 +1028,7 @@ private DeletionStrategy(boolean deleteFromLucene, boolean currentlyDeleted,
10281028
static DeletionStrategy skipDueToVersionConflict(
10291029
VersionConflictEngineException e, long currentVersion, long primaryTerm, boolean currentlyDeleted) {
10301030
final DeleteResult deleteResult =
1031-
new DeleteResult(e, currentVersion, SequenceNumbersService.UNASSIGNED_SEQ_NO, primaryTerm, currentlyDeleted == false);
1031+
new DeleteResult(e, currentVersion, SequenceNumbersService.UNASSIGNED_SEQ_NO, currentlyDeleted == false);
10321032
return new DeletionStrategy(
10331033
false, currentlyDeleted, SequenceNumbersService.UNASSIGNED_SEQ_NO, Versions.NOT_FOUND, deleteResult);
10341034
}
@@ -1057,7 +1057,7 @@ public NoOpResult noOp(final NoOp noOp) {
10571057
try (ReleasableLock ignored = readLock.acquire()) {
10581058
noOpResult = innerNoOp(noOp);
10591059
} catch (final Exception e) {
1060-
noOpResult = new NoOpResult(noOp.seqNo(), noOp.primaryTerm(), e);
1060+
noOpResult = new NoOpResult(noOp.seqNo(), e);
10611061
}
10621062
return noOpResult;
10631063
}
@@ -1066,7 +1066,7 @@ private NoOpResult innerNoOp(final NoOp noOp) throws IOException {
10661066
assert noOp.seqNo() > SequenceNumbersService.NO_OPS_PERFORMED;
10671067
final long seqNo = noOp.seqNo();
10681068
try {
1069-
final NoOpResult noOpResult = new NoOpResult(noOp.seqNo(), noOp.primaryTerm());
1069+
final NoOpResult noOpResult = new NoOpResult(noOp.seqNo());
10701070
final Translog.Location location = translog.add(new Translog.NoOp(noOp.seqNo(), noOp.primaryTerm(), noOp.reason()));
10711071
noOpResult.setTranslogLocation(location);
10721072
noOpResult.setTook(System.nanoTime() - noOp.startTime());

core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ protected IndexResponse indexOnPrimary(IndexRequest request, IndexShard primary)
569569
request.type(),
570570
request.id(),
571571
indexResult.getSeqNo(),
572-
indexResult.getPrimaryTerm(),
572+
primary.getPrimaryTerm(),
573573
indexResult.getVersion(),
574574
indexResult.isCreated());
575575
}

core/src/test/java/org/elasticsearch/index/shard/IndexingOperationListenerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void postDelete(ShardId shardId, Engine.Delete delete, Exception ex) {
137137
ParsedDocument doc = InternalEngineTests.createParsedDoc("1", "test", null);
138138
Engine.Delete delete = new Engine.Delete("test", "1", new Term("_uid", doc.uid()));
139139
Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
140-
compositeListener.postDelete(randomShardId, delete, new Engine.DeleteResult(1, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, true));
140+
compositeListener.postDelete(randomShardId, delete, new Engine.DeleteResult(1, SequenceNumbersService.UNASSIGNED_SEQ_NO, true));
141141
assertEquals(0, preIndex.get());
142142
assertEquals(0, postIndex.get());
143143
assertEquals(0, postIndexException.get());

core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ public void testTranslogOpSerialization() throws Exception {
20852085

20862086
Engine.Delete eDelete = new Engine.Delete(doc.type(), doc.id(), newUid(doc), randomSeqNum, randomPrimaryTerm,
20872087
2, VersionType.INTERNAL, Origin.PRIMARY, 0);
2088-
Engine.DeleteResult eDeleteResult = new Engine.DeleteResult(2, randomSeqNum, primaryTerm, true);
2088+
Engine.DeleteResult eDeleteResult = new Engine.DeleteResult(2, randomSeqNum, true);
20892089
Translog.Delete delete = new Translog.Delete(eDelete, eDeleteResult);
20902090

20912091
out = new BytesStreamOutput();

0 commit comments

Comments
 (0)