Recovery: RecoveryTarget does not fsync the right file name.

Close #9144
This commit is contained in:
Adrien Grand 2015-01-05 19:13:32 +01:00
parent 90f98579a2
commit cd04851206
2 changed files with 6 additions and 15 deletions

View File

@ -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 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) { public IndexOutput getOpenIndexOutput(String key) {
ensureRefCount(); ensureRefCount();
return openIndexOutputs.get(key); 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 */ /** 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) { public IndexOutput removeOpenIndexOutputs(String name) {
ensureRefCount(); ensureRefCount();

View File

@ -46,6 +46,7 @@ import org.elasticsearch.indices.IndicesLifecycle;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*; import org.elasticsearch.transport.*;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -440,7 +441,9 @@ public class RecoveryTarget extends AbstractComponent {
} }
// write the checksum // write the checksum
recoveryStatus.legacyChecksums().add(request.metadata()); 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()); IndexOutput remove = recoveryStatus.removeOpenIndexOutputs(request.name());
recoveryStatus.state().getIndex().addRecoveredFileCount(1); recoveryStatus.state().getIndex().addRecoveredFileCount(1);
assert remove == null || remove == indexOutput; // remove maybe null if we got finished assert remove == null || remove == indexOutput; // remove maybe null if we got finished