From 271521286816ddebe9e36438c23227bfc428c718 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 21 Sep 2010 01:20:37 +0200 Subject: [PATCH] better handling of creation of index --- .../elasticsearch/indexer/twitter/TwitterIndexer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/indexer/twitter/src/main/java/org/elasticsearch/indexer/twitter/TwitterIndexer.java b/plugins/indexer/twitter/src/main/java/org/elasticsearch/indexer/twitter/TwitterIndexer.java index 7b1f31108d4..f05c3245104 100644 --- a/plugins/indexer/twitter/src/main/java/org/elasticsearch/indexer/twitter/TwitterIndexer.java +++ b/plugins/indexer/twitter/src/main/java/org/elasticsearch/indexer/twitter/TwitterIndexer.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.client.action.bulk.BulkRequestBuilder; +import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -98,15 +99,19 @@ public class TwitterIndexer extends AbstractIndexerComponent implements Indexer logger.info("starting twitter stream"); try { client.admin().indices().prepareCreate(indexName).execute().actionGet(); - currentRequest = client.prepareBulk(); - stream.sample(); } catch (Exception e) { if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { // that's fine + } else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) { + // ok, not recovered yet..., lets start indexing and hope we recover by the first bulk + // TODO: a smarter logic can be to register for cluster event listener here, and only start sampling when the block is removed... } else { logger.warn("failed to create index [{}], disabling indexer...", e, indexName); + return; } } + currentRequest = client.prepareBulk(); + stream.sample(); } @Override public void close() {