Skip to content

Commit

Permalink
Remove primary term from result
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Apr 19, 2017
1 parent 4c6b35c commit d4bbfcd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static BulkItemResultHolder executeIndexRequest(final IndexRequest index
return new BulkItemResultHolder(null, indexResult, bulkItemRequest);
} else {
IndexResponse response = new IndexResponse(primary.shardId(), indexRequest.type(), indexRequest.id(),
indexResult.getSeqNo(), indexResult.getPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
indexResult.getSeqNo(), primary.getPrimaryTerm(), indexResult.getVersion(), indexResult.isCreated());
return new BulkItemResultHolder(response, indexResult, bulkItemRequest);
}
}
Expand All @@ -152,7 +152,7 @@ private static BulkItemResultHolder executeDeleteRequest(final DeleteRequest del
return new BulkItemResultHolder(null, deleteResult, bulkItemRequest);
} else {
DeleteResponse response = new DeleteResponse(primary.shardId(), deleteRequest.type(), deleteRequest.id(),
deleteResult.getSeqNo(), deleteResult.getPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
deleteResult.getSeqNo(), primary.getPrimaryTerm(), deleteResult.getVersion(), deleteResult.isFound());
return new BulkItemResultHolder(response, deleteResult, bulkItemRequest);
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ private static BulkItemResultHolder executeUpdateRequest(UpdateRequest updateReq
assert result instanceof Engine.IndexResult : result.getClass();
IndexRequest updateIndexRequest = translate.action();
final IndexResponse indexResponse =
new IndexResponse(primary.shardId(), updateIndexRequest.type(), updateIndexRequest.id(), result.getSeqNo(), result.getPrimaryTerm(),
new IndexResponse(primary.shardId(), updateIndexRequest.type(), updateIndexRequest.id(), result.getSeqNo(), primary.getPrimaryTerm(),
result.getVersion(), ((Engine.IndexResult) result).isCreated());
BytesReference indexSourceAsBytes = updateIndexRequest.source();
updateResponse = new UpdateResponse(
Expand All @@ -343,7 +343,7 @@ private static BulkItemResultHolder executeUpdateRequest(UpdateRequest updateReq
assert result instanceof Engine.DeleteResult : result.getClass();
DeleteRequest updateDeleteRequest = translate.action();
DeleteResponse deleteResponse = new DeleteResponse(primary.shardId(),
updateDeleteRequest.type(), updateDeleteRequest.id(), result.getSeqNo(), result.getPrimaryTerm(),
updateDeleteRequest.type(), updateDeleteRequest.id(), result.getSeqNo(), primary.getPrimaryTerm(),
result.getVersion(), ((Engine.DeleteResult) result).isFound());
updateResponse = new UpdateResponse(
deleteResponse.getShardInfo(),
Expand Down
43 changes: 16 additions & 27 deletions core/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,20 @@ public abstract static class Result {
private final Operation.TYPE operationType;
private final long version;
private final long seqNo;
private final long primaryTerm;
private final Exception failure;
private final SetOnce<Boolean> freeze = new SetOnce<>();
private Translog.Location translogLocation;
private long took;

protected Result(Operation.TYPE operationType, Exception failure, long version, long seqNo, long primaryTerm) {
protected Result(Operation.TYPE operationType, Exception failure, long version, long seqNo) {
this.operationType = operationType;
this.failure = failure;
this.version = version;
this.seqNo = seqNo;
this.primaryTerm = primaryTerm;
}

protected Result(Operation.TYPE operationType, long version, long seqNo, long primaryTerm) {
this(operationType, null, version, seqNo, primaryTerm);
protected Result(Operation.TYPE operationType, long version, long seqNo) {
this(operationType, null, version, seqNo);
}

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

/**
* Get the primary term.
*
* @return the primary term
*/
public long getPrimaryTerm() {
return primaryTerm;
}

/** get the translog location after executing the operation */
public Translog.Location getTranslogLocation() {
return translogLocation;
Expand Down Expand Up @@ -400,20 +389,20 @@ public static class IndexResult extends Result {
private final boolean created;

public IndexResult(long version, long seqNo, long primaryTerm, boolean created) {
super(Operation.TYPE.INDEX, version, seqNo, primaryTerm);
super(Operation.TYPE.INDEX, version, seqNo);
this.created = created;
}

/**
* use in case of index operation failed before getting to internal engine
* (e.g while preparing operation or updating mappings)
* */
public IndexResult(Exception failure, long version, long primaryTerm) {
this(failure, version, SequenceNumbersService.UNASSIGNED_SEQ_NO, primaryTerm);
public IndexResult(Exception failure, long version) {
this(failure, version, SequenceNumbersService.UNASSIGNED_SEQ_NO);
}

public IndexResult(Exception failure, long version, long seqNo, long primaryTerm) {
super(Operation.TYPE.INDEX, failure, version, seqNo, primaryTerm);
public IndexResult(Exception failure, long version, long seqNo) {
super(Operation.TYPE.INDEX, failure, version, seqNo);
this.created = false;
}

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

private final boolean found;

public DeleteResult(long version, long seqNo, long primaryTerm, boolean found) {
super(Operation.TYPE.DELETE, version, seqNo, primaryTerm);
public DeleteResult(long version, long seqNo, boolean found) {
super(Operation.TYPE.DELETE, version, seqNo);
this.found = found;
}

public DeleteResult(Exception failure, long version, long seqNo, long primaryTerm, boolean found) {
super(Operation.TYPE.DELETE, failure, version, seqNo, primaryTerm);
public DeleteResult(Exception failure, long version, long seqNo, boolean found) {
super(Operation.TYPE.DELETE, failure, version, seqNo);
this.found = found;
}

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

static class NoOpResult extends Result {

NoOpResult(long seqNo, long primaryTerm) {
super(Operation.TYPE.NO_OP, 0, seqNo, primaryTerm);
NoOpResult(long seqNo) {
super(Operation.TYPE.NO_OP, 0, seqNo);
}

NoOpResult(long seqNo, long primaryTerm, Exception failure) {
super(Operation.TYPE.NO_OP, failure, 0, seqNo, primaryTerm);
NoOpResult(long seqNo, Exception failure) {
super(Operation.TYPE.NO_OP, failure, 0, seqNo);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ public DeleteResult delete(Delete delete) throws IOException {
deleteResult = deleteInLucene(delete, plan);
} else {
deleteResult = new DeleteResult(
plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
}
if (!deleteResult.hasFailure() &&
delete.origin() != Operation.Origin.LOCAL_TRANSLOG_RECOVERY) {
Expand Down Expand Up @@ -990,12 +990,12 @@ private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan)
new DeleteVersionValue(plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(),
engineConfig.getThreadPool().relativeTimeInMillis()));
return new DeleteResult(
plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
} catch (Exception ex) {
if (indexWriter.getTragicException() == null) {
// there is no tragic event and such it must be a document level failure
return new DeleteResult(
ex, plan.versionOfDeletion, plan.seqNoOfDeletion, delete.primaryTerm(), plan.currentlyDeleted == false);
ex, plan.versionOfDeletion, plan.seqNoOfDeletion, plan.currentlyDeleted == false);
} else {
throw ex;
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ private DeletionStrategy(boolean deleteFromLucene, boolean currentlyDeleted,
static DeletionStrategy skipDueToVersionConflict(
VersionConflictEngineException e, long currentVersion, long primaryTerm, boolean currentlyDeleted) {
final DeleteResult deleteResult =
new DeleteResult(e, currentVersion, SequenceNumbersService.UNASSIGNED_SEQ_NO, primaryTerm, currentlyDeleted == false);
new DeleteResult(e, currentVersion, SequenceNumbersService.UNASSIGNED_SEQ_NO, currentlyDeleted == false);
return new DeletionStrategy(
false, currentlyDeleted, SequenceNumbersService.UNASSIGNED_SEQ_NO, Versions.NOT_FOUND, deleteResult);
}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ public NoOpResult noOp(final NoOp noOp) {
try (ReleasableLock ignored = readLock.acquire()) {
noOpResult = innerNoOp(noOp);
} catch (final Exception e) {
noOpResult = new NoOpResult(noOp.seqNo(), noOp.primaryTerm(), e);
noOpResult = new NoOpResult(noOp.seqNo(), e);
}
return noOpResult;
}
Expand All @@ -1066,7 +1066,7 @@ private NoOpResult innerNoOp(final NoOp noOp) throws IOException {
assert noOp.seqNo() > SequenceNumbersService.NO_OPS_PERFORMED;
final long seqNo = noOp.seqNo();
try {
final NoOpResult noOpResult = new NoOpResult(noOp.seqNo(), noOp.primaryTerm());
final NoOpResult noOpResult = new NoOpResult(noOp.seqNo());
final Translog.Location location = translog.add(new Translog.NoOp(noOp.seqNo(), noOp.primaryTerm(), noOp.reason()));
noOpResult.setTranslogLocation(location);
noOpResult.setTook(System.nanoTime() - noOp.startTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ protected IndexResponse indexOnPrimary(IndexRequest request, IndexShard primary)
request.type(),
request.id(),
indexResult.getSeqNo(),
indexResult.getPrimaryTerm(),
primary.getPrimaryTerm(),
indexResult.getVersion(),
indexResult.isCreated());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void postDelete(ShardId shardId, Engine.Delete delete, Exception ex) {
ParsedDocument doc = InternalEngineTests.createParsedDoc("1", "test", null);
Engine.Delete delete = new Engine.Delete("test", "1", new Term("_uid", doc.uid()));
Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
compositeListener.postDelete(randomShardId, delete, new Engine.DeleteResult(1, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, true));
compositeListener.postDelete(randomShardId, delete, new Engine.DeleteResult(1, SequenceNumbersService.UNASSIGNED_SEQ_NO, true));
assertEquals(0, preIndex.get());
assertEquals(0, postIndex.get());
assertEquals(0, postIndexException.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ public void testTranslogOpSerialization() throws Exception {

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

out = new BytesStreamOutput();
Expand Down

0 comments on commit d4bbfcd

Please sign in to comment.