From 50907d5b7d5b94a7c57b430921fae23935430744 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 8 Oct 2015 14:22:21 +0200 Subject: [PATCH] apply review comments --- .../metadata/MetaDataIndexUpgradeService.java | 6 +---- .../index/engine/InternalEngine.java | 25 +++++++++---------- .../ExceptionSerializationTests.java | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index f0d1db9bf99..44b65c7f8c9 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -166,7 +166,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { /** * Elasticsearch 3.0 no longer supports indices with pre Lucene v5.0 (Elasticsearch v2.0.0.beta1) segments. All indices - * that were created before Elasticsearch v2.0.0.beta1 should be upgraded using upgrade plugin before they can + * that were created before Elasticsearch v2.0.0.beta1 should be upgraded using upgrade API before they can * be open by this version of elasticsearch. */ private void checkSupportedVersion(IndexMetaData indexMetaData) { @@ -185,10 +185,6 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { // The index was created with elasticsearch that was using Lucene 5.2.1 return true; } - if (indexMetaData.getUpgradeVersion().onOrAfter(Version.V_2_0_0_beta1) == false) { - // early terminate if we are not upgrade - we don't even need to look at the segment version - return false; - } if (indexMetaData.getMinimumCompatibleVersion() != null && indexMetaData.getMinimumCompatibleVersion().onOrAfter(org.apache.lucene.util.Version.LUCENE_5_0_0)) { //The index was upgraded we can work with it diff --git a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 245ee7a0a23..9177e3b435b 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -172,21 +172,12 @@ public class InternalEngine extends Engine { } private Translog openTranslog(EngineConfig engineConfig, IndexWriter writer, boolean createNew) throws IOException { - final Translog.TranslogGeneration generation = loadTranslogIdFromCommit(writer); + final Translog.TranslogGeneration generation = loadTranslogIdFromCommit(writer, createNew); final TranslogConfig translogConfig = engineConfig.getTranslogConfig(); - - if (createNew == false) { - // We expect that this shard already exists, so it must already have an existing translog else something is badly wrong! - if (generation == null) { - throw new IllegalStateException("no translog generation present in commit data but translog is expected to exist"); - } - translogConfig.setTranslogGeneration(generation); - if (generation != null && generation.translogUUID == null) { - throw new IndexFormatTooOldException("trasnlog", "translog has no generation nor a UUID - this might be an index from a previous version consider upgrading to N-1 first"); - } - } + translogConfig.setTranslogGeneration(generation); final Translog translog = new Translog(translogConfig); if (generation == null || generation.translogUUID == null) { + assert createNew; if (generation == null) { logger.debug("no translog ID present in the current generation - creating one"); } else if (generation.translogUUID == null) { @@ -249,7 +240,7 @@ public class InternalEngine extends Engine { * translog id into lucene and returns null. */ @Nullable - private Translog.TranslogGeneration loadTranslogIdFromCommit(IndexWriter writer) throws IOException { + private Translog.TranslogGeneration loadTranslogIdFromCommit(IndexWriter writer, boolean createNew) throws IOException { // commit on a just opened writer will commit even if there are no changes done to it // we rely on that for the commit data translog id key final Map commitUserData = writer.getCommitData(); @@ -262,8 +253,16 @@ public class InternalEngine extends Engine { } final String translogUUID = commitUserData.get(Translog.TRANSLOG_UUID_KEY); final long translogGen = Long.parseLong(commitUserData.get(Translog.TRANSLOG_GENERATION_KEY)); + if (createNew == false && translogUUID == null) { + throw new IndexFormatTooOldException("translog", "translog has no generation nor a UUID - this might be an index from a previous version consider upgrading to N-1 first"); + } return new Translog.TranslogGeneration(translogUUID, translogGen); } + + if (createNew == false) { + // We expect that this shard already exists, so it must already have an existing translog else something is badly wrong! + throw new IllegalStateException("no translog generation present in commit data but translog is expected to exist"); + } return null; } diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 9297c6b2d86..55dc2e42113 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -705,7 +705,7 @@ public class ExceptionSerializationTests extends ESTestCase { ids.put(61, org.elasticsearch.cluster.routing.RoutingValidationException.class); ids.put(62, org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper.class); ids.put(63, org.elasticsearch.indices.AliasFilterParsingException.class); - ids.put(64, org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class); + ids.put(64, null); // DeleteByQueryFailedEngineException was removed in 3.0 ids.put(65, org.elasticsearch.gateway.GatewayException.class); ids.put(66, org.elasticsearch.index.shard.IndexShardNotRecoveringException.class); ids.put(67, org.elasticsearch.http.HttpException.class);