From 3893417c44e36d0e1b59a87b0820b1ebe7846345 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 28 Apr 2012 00:37:35 +0300 Subject: [PATCH] index.shard.check_on_startup set to fix: throw failure only if we are not fixing the index --- .../index/shard/service/InternalIndexShard.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index f2036e7fd2f..02a23cd8017 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -30,6 +30,7 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.Booleans; import org.elasticsearch.common.BytesHolder; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -113,7 +114,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I private final Object mutex = new Object(); private final String checkIndexOnStartup; - + private long checkIndexTook = 0; private volatile IndexShardState state; @@ -265,7 +266,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I if (state == IndexShardState.RELOCATED) { throw new IndexShardRelocatedException(shardId); } - if (!"false".equalsIgnoreCase(checkIndexOnStartup)) { + if (Booleans.parseBoolean(checkIndexOnStartup, false)) { checkIndex(true); } engine.start(); @@ -569,7 +570,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I throw new IndexShardNotRecoveringException(shardId, state); } // also check here, before we apply the translog - if (!"false".equalsIgnoreCase(checkIndexOnStartup)) { + if (Booleans.parseBoolean(checkIndexOnStartup, false)) { checkIndex(true); } // we disable deletes since we allow for operations to be executed against the shard while recovering @@ -858,9 +859,6 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I return; } logger.warn("check index [failure]\n{}", new String(os.underlyingBytes(), 0, os.size())); - if (throwException) { - throw new IndexShardException(shardId, "index check failure"); - } if ("fix".equalsIgnoreCase(checkIndexOnStartup)) { if (logger.isDebugEnabled()) { logger.debug("fixing index, writing new segments file ..."); @@ -869,6 +867,11 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I if (logger.isDebugEnabled()) { logger.debug("index fixed, wrote new segments file \"{}\"", status.segmentsFileName); } + } else { + // only throw a failure if we are not going to fix the index + if (throwException) { + throw new IndexShardException(shardId, "index check failure"); + } } } else { if (logger.isDebugEnabled()) {