diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryStatus.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryStatus.java index b4d93b5716c..aaf2f7cda1a 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryStatus.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryStatus.java @@ -186,28 +186,16 @@ public class RecoveryStatus extends AbstractRefCounted { } } - private String getTempNameForFile(String origFile) { + /** Get a temporary name for the provided file name. */ + public String getTempNameForFile(String origFile) { return tempFilePrefix + origFile; } - /** return true if the give file is a temporary file name issued by this recovery */ - private boolean isTempFile(String filename) { - return tempFileNames.containsKey(filename); - } - public IndexOutput getOpenIndexOutput(String key) { ensureRefCount(); return openIndexOutputs.get(key); } - /** returns the original file name for a temporary file name issued by this recovery */ - private String originalNameForTempFile(String tempFile) { - if (!isTempFile(tempFile)) { - throw new ElasticsearchException("[" + tempFile + "] is not a temporary file made by this recovery"); - } - return tempFile.substring(tempFilePrefix.length()); - } - /** remove and {@link org.apache.lucene.store.IndexOutput} for a given file. It is the caller's responsibility to close it */ public IndexOutput removeOpenIndexOutputs(String name) { ensureRefCount(); diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java index 4053d6c29c9..e1e7fba6a04 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java @@ -46,6 +46,7 @@ import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -440,7 +441,9 @@ public class RecoveryTarget extends AbstractComponent { } // write the checksum recoveryStatus.legacyChecksums().add(request.metadata()); - store.directory().sync(Collections.singleton(request.name())); + final String temporaryFileName = recoveryStatus.getTempNameForFile(request.name()); + assert Arrays.asList(store.directory().listAll()).contains(temporaryFileName); + store.directory().sync(Collections.singleton(temporaryFileName)); IndexOutput remove = recoveryStatus.removeOpenIndexOutputs(request.name()); recoveryStatus.state().getIndex().addRecoveredFileCount(1); assert remove == null || remove == indexOutput; // remove maybe null if we got finished