|
51 | 51 | import java.io.EOFException;
|
52 | 52 | import java.io.File;
|
53 | 53 | import java.io.IOException;
|
| 54 | +import java.nio.file.Files; |
54 | 55 | import java.util.Arrays;
|
55 | 56 | import java.util.Set;
|
56 | 57 | import java.util.concurrent.CountDownLatch;
|
@@ -204,12 +205,30 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
|
204 | 205 | if (!tmpRecoveringFile.exists()) {
|
205 | 206 | File tmpTranslogFile = new File(translogLocation, translogName);
|
206 | 207 | if (tmpTranslogFile.exists()) {
|
| 208 | + logger.trace("Translog file found in {} - renaming", translogLocation); |
| 209 | + boolean success = false; |
207 | 210 | for (int i = 0; i < RECOVERY_TRANSLOG_RENAME_RETRIES; i++) {
|
208 | 211 | if (tmpTranslogFile.renameTo(tmpRecoveringFile)) {
|
| 212 | + |
209 | 213 | recoveringTranslogFile = tmpRecoveringFile;
|
| 214 | + logger.trace("Renamed translog from {} to {}", tmpTranslogFile.getName(), recoveringTranslogFile.getName()); |
| 215 | + success = true; |
210 | 216 | break;
|
211 | 217 | }
|
212 | 218 | }
|
| 219 | + if (success == false) { |
| 220 | + try { |
| 221 | + // this is a fallback logic that to ensure we can recover from the file. |
| 222 | + // on windows a virus-scanner etc can hold on to the file and after retrying |
| 223 | + // we just skip the recovery and the engine will reuse the file and truncate it. |
| 224 | + // in 2.0 this is all not needed since translog files are write once. |
| 225 | + Files.copy(tmpTranslogFile.toPath(), tmpRecoveringFile.toPath()); |
| 226 | + recoveringTranslogFile = tmpRecoveringFile; |
| 227 | + logger.trace("Copied translog from {} to {}", tmpTranslogFile.getName(), recoveringTranslogFile.getName()); |
| 228 | + } catch (IOException ex) { |
| 229 | + throw new ElasticsearchException("failed to copy recovery file", ex); |
| 230 | + } |
| 231 | + } |
213 | 232 | }
|
214 | 233 | } else {
|
215 | 234 | recoveringTranslogFile = tmpRecoveringFile;
|
|
0 commit comments