diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCache.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCache.java index affe69ac12663..bf9520623cb2e 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCache.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCache.java @@ -56,10 +56,12 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; @@ -212,9 +214,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { void commit() throws IOException { ensureOpen(); try { - for (CacheIndexWriter writer : writers) { - writer.prepareCommit(); - } for (CacheIndexWriter writer : writers) { writer.commit(); } @@ -457,16 +456,14 @@ void deleteCacheFile(String cacheFileId) throws IOException { indexWriter.deleteDocuments(term); } - void prepareCommit() throws IOException { - logger.debug("preparing commit"); - final Map commitData = new HashMap<>(1); - commitData.put(NODE_VERSION_COMMIT_KEY, Integer.toString(Version.CURRENT.id)); - indexWriter.setLiveCommitData(commitData.entrySet()); - indexWriter.prepareCommit(); - } + private static final Set> LUCENE_COMMIT_DATA = Collections.singletonMap( + NODE_VERSION_COMMIT_KEY, + Integer.toString(Version.CURRENT.id) + ).entrySet(); void commit() throws IOException { logger.debug("committing"); + indexWriter.setLiveCommitData(LUCENE_COMMIT_DATA); indexWriter.commit(); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCacheTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCacheTests.java index 1c8a12685f6f6..454149ec3851c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCacheTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/PersistentCacheTests.java @@ -119,11 +119,8 @@ public void testCacheIndexWriter() throws Exception { boolean commit = false; if (frequently()) { - writer.prepareCommit(); - if (frequently()) { - writer.commit(); - commit = true; - } + writer.commit(); + commit = true; } if (commit) {