-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow _update and upsert to read from the transaction log #29264
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a8d3b73
Allow _update and upsert to read from the transaction log
s1monw 3fa0fc0
apply feedback from @jpountz
s1monw 41a3c32
Merge branch 'master' into read_from_translog_for_updates
s1monw 3b84354
apply feedback from @ywelch
s1monw 5be76c5
add annontation
s1monw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ | |
import org.elasticsearch.threadpool.ThreadPool; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
@@ -145,6 +146,7 @@ public class InternalEngine extends Engine { | |
* being indexed/deleted. | ||
*/ | ||
private final AtomicLong writingBytes = new AtomicLong(); | ||
private final AtomicBoolean trackTranslogLocation = new AtomicBoolean(false); | ||
|
||
@Nullable | ||
private final String historyUUID; | ||
|
@@ -558,6 +560,25 @@ public GetResult get(Get get, BiFunction<String, SearcherScope, Searcher> search | |
throw new VersionConflictEngineException(shardId, get.type(), get.id(), | ||
get.versionType().explainConflictForReads(versionValue.version, get.version())); | ||
} | ||
if (get.isReadFromTranslog()) { | ||
// this is only used for updates - API _GET calls will always read form a reader for consistency | ||
// the update call doesn't need the consistency since it's source only + _parent but parent can go away in 7.0 | ||
if (versionValue.getLocation() != null) { | ||
try { | ||
Translog.Operation operation = translog.readOperation(versionValue.getLocation()); | ||
if (operation != null) { | ||
TranslogLeafReader reader = new TranslogLeafReader((Translog.Index) operation, engineConfig | ||
.getIndexSettings().getIndexVersionCreated()); | ||
return new GetResult(new Searcher("realtime_get", new IndexSearcher(reader)), | ||
new VersionsAndSeqNoResolver.DocIdAndVersion(0, ((Translog.Index) operation).version(), reader, 0)); | ||
} | ||
} catch (IOException e) { | ||
throw new EngineException(shardId, "failed to read operation from translog", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to fail the engine (as we do when indexing)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is the read side of things I am not sure any imo exceptions are fatal?! |
||
} | ||
} else { | ||
trackTranslogLocation.set(true); | ||
} | ||
} | ||
refresh("realtime_get", SearcherScope.INTERNAL); | ||
} | ||
scope = SearcherScope.INTERNAL; | ||
|
@@ -790,6 +811,10 @@ public IndexResult index(Index index) throws IOException { | |
} | ||
indexResult.setTranslogLocation(location); | ||
} | ||
if (plan.indexIntoLucene && indexResult.hasFailure() == false) { | ||
versionMap.maybePutUnderLock(index.uid().bytes(), | ||
getVersionValue(plan.versionForIndexing, plan.seqNoForIndexing, index.primaryTerm(), indexResult.getTranslogLocation())); | ||
} | ||
if (indexResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { | ||
localCheckpointTracker.markSeqNoAsCompleted(indexResult.getSeqNo()); | ||
} | ||
|
@@ -916,8 +941,6 @@ private IndexResult indexIntoLucene(Index index, IndexingStrategy plan) | |
assert assertDocDoesNotExist(index, canOptimizeAddDocument(index) == false); | ||
index(index.docs(), indexWriter); | ||
} | ||
versionMap.maybePutUnderLock(index.uid().bytes(), | ||
new VersionValue(plan.versionForIndexing, plan.seqNoForIndexing, index.primaryTerm())); | ||
return new IndexResult(plan.versionForIndexing, plan.seqNoForIndexing, plan.currentNotFoundOrDeleted); | ||
} catch (Exception ex) { | ||
if (indexWriter.getTragicException() == null) { | ||
|
@@ -941,6 +964,13 @@ private IndexResult indexIntoLucene(Index index, IndexingStrategy plan) | |
} | ||
} | ||
|
||
private VersionValue getVersionValue(long version, long seqNo, long term, Translog.Location location) { | ||
if (location != null && trackTranslogLocation.get()) { | ||
return new TranslogVersionValue(location, version, seqNo, term); | ||
} | ||
return new VersionValue(version, seqNo, term); | ||
} | ||
|
||
/** | ||
* returns true if the indexing operation may have already be processed by this engine. | ||
* Note that it is OK to rarely return true even if this is not the case. However a `false` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when do we expect this to be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the translog generation is not available anymore I think it’s unlikely but I see a chance. I can add a comment in the code