diff --git a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index 449ac47798d..311b55c1682 100644 --- a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -23,6 +23,9 @@ import com.google.common.collect.Lists; import org.apache.lucene.index.*; import org.apache.lucene.search.*; import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -245,8 +248,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { try { // commit on a just opened writer will commit even if there are no changes done to it // we rely on that for the commit data translog id key - if (IndexReader.indexExists(store.directory())) { - Map commitUserData = IndexReader.getCommitUserData(store.directory()); + if (DirectoryReader.indexExists(store.directory())) { + Map commitUserData = getCommitUserData(store.directory()); if (commitUserData.containsKey(Translog.TRANSLOG_ID_KEY)) { translogIdGenerator.set(Long.parseLong(commitUserData.get(Translog.TRANSLOG_ID_KEY))); } else { @@ -861,7 +864,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { indexWriter.commit(MapBuilder.newMapBuilder().put(Translog.TRANSLOG_ID_KEY, Long.toString(translogId)).map()); if (flush.force()) { // if we force, we might not have committed, we need to check that its the same id - Map commitUserData = IndexReader.getCommitUserData(store.directory()); + Map commitUserData = getCommitUserData(store.directory()); long committedTranslogId = Long.parseLong(commitUserData.get(Translog.TRANSLOG_ID_KEY)); if (committedTranslogId != translogId) { // we did not commit anything, revert to the old translog @@ -1325,7 +1328,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { logger.warn("shard is locked, releasing lock"); IndexWriter.unlock(store.directory()); } - boolean create = !IndexReader.indexExists(store.directory()); + boolean create = !DirectoryReader.indexExists(store.directory()); IndexWriterConfig config = new IndexWriterConfig(Lucene.VERSION, analysisService.defaultIndexAnalyzer()); config.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND); config.setIndexDeletionPolicy(deletionPolicy); @@ -1531,4 +1534,13 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { return searcher; } } + + /** + * Reads the latest commit and loads the userdata + */ + private static final Map getCommitUserData(final Directory directory) throws IOException { + final SegmentInfos sis = new SegmentInfos(); + sis.read(directory); + return sis.getUserData(); + } }