-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Associate translog with Lucene index commit for searchable snapshots shards #53459
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
tlrx
merged 5 commits into
elastic:feature/searchable-snapshots
from
tlrx:associate-translog-with-lucene-index
Mar 13, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
406d4de
Associate translog with Lucene index commit
tlrx 32df1c4
Partial revert "Associate translog with Lucene index commit"
tlrx 4ab94ce
Add pre recovery hook
tlrx 557d924
Feedback
tlrx f3fc163
Merge branch 'feature/searchable-snapshots' into associate-translog-w…
elasticmachine 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
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
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
...ava/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotIndexEventListener.java
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.searchablesnapshots; | ||
|
||
import org.apache.lucene.index.SegmentInfos; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.seqno.SequenceNumbers; | ||
import org.elasticsearch.index.shard.IndexEventListener; | ||
import org.elasticsearch.index.shard.IndexShard; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.index.translog.TranslogException; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.isSearchableSnapshotStore; | ||
|
||
public class SearchableSnapshotIndexEventListener implements IndexEventListener { | ||
|
||
@Override | ||
public void beforeIndexShardRecovery(IndexShard indexShard, IndexSettings indexSettings) { | ||
assert Thread.currentThread().getName().contains(ThreadPool.Names.GENERIC); | ||
associateNewEmptyTranslogWithIndex(indexShard); | ||
} | ||
|
||
private static void associateNewEmptyTranslogWithIndex(IndexShard indexShard) { | ||
final ShardId shardId = indexShard.shardId(); | ||
assert isSearchableSnapshotStore(indexShard.indexSettings().getSettings()) : "Expected a searchable snapshot shard " + shardId; | ||
try { | ||
final SegmentInfos segmentInfos = indexShard.store().readLastCommittedSegmentsInfo(); | ||
final long localCheckpoint = Long.parseLong(segmentInfos.userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)); | ||
final long primaryTerm = indexShard.getPendingPrimaryTerm(); | ||
final String translogUUID = segmentInfos.userData.get(Translog.TRANSLOG_UUID_KEY); | ||
final Path translogLocation = indexShard.shardPath().resolveTranslog(); | ||
Translog.createEmptyTranslog(translogLocation, shardId, localCheckpoint, primaryTerm, translogUUID, null); | ||
} catch (Exception e) { | ||
throw new TranslogException(shardId, "failed to associate a new translog", e); | ||
} | ||
} | ||
} |
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
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.
Suggest adding a big warning in a comment here saying how dangerous it is to specify the translog UUID and that it should only be used for shards that will see no indexing.
I'm also idly wondering about how hard it would be to make this
Translog
read-only when it's not been created with a fresh UUID. Probably too hard to be worth doing, but thought I'd mention it anyway.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.
Sure, I added some doc in 557d924
I find the idea interesting but I'm not sure if it worths it; I'd prefer to not create translogs at all if they were not to be used.