-
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
[Draft] Improve usage of blob store cache during searchable snapshots shard recovery #69283
Closed
Closed
Changes from all commits
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
92 changes: 92 additions & 0 deletions
92
...s/src/internalClusterTest/java/org/apache/lucene/codecs/lucene50/CompoundReaderUtils.java
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.apache.lucene.codecs.lucene50; | ||
|
||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.CodecUtil; | ||
import org.apache.lucene.codecs.CompoundDirectory; | ||
import org.apache.lucene.index.CorruptIndexException; | ||
import org.apache.lucene.index.IndexFileNames; | ||
import org.apache.lucene.index.SegmentCommitInfo; | ||
import org.apache.lucene.index.SegmentInfo; | ||
import org.apache.lucene.index.SegmentInfos; | ||
import org.apache.lucene.store.ChecksumIndexInput; | ||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.IOContext; | ||
import org.elasticsearch.common.collect.Tuple; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class CompoundReaderUtils { | ||
|
||
private CompoundReaderUtils() {} | ||
|
||
public static Map<String, Map<String, Tuple<Long, Long>>> extractCompoundFiles(Directory directory) throws IOException { | ||
final Map<String, Map<String, Tuple<Long, Long>>> compoundFiles = new HashMap<>(); | ||
final SegmentInfos segmentInfos = SegmentInfos.readLatestCommit(directory); | ||
for (SegmentCommitInfo segmentCommitInfo : segmentInfos) { | ||
final SegmentInfo segmentInfo = segmentCommitInfo.info; | ||
if (segmentInfo.getUseCompoundFile()) { | ||
final Codec codec = segmentInfo.getCodec(); | ||
try (CompoundDirectory compoundDir = codec.compoundFormat().getCompoundReader(directory, segmentInfo, IOContext.DEFAULT)) { | ||
String className = compoundDir.getClass().getName(); | ||
switch (className) { | ||
case "org.apache.lucene.codecs.lucene50.Lucene50CompoundReader": | ||
compoundFiles.put(segmentInfo.name, readEntries(directory, segmentCommitInfo.info)); | ||
break; | ||
default: | ||
assert false : "please implement readEntries() for this format of compound files: " + className; | ||
throw new IllegalStateException("This format of compound files is not supported: " + className); | ||
} | ||
} | ||
} | ||
} | ||
return Collections.unmodifiableMap(compoundFiles); | ||
} | ||
|
||
private static Map<String, Tuple<Long, Long>> readEntries(Directory directory, SegmentInfo segmentInfo) throws IOException { | ||
final String entriesFileName = IndexFileNames.segmentFileName(segmentInfo.name, "", Lucene50CompoundFormat.ENTRIES_EXTENSION); | ||
try (ChecksumIndexInput entriesStream = directory.openChecksumInput(entriesFileName, IOContext.READONCE)) { | ||
Map<String, Tuple<Long, Long>> mapping = new HashMap<>(); | ||
Throwable trowable = null; | ||
try { | ||
CodecUtil.checkIndexHeader( | ||
entriesStream, | ||
Lucene50CompoundFormat.ENTRY_CODEC, | ||
Lucene50CompoundFormat.VERSION_START, | ||
Lucene50CompoundFormat.VERSION_CURRENT, | ||
segmentInfo.getId(), | ||
"" | ||
); | ||
|
||
final int numEntries = entriesStream.readVInt(); | ||
final Set<String> seen = new HashSet<>(numEntries); | ||
for (int i = 0; i < numEntries; i++) { | ||
final String id = entriesStream.readString(); | ||
if (seen.add(id) == false) { | ||
throw new CorruptIndexException("Duplicate cfs entry id=" + id + " in CFS ", entriesStream); | ||
} | ||
long offset = entriesStream.readLong(); | ||
long length = entriesStream.readLong(); | ||
mapping.put(id, Tuple.tuple(offset, length)); | ||
} | ||
assert mapping.size() == numEntries; | ||
} catch (Throwable exception) { | ||
trowable = exception; | ||
} finally { | ||
CodecUtil.checkFooter(entriesStream, trowable); | ||
} | ||
return Collections.unmodifiableMap(mapping); | ||
} | ||
} | ||
} |
235 changes: 152 additions & 83 deletions
235
...t/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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.
I'm really sorry but I did not find any better way to extract the list of files that composed the CFS. Reading only the .cfe is possible but that won't give the inner offsets (only the lengths) and I think it is better to check the right boundaries.