From 50c771be290aa6ca07eff37bf4be79fa5aaeedbb Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 15 May 2015 08:31:54 +0200 Subject: [PATCH] [ENGINE] Signal when a new index is created also in Translog creation code Clarify when a new tranlog should be created by passing the same create flag to the IndexWriter as well as to the Translog creation --- .../elasticsearch/index/engine/InternalEngine.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index c68c3a114d1..50c8f7104a3 100644 --- a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -131,9 +131,10 @@ public class InternalEngine extends Engine { this.searcherFactory = new SearchFactory(engineConfig); final Translog.TranslogGeneration translogGeneration; try { - writer = createWriter(); + boolean create = !Lucene.indexExists(store.directory()); + writer = createWriter(create); indexWriter = writer; - translog = openTranslog(engineConfig, writer, skipInitialTranslogRecovery || engineConfig.forceNewTranslog()); + translog = openTranslog(engineConfig, writer, create || skipInitialTranslogRecovery || engineConfig.forceNewTranslog()); translogGeneration = translog.getGeneration(); assert translogGeneration != null; } catch (IOException | TranslogCorruptedException e) { @@ -183,8 +184,8 @@ public class InternalEngine extends Engine { } final Translog translog = new Translog(translogConfig); if (generation == null) { - if (createNew) { - throw new IllegalStateException("no tranlog generation present in commit data but tranlog is expected to exists"); + if (createNew == false) { + throw new IllegalStateException("no tranlog generation present in commit data but translog is expected to exist"); } logger.debug("no translog ID present in the current generation - creating one"); commitIndexWriter(writer, translog); @@ -986,9 +987,8 @@ public class InternalEngine extends Engine { } } - private IndexWriter createWriter() throws IOException { + private IndexWriter createWriter(boolean create) throws IOException { try { - boolean create = !Lucene.indexExists(store.directory()); final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer()); iwc.setCommitOnClose(false); // we by default don't commit on close iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);