no need to log a failure when deleting an index and a shard is recovering

This commit is contained in:
Shay Banon 2011-09-27 13:21:20 +03:00
parent 8fd28320e4
commit f63727e3c6
2 changed files with 105 additions and 2 deletions

View File

@ -125,8 +125,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
private final boolean asyncLoadBloomFilter;
// no need for volatile, its always used under a lock
private IndexWriter indexWriter;
private volatile IndexWriter indexWriter;
private volatile AcquirableResource<ReaderSearcherHolder> nrtResource;
@ -238,6 +237,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
if (indexWriter != null) {
throw new EngineAlreadyStartedException(shardId);
}
if (closed) {
throw new EngineClosedException(shardId);
}
if (logger.isDebugEnabled()) {
logger.debug("Starting engine");
}
@ -1033,6 +1035,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
} catch (Exception e) {
--disableFlushCounter;
phase1Snapshot.release();
if (closed) {
e = new EngineClosedException(shardId, e);
}
throw new RecoveryEngineException(shardId, 1, "Execution failed", e);
}
@ -1042,6 +1047,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
} catch (Exception e) {
--disableFlushCounter;
phase1Snapshot.release();
if (closed) {
e = new EngineClosedException(shardId, e);
}
throw new RecoveryEngineException(shardId, 2, "Snapshot failed", e);
}
@ -1051,6 +1059,9 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
--disableFlushCounter;
phase1Snapshot.release();
phase2Snapshot.release();
if (closed) {
e = new EngineClosedException(shardId, e);
}
throw new RecoveryEngineException(shardId, 2, "Execution failed", e);
}

View File

@ -0,0 +1,92 @@
/*
* 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.test.stress.refresh;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import java.util.UUID;
/**
*/
public class RefreshStressTest1 {
public static void main(String[] args) throws InterruptedException {
Node node = NodeBuilder.nodeBuilder().local(true).loadConfigSettings(false).clusterName("testCluster").settings(
ImmutableSettings.settingsBuilder()
.put("node.name", "node1")
.put("gateway.type", "none")
//.put("path.data", new File("target/data").getAbsolutePath())
.build()).node();
Node node2 = NodeBuilder.nodeBuilder().local(true).loadConfigSettings(false).clusterName("testCluster").settings(
ImmutableSettings.settingsBuilder()
.put("node.name", "node2")
.put("gateway.type", "none")
//.put("path.data", new File("target/data").getAbsolutePath())
.build()).node();
Client client = node.client();
for (int loop = 1; loop < 1000; loop++) {
String indexName = "testindex" + loop;
String typeName = "testType" + loop;
String id = UUID.randomUUID().toString();
String mapping = "{ \"" + typeName + "\" : {\"dynamic_templates\" : [{\"no_analyze_strings\" : {\"match_mapping_type\" : \"string\",\"match\" : \"*\",\"mapping\" : {\"type\" : \"string\",\"index\" : \"not_analyzed\"}}}]}}";
client.admin().indices().prepareCreate(indexName).execute().actionGet();
client.admin().indices().preparePutMapping(indexName).setType(typeName).setSource(mapping).execute().actionGet();
// sleep after put mapping
// Thread.sleep(100);
System.out.println("indexing " + loop);
String name = "name" + id;
client.prepareIndex(indexName, typeName, id).setSource("{ \"id\": \"" + id + "\", \"name\": \"" + name + "\" }").execute().actionGet();
client.admin().indices().prepareRefresh(indexName).execute().actionGet();
// sleep after refresh
// Thread.sleep(100);
System.out.println("searching " + loop);
SearchResponse result = client.prepareSearch(indexName).setFilter(FilterBuilders.termFilter("name", name)).execute().actionGet();
if (result.getHits().hits().length != 1) {
for (int i = 1; i <= 100; i++) {
System.out.println("retry " + loop + ", " + i);
client.admin().indices().prepareRefresh(indexName).execute().actionGet();
Thread.sleep(100);
result = client.prepareSearch(indexName).setFilter(FilterBuilders.termFilter("name", name)).execute().actionGet();
if (result.getHits().hits().length == 1) {
throw new RuntimeException("Record found after " + (i * 100) + " ms");
} else if (i == 100) {
if (client.prepareGet(indexName, typeName, id).execute().actionGet().isExists())
throw new RuntimeException("Record wasn't found after 10s but can be get by id");
else throw new RuntimeException("Record wasn't found after 10s and can't be get by id");
}
}
}
client.admin().indices().prepareDelete(indexName).execute().actionGet();
}
client.close();
node2.close();
node.close();
}
}