-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Clarify global checkpoint recovery #21934
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
Merged
jasontedor
merged 2 commits into
elastic:master
from
jasontedor:global-checkpoint-recovery-clarification
Dec 2, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -154,23 +154,33 @@ public InternalEngine(EngineConfig engineConfig) throws EngineException { | |
| throttle = new IndexThrottle(); | ||
| this.searcherFactory = new SearchFactory(logger, isClosed, engineConfig); | ||
| try { | ||
| writer = createWriter(openMode == EngineConfig.OpenMode.CREATE_INDEX_AND_TRANSLOG); | ||
| final SeqNoStats seqNoStats = loadSeqNoStats(engineConfig, writer); | ||
| if (logger.isTraceEnabled()) { | ||
| logger.trace( | ||
| "recovering max sequence number: [{}], local checkpoint: [{}], global checkpoint: [{}]", | ||
| seqNoStats.getMaxSeqNo(), | ||
| seqNoStats.getLocalCheckpoint(), | ||
| seqNoStats.getGlobalCheckpoint()); | ||
| final SeqNoStats seqNoStats; | ||
| switch (openMode) { | ||
| case OPEN_INDEX_AND_TRANSLOG: | ||
| writer = createWriter(false); | ||
| seqNoStats = loadSeqNoStatsFromLuceneAndTranslog(engineConfig.getTranslogConfig(), writer); | ||
| break; | ||
| case OPEN_INDEX_CREATE_TRANSLOG: | ||
| writer = createWriter(false); | ||
| seqNoStats = loadSeqNoStatsLucene(SequenceNumbersService.UNASSIGNED_SEQ_NO, writer); | ||
| break; | ||
| case CREATE_INDEX_AND_TRANSLOG: | ||
| writer = createWriter(true); | ||
| seqNoStats = new SeqNoStats( | ||
| SequenceNumbersService.NO_OPS_PERFORMED, | ||
| SequenceNumbersService.NO_OPS_PERFORMED, | ||
| SequenceNumbersService.UNASSIGNED_SEQ_NO); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException(openMode.toString()); | ||
| } | ||
| seqNoService = | ||
| new SequenceNumbersService( | ||
| shardId, | ||
| engineConfig.getIndexSettings(), | ||
| seqNoStats.getMaxSeqNo(), | ||
| seqNoStats.getLocalCheckpoint(), | ||
| seqNoStats.getGlobalCheckpoint()); | ||
| logger.trace( | ||
| "recovered max sequence number: [{}], local checkpoint: [{}], global checkpoint: [{}]", | ||
| seqNoStats.getMaxSeqNo(), | ||
| seqNoStats.getLocalCheckpoint(), | ||
| seqNoStats.getGlobalCheckpoint()); | ||
| indexWriter = writer; | ||
| seqNoService = sequenceNumberService(shardId, engineConfig.getIndexSettings(), seqNoStats); | ||
| translog = openTranslog(engineConfig, writer, seqNoService::getGlobalCheckpoint); | ||
| assert translog.getGeneration() != null; | ||
| } catch (IOException | TranslogCorruptedException e) { | ||
|
|
@@ -209,6 +219,18 @@ public InternalEngine(EngineConfig engineConfig) throws EngineException { | |
| logger.trace("created new InternalEngine"); | ||
| } | ||
|
|
||
| private static SequenceNumbersService sequenceNumberService( | ||
|
Contributor
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. this is what you get from the crazy syntax 👅 |
||
| final ShardId shardId, | ||
| final IndexSettings indexSettings, | ||
| final SeqNoStats seqNoStats) { | ||
| return new SequenceNumbersService( | ||
| shardId, | ||
| indexSettings, | ||
| seqNoStats.getMaxSeqNo(), | ||
| seqNoStats.getLocalCheckpoint(), | ||
| seqNoStats.getGlobalCheckpoint()); | ||
| } | ||
|
|
||
| @Override | ||
| public InternalEngine recoverFromTranslog() throws IOException { | ||
| flushLock.lock(); | ||
|
|
@@ -326,18 +348,33 @@ private Translog.TranslogGeneration loadTranslogIdFromCommit(IndexWriter writer) | |
| } | ||
|
|
||
| /** | ||
| * Reads the sequence number stats from the Lucene commit point (maximum sequence number and local checkpoint) and the Translog | ||
| * Reads the sequence number stats from the Lucene commit point (maximum sequence number and local checkpoint) and the translog | ||
| * checkpoint (global checkpoint). | ||
| * | ||
| * @param engineConfig the engine configuration (for the open mode and the translog path) | ||
| * @param writer the index writer (for the Lucene commit point) | ||
| * @param translogConfig the translog config (for the global checkpoint) | ||
| * @param indexWriter the index writer (for the Lucene commit point) | ||
| * @return the sequence number stats | ||
| * @throws IOException if an I/O exception occurred reading the Lucene commit point or the translog checkpoint | ||
| */ | ||
| private static SeqNoStats loadSeqNoStats(final EngineConfig engineConfig, final IndexWriter writer) throws IOException { | ||
| private static SeqNoStats loadSeqNoStatsFromLuceneAndTranslog( | ||
| final TranslogConfig translogConfig, | ||
| final IndexWriter indexWriter) throws IOException { | ||
| long globalCheckpoint = Translog.readGlobalCheckpoint(translogConfig.getTranslogPath()); | ||
| return loadSeqNoStatsLucene(globalCheckpoint, indexWriter); | ||
| } | ||
|
|
||
| /** | ||
| * Reads the sequence number stats from the Lucene commit point (maximum sequence number and local checkpoint) and uses the | ||
| * specified global checkpoint. | ||
| * | ||
| * @param globalCheckpoint the global checkpoint to use | ||
| * @param indexWriter the index writer (for the Lucene commit point) | ||
| * @return the sequence number stats | ||
| */ | ||
| private static SeqNoStats loadSeqNoStatsLucene(final long globalCheckpoint, final IndexWriter indexWriter) { | ||
| long maxSeqNo = SequenceNumbersService.NO_OPS_PERFORMED; | ||
| long localCheckpoint = SequenceNumbersService.NO_OPS_PERFORMED; | ||
| for (Map.Entry<String, String> entry : writer.getLiveCommitData()) { | ||
| for (Map.Entry<String, String> entry : indexWriter.getLiveCommitData()) { | ||
| final String key = entry.getKey(); | ||
| if (key.equals(LOCAL_CHECKPOINT_KEY)) { | ||
| assert localCheckpoint == SequenceNumbersService.NO_OPS_PERFORMED; | ||
|
|
@@ -348,13 +385,6 @@ private static SeqNoStats loadSeqNoStats(final EngineConfig engineConfig, final | |
| } | ||
| } | ||
|
|
||
| final long globalCheckpoint; | ||
| if (engineConfig.getOpenMode() == EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG) { | ||
| globalCheckpoint = Translog.readGlobalCheckpoint(engineConfig.getTranslogConfig().getTranslogPath()); | ||
| } else { | ||
| globalCheckpoint = SequenceNumbersService.UNASSIGNED_SEQ_NO; | ||
| } | ||
|
|
||
| return new SeqNoStats(maxSeqNo, localCheckpoint, globalCheckpoint); | ||
| } | ||
|
|
||
|
|
||
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.
nit: seqNoStats has a toString - just use it and be safe?
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.
I pushed 7a48c39.