From ae98d5989951af3763589501dcfcda432bb09f5a Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 13 Jul 2016 10:52:17 +0200 Subject: [PATCH] Don't assert that files exists if recovery has been cancled Today we assert that the tmp files are present but if the recovery was canceled this might not be the case while still a valid state. This chance only throws the AssertionError if the recovery is still active. --- .../indices/recovery/RecoveryTarget.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java index 4a091f53ed1..16cf36fcfa9 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryTarget.java @@ -394,10 +394,23 @@ public class RecoveryTarget extends AbstractRefCounted implements RecoveryTarget indexOutput.close(); } final String temporaryFileName = getTempNameForFile(name); - assert Arrays.asList(store.directory().listAll()).contains(temporaryFileName); + assert assertTempFileExists(temporaryFileName); store.directory().sync(Collections.singleton(temporaryFileName)); IndexOutput remove = removeOpenIndexOutputs(name); assert remove == null || remove == indexOutput; // remove maybe null if we got finished } } + + private boolean assertTempFileExists(String temporaryFileName) throws IOException { + try { + assert Arrays.asList(store.directory().listAll()).contains(temporaryFileName) : + "expected: [" + temporaryFileName + "] in " + Arrays.toString(store.directory().listAll()); + } catch (AssertionError error) { + if (finished.get() == false) { + // if we got canceled stuff might not be here anymore.. + throw error; + } + } + return true; + } }