From 39e546b64dbc2a5a8af2c17f04f93c3d8c3a4574 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 21 Jul 2010 01:51:58 +0300 Subject: [PATCH] add a proper master not discovered exception for master based operations (cluster state) and the ability to control the timeout till master is found --- .../cluster/state/ClusterStateRequest.java | 2 + .../indices/create/CreateIndexRequest.java | 2 + .../indices/delete/DeleteIndexRequest.java | 2 + .../master/MasterNodeOperationRequest.java | 17 +++++++++ .../TransportMasterNodeOperationAction.java | 37 +++++++++++++++++-- .../health/ClusterHealthRequestBuilder.java | 8 ++++ .../shutdown/NodesShutdownRequestBuilder.java | 9 +++++ .../alias/IndicesAliasesRequestBuilder.java | 9 +++++ .../create/CreateIndexRequestBuilder.java | 8 ++++ .../delete/DeleteIndexRequestBuilder.java | 9 +++++ .../mapping/put/PutMappingRequestBuilder.java | 8 ++++ .../MasterNotDiscoveredException.java | 32 ++++++++++++++++ 12 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java index 87295b4dcd3..4fed1f5fcce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java @@ -95,6 +95,7 @@ public class ClusterStateRequest extends MasterNodeOperationRequest { } @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); filterRoutingTable = in.readBoolean(); filterNodes = in.readBoolean(); filterMetaData = in.readBoolean(); @@ -109,6 +110,7 @@ public class ClusterStateRequest extends MasterNodeOperationRequest { } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeBoolean(filterRoutingTable); out.writeBoolean(filterNodes); out.writeBoolean(filterMetaData); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index bfc1156f978..5c481b43447 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -230,6 +230,7 @@ public class CreateIndexRequest extends MasterNodeOperationRequest { } @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); cause = in.readUTF(); index = in.readUTF(); settings = readSettingsFromStream(in); @@ -241,6 +242,7 @@ public class CreateIndexRequest extends MasterNodeOperationRequest { } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeUTF(cause); out.writeUTF(index); writeSettingsToStream(settings, out); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java index 2adeb6b19fa..2ac13422251 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java @@ -92,11 +92,13 @@ public class DeleteIndexRequest extends MasterNodeOperationRequest { } @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); index = in.readUTF(); timeout = readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeUTF(index); timeout.writeTo(out); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java index 930f0d6ff74..49b51b78cda 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.support.master; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.unit.TimeValue; import java.io.IOException; @@ -32,6 +33,8 @@ import java.io.IOException; */ public abstract class MasterNodeOperationRequest implements ActionRequest { + private TimeValue masterNodeTimeout = TimeValue.timeValueSeconds(30); + @Override public boolean listenerThreaded() { // always threaded return true; @@ -42,9 +45,23 @@ public abstract class MasterNodeOperationRequest implements ActionRequest { return this; } + /** + * A timeout value in case the master has not been discovered yet or disconnected. + */ + public MasterNodeOperationRequest masterNodeTimeout(TimeValue timeout) { + this.masterNodeTimeout = timeout; + return this; + } + + public TimeValue masterNodeTimeout() { + return this.masterNodeTimeout; + } + @Override public void readFrom(StreamInput in) throws IOException { + masterNodeTimeout = TimeValue.readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { + masterNodeTimeout.writeTo(out); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java index abbb96b94f5..318d4364961 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.support.master; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.BaseAction; @@ -31,6 +30,7 @@ import org.elasticsearch.cluster.TimeoutClusterStateListener; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.node.NodeCloseException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -94,7 +94,38 @@ public abstract class TransportMasterNodeOperationAction() { @@ -112,7 +143,7 @@ public abstract class TransportMasterNodeOperationAction listener) { client.nodesShutdown(request, listener); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/alias/IndicesAliasesRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/alias/IndicesAliasesRequestBuilder.java index 66b977255f7..0a3f5303968 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/alias/IndicesAliasesRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/alias/IndicesAliasesRequestBuilder.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.common.unit.TimeValue; /** * @author kimchy (shay.banon) @@ -56,6 +57,14 @@ public class IndicesAliasesRequestBuilder extends BaseIndicesRequestBuilder listener) { client.aliases(request, listener); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java index 18fe304cf5f..4035418923f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -130,6 +130,14 @@ public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { client.create(request, listener); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/delete/DeleteIndexRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/delete/DeleteIndexRequestBuilder.java index 82cab72cc31..f73d01ced45 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/delete/DeleteIndexRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/delete/DeleteIndexRequestBuilder.java @@ -53,6 +53,15 @@ public class DeleteIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { client.delete(request, listener); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 1ab34e172ca..f05ffa54bc6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -94,6 +94,14 @@ public class PutMappingRequestBuilder extends BaseIndicesRequestBuilder