Skip to content

Commit 9b2a6d8

Browse files
committed
Inline 'plan' and 'status'
1 parent dd4521c commit 9b2a6d8

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

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

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ enum OpVsLuceneDocStatus {
579579

580580
private OpVsLuceneDocStatus compareOpToLuceneDocBasedOnSeqNo(final Operation op) throws IOException {
581581
assert op.seqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO : "resolving ops based on seq# but no seqNo is found";
582-
final OpVsLuceneDocStatus status;
583582
if (op.seqNo() <= localCheckpointTracker.getCheckpoint()) {
584583
// The operation seq# is lower then the current local checkpoint and thus was already put into Lucene. This
585584
// can happen during recovery where older operations are sent from the translog that are already part of the
@@ -600,37 +599,36 @@ private OpVsLuceneDocStatus compareOpToLuceneDocBasedOnSeqNo(final Operation op)
600599
// then the present op would appear to be fresh and would be applied a second time. To avoid this, we must
601600
// check the local checkpoint again: since the local checkpoint only ever advances, checking it after the
602601
// call to getVersionFromMap() gives the correct result.
603-
status = OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
602+
return OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
604603
} else if (versionValue != null) {
605604
if (op.seqNo() > versionValue.seqNo ||
606-
(op.seqNo() == versionValue.seqNo && op.primaryTerm() > versionValue.term))
607-
status = OpVsLuceneDocStatus.OP_NEWER;
608-
else {
609-
status = OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
605+
(op.seqNo() == versionValue.seqNo && op.primaryTerm() > versionValue.term)) {
606+
return OpVsLuceneDocStatus.OP_NEWER;
607+
} else {
608+
return OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
610609
}
611610
} else {
612611
// load from index
613612
assert incrementIndexVersionLookup();
614613
try (Searcher searcher = acquireSearcher("load_seq_no", SearcherScope.INTERNAL)) {
615614
DocIdAndSeqNo docAndSeqNo = VersionsAndSeqNoResolver.loadDocIdAndSeqNo(searcher.reader(), op.uid());
616615
if (docAndSeqNo == null) {
617-
status = OpVsLuceneDocStatus.LUCENE_DOC_NOT_FOUND;
616+
return OpVsLuceneDocStatus.LUCENE_DOC_NOT_FOUND;
618617
} else if (op.seqNo() > docAndSeqNo.seqNo) {
619-
status = OpVsLuceneDocStatus.OP_NEWER;
618+
return OpVsLuceneDocStatus.OP_NEWER;
620619
} else if (op.seqNo() == docAndSeqNo.seqNo) {
621620
// load term to tie break
622621
final long existingTerm = VersionsAndSeqNoResolver.loadPrimaryTerm(docAndSeqNo, op.uid().field());
623622
if (op.primaryTerm() > existingTerm) {
624-
status = OpVsLuceneDocStatus.OP_NEWER;
623+
return OpVsLuceneDocStatus.OP_NEWER;
625624
} else {
626-
status = OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
625+
return OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
627626
}
628627
} else {
629-
status = OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
628+
return OpVsLuceneDocStatus.OP_STALE_OR_EQUAL;
630629
}
631630
}
632631
}
633-
return status;
634632
}
635633

636634
/** resolves the current version of the document, returning null if not found */
@@ -824,7 +822,6 @@ public IndexResult index(Index index) throws IOException {
824822
}
825823

826824
private IndexingStrategy planIndexingAsNonPrimary(Index index) throws IOException {
827-
final IndexingStrategy plan;
828825
final boolean appendOnlyRequest = canOptimizeAddDocument(index);
829826
if (appendOnlyRequest && mayHaveBeenIndexedBefore(index) == false && index.seqNo() > maxSeqNoOfNonAppendOnlyOperations.get()) {
830827
/*
@@ -836,7 +833,7 @@ private IndexingStrategy planIndexingAsNonPrimary(Index index) throws IOExceptio
836833
* requests, we can assert the replica have not seen the document of that append-only request, thus we can apply optimization.
837834
*/
838835
assert index.version() == 1L : "can optimize on replicas but incoming version is [" + index.version() + "]";
839-
plan = IndexingStrategy.optimizedAppendOnly(index.seqNo());
836+
return IndexingStrategy.optimizedAppendOnly(index.seqNo());
840837
} else {
841838
if (appendOnlyRequest == false) {
842839
maxSeqNoOfNonAppendOnlyOperations.updateAndGet(curr -> Math.max(index.seqNo(), curr));
@@ -852,26 +849,25 @@ private IndexingStrategy planIndexingAsNonPrimary(Index index) throws IOExceptio
852849
// a delete state and return false for the created flag in favor of code simplicity
853850
final OpVsLuceneDocStatus opVsLucene = compareOpToLuceneDocBasedOnSeqNo(index);
854851
if (opVsLucene == OpVsLuceneDocStatus.OP_STALE_OR_EQUAL) {
855-
plan = IndexingStrategy.processButSkipLucene(false, index.seqNo(), index.version());
852+
return IndexingStrategy.processButSkipLucene(false, index.seqNo(), index.version());
856853
} else {
857-
plan = IndexingStrategy.processNormally(
854+
return IndexingStrategy.processNormally(
858855
opVsLucene == OpVsLuceneDocStatus.LUCENE_DOC_NOT_FOUND, index.seqNo(), index.version()
859856
);
860857
}
861858
}
862-
return plan;
863859
}
864860

865861
private IndexingStrategy planIndexingAsPrimary(Index index) throws IOException {
866-
assert index.origin() == Operation.Origin.PRIMARY : "planing as primary but origin isn't. got " + index.origin();
867-
final IndexingStrategy plan;
862+
assert index.origin() == Operation.Origin.PRIMARY : "planning as primary but origin is " + index.origin();
868863
// resolve an external operation into an internal one which is safe to replay
869864
if (canOptimizeAddDocument(index)) {
870865
if (mayHaveBeenIndexedBefore(index)) {
871-
plan = IndexingStrategy.overrideExistingAsIfNotThere(generateSeqNoForOperation(index), 1L);
866+
final IndexingStrategy plan = IndexingStrategy.overrideExistingAsIfNotThere(generateSeqNoForOperation(index), 1L);
872867
versionMap.enforceSafeAccess();
868+
return plan;
873869
} else {
874-
plan = IndexingStrategy.optimizedAppendOnly(generateSeqNoForOperation(index));
870+
return IndexingStrategy.optimizedAppendOnly(generateSeqNoForOperation(index));
875871
}
876872
} else {
877873
versionMap.enforceSafeAccess();
@@ -890,15 +886,14 @@ private IndexingStrategy planIndexingAsPrimary(Index index) throws IOException {
890886
currentVersion, index.version(), currentNotFoundOrDeleted)) {
891887
final VersionConflictEngineException e =
892888
new VersionConflictEngineException(shardId, index, currentVersion, currentNotFoundOrDeleted);
893-
plan = IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion);
889+
return IndexingStrategy.skipDueToVersionConflict(e, currentNotFoundOrDeleted, currentVersion);
894890
} else {
895-
plan = IndexingStrategy.processNormally(currentNotFoundOrDeleted,
891+
return IndexingStrategy.processNormally(currentNotFoundOrDeleted,
896892
generateSeqNoForOperation(index),
897893
index.versionType().updateVersion(currentVersion, index.version())
898894
);
899895
}
900896
}
901-
return plan;
902897
}
903898

904899
private IndexResult indexIntoLucene(Index index, IndexingStrategy plan)
@@ -1138,15 +1133,13 @@ private DeletionStrategy planDeletionAsNonPrimary(Delete delete) throws IOExcept
11381133
// a delete state and return true for the found flag in favor of code simplicity
11391134
final OpVsLuceneDocStatus opVsLucene = compareOpToLuceneDocBasedOnSeqNo(delete);
11401135

1141-
final DeletionStrategy plan;
11421136
if (opVsLucene == OpVsLuceneDocStatus.OP_STALE_OR_EQUAL) {
1143-
plan = DeletionStrategy.processButSkipLucene(false, delete.seqNo(), delete.version());
1137+
return DeletionStrategy.processButSkipLucene(false, delete.seqNo(), delete.version());
11441138
} else {
1145-
plan = DeletionStrategy.processNormally(
1139+
return DeletionStrategy.processNormally(
11461140
opVsLucene == OpVsLuceneDocStatus.LUCENE_DOC_NOT_FOUND,
11471141
delete.seqNo(), delete.version());
11481142
}
1149-
return plan;
11501143
}
11511144

11521145
private DeletionStrategy planDeletionAsPrimary(Delete delete) throws IOException {
@@ -1163,17 +1156,15 @@ private DeletionStrategy planDeletionAsPrimary(Delete delete) throws IOException
11631156
currentVersion = versionValue.version;
11641157
currentlyDeleted = versionValue.isDelete();
11651158
}
1166-
final DeletionStrategy plan;
11671159
if (delete.versionType().isVersionConflictForWrites(currentVersion, delete.version(), currentlyDeleted)) {
11681160
final VersionConflictEngineException e = new VersionConflictEngineException(shardId, delete, currentVersion, currentlyDeleted);
1169-
plan = DeletionStrategy.skipDueToVersionConflict(e, currentVersion, currentlyDeleted);
1161+
return DeletionStrategy.skipDueToVersionConflict(e, currentVersion, currentlyDeleted);
11701162
} else {
1171-
plan = DeletionStrategy.processNormally(
1163+
return DeletionStrategy.processNormally(
11721164
currentlyDeleted,
11731165
generateSeqNoForOperation(delete),
11741166
delete.versionType().updateVersion(currentVersion, delete.version()));
11751167
}
1176-
return plan;
11771168
}
11781169

11791170
private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan)

0 commit comments

Comments
 (0)