private static boolean hasCommits( Directory directory ) throws IOException { return DirectoryReader.indexExists( directory ) && SegmentInfos.readLatestCommit( directory ) != null; } }
/** * Check index version in given directory. It assumes that that all commits * in the Lucene segment file were done with the same version. * * @param dir directory with index * @thows IOException if the directory cannot be opened */ private static void checkDir(File dir) throws Exception { LockFactory lockfact = NativeFSLockFactory.INSTANCE; int segVersion; try (Directory indexDirectory = FSDirectory.open(dir.toPath(), lockfact)) { SegmentInfos segInfos = null; try { segInfos = SegmentInfos.readLatestCommit(indexDirectory); segVersion = segInfos.getIndexCreatedVersionMajor(); } catch (IndexNotFoundException e) { return; } } if (segVersion != Version.LATEST.major) { throw new IndexVersionException( String.format("Directory %s has index of version %d and Lucene has %d", dir.toString(), segVersion, Version.LATEST.major)); } } }
SegmentInfos latest = SegmentInfos.readLatestCommit(dir); final long currentGen = latest.getGeneration();
@Override public boolean isCurrent() throws IOException { ensureOpen(); if (writer == null || writer.isClosed()) { // Fully read the segments file: this ensures that it's // completely written so that if // IndexWriter.prepareCommit has been called (but not // yet commit), then the reader will still see itself as // current: SegmentInfos sis = SegmentInfos.readLatestCommit(directory); // we loaded SegmentInfos from the directory return sis.getVersion() == segmentInfos.getVersion(); } else { return writer.nrtIsCurrent(segmentInfos); } }
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }
infoStream.message("IW", "addIndexes: process directory " + dir); SegmentInfos sis = SegmentInfos.readLatestCommit(dir); // read infos from dir if (segmentInfos.getIndexCreatedVersionMajor() != sis.getIndexCreatedVersionMajor()) { throw new IllegalArgumentException("Cannot use addIndexes(Directory) with indexes that have been created "
private boolean assertSequenceNumbersInCommit() throws IOException { final Map<String, String> userData = SegmentInfos.readLatestCommit(store.directory()).getUserData(); assert userData.containsKey(SequenceNumbers.LOCAL_CHECKPOINT_KEY) : "commit point doesn't contains a local checkpoint"; assert userData.containsKey(SequenceNumbers.MAX_SEQ_NO) : "commit point doesn't contains a maximum sequence number"; assert userData.containsKey(Engine.HISTORY_UUID_KEY) : "commit point doesn't contains a history uuid"; assert userData.get(Engine.HISTORY_UUID_KEY).equals(getHistoryUUID()) : "commit point history uuid [" + userData.get(Engine.HISTORY_UUID_KEY) + "] is different than engine [" + getHistoryUUID() + "]"; return true; }
final SegmentInfos previous = SegmentInfos.readLatestCommit(directory); sis.updateGenerationVersionAndCounter(previous);
private boolean assertMaxUnsafeAutoIdInCommit() throws IOException { final Map<String, String> userData = SegmentInfos.readLatestCommit(store.directory()).getUserData(); if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_5_0)) { // as of 5.5.0, the engine stores the maxUnsafeAutoIdTimestamp in the commit point. // This should have baked into the commit by the primary we recover from, regardless of the index age. assert userData.containsKey(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID) : "opening index which was created post 5.5.0 but " + Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID + " is not found in commit"; } return true; }
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }
/** * Reads the segments infos, failing if it fails to load */ public static SegmentInfos readSegmentInfos(Directory directory) throws IOException { return SegmentInfos.readLatestCommit(directory); }
public IndexSplitter(Path dir) throws IOException { this.dir = dir; fsDir = FSDirectory.open(dir); infos = SegmentInfos.readLatestCommit(fsDir); }
public IndexSplitter(Path dir) throws IOException { this.dir = dir; fsDir = FSDirectory.open(dir); infos = SegmentInfos.readLatestCommit(fsDir); }
public IndexSplitter(Path dir) throws IOException { this.dir = dir; fsDir = FSDirectory.open(dir); infos = SegmentInfos.readLatestCommit(fsDir); }
/** Reads the commit data from a Directory. */ private static Map<String, String> readCommitData(Directory dir) throws IOException { SegmentInfos infos = SegmentInfos.readLatestCommit(dir); return infos.getUserData(); }
/** Reads the commit data from a Directory. */ private static Map<String, String> readCommitData(Directory dir) throws IOException { SegmentInfos infos = SegmentInfos.readLatestCommit(dir); return infos.getUserData(); }
private boolean assertSequenceNumbersInCommit() throws IOException { final Map<String, String> userData = SegmentInfos.readLatestCommit(store.directory()).getUserData(); assert userData.containsKey(SequenceNumbers.LOCAL_CHECKPOINT_KEY) : "commit point doesn't contains a local checkpoint"; assert userData.containsKey(SequenceNumbers.MAX_SEQ_NO) : "commit point doesn't contains a maximum sequence number"; assert userData.containsKey(Engine.HISTORY_UUID_KEY) : "commit point doesn't contains a history uuid"; assert userData.get(Engine.HISTORY_UUID_KEY).equals(getHistoryUUID()) : "commit point history uuid [" + userData.get(Engine.HISTORY_UUID_KEY) + "] is different than engine [" + getHistoryUUID() + "]"; return true; }
private boolean assertMaxUnsafeAutoIdInCommit() throws IOException { final Map<String, String> userData = SegmentInfos.readLatestCommit(store.directory()).getUserData(); if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_5_0)) { // as of 5.5.0, the engine stores the maxUnsafeAutoIdTimestamp in the commit point. // This should have baked into the commit by the primary we recover from, regardless of the index age. assert userData.containsKey(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID) : "opening index which was created post 5.5.0 but " + Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID + " is not found in commit"; } return true; }