From 2a0e8d4ec9be8fc6ffe79dd8b03bbd04516364a7 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 21 Jul 2010 09:20:28 +0300 Subject: [PATCH] better state when closing shard, and handling its state --- ...licationShardOperationFailedException.java | 2 +- ...nsportShardReplicationOperationAction.java | 18 +++------ .../index/engine/EngineClosedException.java | 38 +++++++++++++++++++ .../index/engine/robin/RobinEngine.java | 24 ++++++++++-- 4 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/ReplicationShardOperationFailedException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/ReplicationShardOperationFailedException.java index 8271bfdcc2a..c4c2c953351 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/ReplicationShardOperationFailedException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/ReplicationShardOperationFailedException.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.shard.ShardId; /** * An exception indicating that a failure occurred performing an operation on the shard. * - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public class ReplicationShardOperationFailedException extends IndexShardException implements ElasticSearchWrapperException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index 37866f1f30a..e94f41fec0b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -42,7 +42,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.shard.IllegalIndexShardStateException; -import org.elasticsearch.index.shard.IndexShardNotStartedException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndexMissingException; @@ -295,8 +294,9 @@ public abstract class TransportShardReplicationOperationAction - *
  • IllegalIndexShardStateException: The shard has not yet moved to started mode (it is still recovering). - *
  • IndexMissingException/IndexShardMissingException: The shard has not yet started to initialize on the target node. - * + * Should an exception be ignored when the operation is performed on the replica. */ private boolean ignoreReplicaException(Throwable e) { Throwable cause = ExceptionsHelper.unwrapCause(e); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java new file mode 100644 index 00000000000..a47cbb6660e --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.engine; + +import org.elasticsearch.index.shard.IndexShardClosedException; +import org.elasticsearch.index.shard.ShardId; + +/** + * An engine is already closed. + * + *

    Note, the relationship between shard and engine indicates that engine closed is shard closed, and + * we might get something slipping through the the shard and into the engine while the shard is closing. + * + * @author kimchy (shay.banon) + */ +public class EngineClosedException extends IndexShardClosedException { + + public EngineClosedException(ShardId shardId) { + super(shardId); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index e75c67cf09d..d50018e477d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -182,7 +182,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine, @Override public void create(Create create) throws EngineException { rwl.readLock().lock(); try { - indexWriter.addDocument(create.doc(), create.analyzer()); + IndexWriter writer = this.indexWriter; + if (writer == null) { + throw new EngineClosedException(shardId); + } + writer.addDocument(create.doc(), create.analyzer()); translog.add(new Translog.Create(create)); dirty = true; } catch (IOException e) { @@ -195,7 +199,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine, @Override public void index(Index index) throws EngineException { rwl.readLock().lock(); try { - indexWriter.updateDocument(index.uid(), index.doc(), index.analyzer()); + IndexWriter writer = this.indexWriter; + if (writer == null) { + throw new EngineClosedException(shardId); + } + writer.updateDocument(index.uid(), index.doc(), index.analyzer()); translog.add(new Translog.Index(index)); dirty = true; } catch (IOException e) { @@ -208,7 +216,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine, @Override public void delete(Delete delete) throws EngineException { rwl.readLock().lock(); try { - indexWriter.deleteDocuments(delete.uid()); + IndexWriter writer = this.indexWriter; + if (writer == null) { + throw new EngineClosedException(shardId); + } + writer.deleteDocuments(delete.uid()); translog.add(new Translog.Delete(delete)); dirty = true; } catch (IOException e) { @@ -221,7 +233,11 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine, @Override public void delete(DeleteByQuery delete) throws EngineException { rwl.readLock().lock(); try { - indexWriter.deleteDocuments(delete.query()); + IndexWriter writer = this.indexWriter; + if (writer == null) { + throw new EngineClosedException(shardId); + } + writer.deleteDocuments(delete.query()); translog.add(new Translog.DeleteByQuery(delete)); dirty = true; } catch (IOException e) {