[STORE] Ignore segments.gen on metadata snapshots
The segments.gen file is optional and might even change while we read it. It's safer to just ignore that file in the snapshot instead.
This commit is contained in:
parent
4af1a29057
commit
4d3f761d3d
|
@ -448,7 +448,10 @@ public class Store extends AbstractIndexShardComponent implements CloseableIndex
|
|||
* Represents a snaphshot of the current directory build from the latest Lucene commit.
|
||||
* Only files that are part of the last commit are considered in this datastrucutre.
|
||||
* For backwards compatibility the snapshot might include legacy checksums that
|
||||
* are derived from a dedicated checksum file written by older elastcisearch version pre 1.3
|
||||
* are derived from a dedicated checksum file written by older elasticsearch version pre 1.3
|
||||
*
|
||||
* Note: This class will ignore the <tt>segments.gen</tt> file since it's optional and might
|
||||
* change concurrently for safety reasons.
|
||||
*
|
||||
* @see StoreFileMetaData
|
||||
*/
|
||||
|
@ -490,23 +493,12 @@ public class Store extends AbstractIndexShardComponent implements CloseableIndex
|
|||
}
|
||||
}
|
||||
}
|
||||
for (String file : Arrays.asList(segmentCommitInfos.getSegmentsFileName(), IndexFileNames.SEGMENTS_GEN)) {
|
||||
if (!added.contains(file)) {
|
||||
try {
|
||||
String legacyChecksum = checksumMap.get(file);
|
||||
final String segmentsFile = segmentCommitInfos.getSegmentsFileName();
|
||||
String legacyChecksum = checksumMap.get(segmentsFile);
|
||||
if (maxVersion.onOrAfter(Version.LUCENE_4_8) && legacyChecksum == null) {
|
||||
checksumFromLuceneFile(directory, file, builder, logger, maxVersion);
|
||||
checksumFromLuceneFile(directory, segmentsFile, builder, logger, maxVersion);
|
||||
} else {
|
||||
builder.put(file, new StoreFileMetaData(file, directory.fileLength(file), legacyChecksum, null));
|
||||
}
|
||||
added.add(file);
|
||||
} catch (FileNotFoundException | NoSuchFileException ex) {
|
||||
if (IndexFileNames.SEGMENTS_GEN.equals(file) == false) {
|
||||
// segments.gen is optional
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.put(segmentsFile, new StoreFileMetaData(segmentsFile, directory.fileLength(segmentsFile), legacyChecksum, null));
|
||||
}
|
||||
} catch (CorruptIndexException ex) {
|
||||
throw ex;
|
||||
|
|
|
@ -24,10 +24,7 @@ import org.apache.lucene.document.Document;
|
|||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.SortedDocValuesField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.*;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
@ -147,7 +144,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase {
|
|||
Store.LegacyChecksums checksums = new Store.LegacyChecksums();
|
||||
Map<String, StoreFileMetaData> legacyMeta = new HashMap<>();
|
||||
for (String file : store.directory().listAll()) {
|
||||
if (file.equals("write.lock")) {
|
||||
if (file.equals("write.lock") || file.equals(IndexFileNames.SEGMENTS_GEN)) {
|
||||
continue;
|
||||
}
|
||||
try (IndexInput input = store.directory().openInput(file, IOContext.READONCE)) {
|
||||
|
@ -494,7 +491,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase {
|
|||
|
||||
public static void assertConsistent(Store store, Store.MetadataSnapshot metadata) throws IOException {
|
||||
for (String file : store.directory().listAll()) {
|
||||
if (!"write.lock".equals(file) && !Store.isChecksum(file)) {
|
||||
if (!"write.lock".equals(file) && !IndexFileNames.SEGMENTS_GEN.equals(file) && !Store.isChecksum(file)) {
|
||||
assertTrue(file + " is not in the map: " + metadata.asMap().size() + " vs. " + store.directory().listAll().length, metadata.asMap().containsKey(file));
|
||||
} else {
|
||||
assertFalse(file + " is not in the map: " + metadata.asMap().size() + " vs. " + store.directory().listAll().length, metadata.asMap().containsKey(file));
|
||||
|
|
Loading…
Reference in New Issue