Skip to content

Commit

Permalink
Unified default ack timeout to 30 seconds
Browse files Browse the repository at this point in the history
Increased also default publish state timeout to 30 seconds (from 5 seconds) and introduced constant for it.
Introduced AcknowledgedRequest.DEFAULT_ACK_TIMEOUT constant.
Removed misleading default values coming from the REST layer.
Removed (in a bw compatible manner) the timeout support in put/delete index template as the timeout parameter was ignored.

Closes elastic#4395
  • Loading branch information
javanna committed Dec 11, 2013
1 parent f9ff733 commit 037bf6a
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesArray;
Expand All @@ -41,7 +42,6 @@

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.action.ValidateActions.addValidationError;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class CreateIndexRequest extends MasterNodeOperationRequest<CreateIndexRe

private Map<String, IndexMetaData.Custom> customs = newHashMap();

private TimeValue timeout = new TimeValue(10, TimeUnit.SECONDS);
private TimeValue timeout = AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;

CreateIndexRequest() {
}
Expand Down Expand Up @@ -342,7 +342,7 @@ Map<String, IndexMetaData.Custom> customs() {
* Timeout to wait for the index creation to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
TimeValue timeout() {
public TimeValue timeout() {
return timeout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.action.admin.indices.delete;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand All @@ -29,7 +30,6 @@

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;

/**
* A request to delete an index. Best created with {@link org.elasticsearch.client.Requests#deleteIndexRequest(String)}.
Expand All @@ -38,7 +38,7 @@ public class DeleteIndexRequest extends MasterNodeOperationRequest<DeleteIndexRe

private String[] indices;

private TimeValue timeout = timeValueSeconds(60);
private TimeValue timeout = AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;

DeleteIndexRequest() {
}
Expand Down Expand Up @@ -79,7 +79,7 @@ String[] indices() {
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
TimeValue timeout() {
public TimeValue timeout() {
return timeout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

package org.elasticsearch.action.admin.indices.template.delete;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;

import java.io.IOException;

import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;

/**
* A request to delete an index template.
Expand All @@ -38,8 +38,6 @@ public class DeleteIndexTemplateRequest extends MasterNodeOperationRequest<Delet

private String name;

private TimeValue timeout = timeValueSeconds(10);

DeleteIndexTemplateRequest() {
}

Expand All @@ -66,42 +64,23 @@ String name() {
return name;
}

/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
TimeValue timeout() {
return timeout;
}

/**
* Timeout to wait for the index template deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteIndexTemplateRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
}

/**
* Timeout to wait for the index template deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteIndexTemplateRequest timeout(String timeout) {
return timeout(TimeValue.parseTimeValue(timeout, null));
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
timeout = readTimeValue(in);
//timeout was ignored till 0.90.7, removed afterwards
if (in.getVersion().onOrBefore(Version.V_0_90_7)) {
readTimeValue(in);
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
timeout.writeTo(out);
//timeout was ignored till 0.90.7, removed afterwards
if (out.getVersion().onOrBefore(Version.V_0_90_7)) {
AcknowledgedRequest.DEFAULT_ACK_TIMEOUT.writeTo(out);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
import org.elasticsearch.common.unit.TimeValue;

/**
*
Expand All @@ -38,24 +37,6 @@ public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, Strin
super((InternalIndicesAdminClient) indicesClient, new DeleteIndexTemplateRequest(name));
}

/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteIndexTemplateRequestBuilder setTimeout(TimeValue timeout) {
request.timeout(timeout);
return this;
}

/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public DeleteIndexTemplateRequestBuilder setTimeout(String timeout) {
request.timeout(timeout);
return this;
}

@Override
protected void doExecute(ActionListener<DeleteIndexTemplateResponse> listener) {
((IndicesAdminClient) client).deleteTemplate(request, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.elasticsearch.ElasticSearchGenerationException;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
Expand All @@ -31,15 +33,13 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.action.ValidateActions.addValidationError;
Expand Down Expand Up @@ -69,8 +69,6 @@ public class PutIndexTemplateRequest extends MasterNodeOperationRequest<PutIndex

private Map<String, IndexMetaData.Custom> customs = newHashMap();

private TimeValue timeout = new TimeValue(10, TimeUnit.SECONDS);

PutIndexTemplateRequest() {
}

Expand Down Expand Up @@ -342,31 +340,6 @@ Map<String, IndexMetaData.Custom> customs() {
return this.customs;
}

/**
* Timeout to wait till the put mapping gets acknowledged of all current cluster nodes. Defaults to
* <tt>10s</tt>.
*/
TimeValue timeout() {
return timeout;
}

/**
* Timeout to wait till the put mapping gets acknowledged of all current cluster nodes. Defaults to
* <tt>10s</tt>.
*/
public PutIndexTemplateRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
}

/**
* Timeout to wait till the put mapping gets acknowledged of all current cluster nodes. Defaults to
* <tt>10s</tt>.
*/
public PutIndexTemplateRequest timeout(String timeout) {
return timeout(TimeValue.parseTimeValue(timeout, null));
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
Expand All @@ -376,7 +349,10 @@ public void readFrom(StreamInput in) throws IOException {
order = in.readInt();
create = in.readBoolean();
settings = readSettingsFromStream(in);
timeout = readTimeValue(in);
//timeout was ignored till 0.90.7, removed afterwards
if (in.getVersion().onOrBefore(Version.V_0_90_7)) {
readTimeValue(in);
}
int size = in.readVInt();
for (int i = 0; i < size; i++) {
mappings.put(in.readString(), in.readString());
Expand All @@ -398,7 +374,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInt(order);
out.writeBoolean(create);
writeSettingsToStream(settings, out);
timeout.writeTo(out);
//timeout was ignored till 0.90.7, removed afterwards
if (out.getVersion().onOrBefore(Version.V_0_90_7)) {
AcknowledgedRequest.DEFAULT_ACK_TIMEOUT.writeTo(out);
}
out.writeVInt(mappings.size());
for (Map.Entry<String, String> entry : mappings.entrySet()) {
out.writeString(entry.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.util.Map;
Expand Down Expand Up @@ -189,24 +188,6 @@ public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, int offse
return this;
}

/**
* Timeout to wait for the index creation to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public PutIndexTemplateRequestBuilder setTimeout(TimeValue timeout) {
request.timeout(timeout);
return this;
}

/**
* Timeout to wait for the index creation to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.
*/
public PutIndexTemplateRequestBuilder setTimeout(String timeout) {
request.timeout(timeout);
return this;
}

@Override
protected void doExecute(ActionListener<PutIndexTemplateResponse> listener) {
((IndicesAdminClient) client).putTemplate(request, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
*/
public abstract class AcknowledgedRequest<T extends MasterNodeOperationRequest> extends MasterNodeOperationRequest<T> {

protected TimeValue timeout = timeValueSeconds(10);
public static final TimeValue DEFAULT_ACK_TIMEOUT = timeValueSeconds(30);

protected TimeValue timeout = DEFAULT_ACK_TIMEOUT;

protected AcknowledgedRequest() {
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/elasticsearch/discovery/Discovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.rest.RestStatus;

Expand All @@ -38,6 +39,8 @@ public interface Discovery extends LifecycleComponent<Discovery> {

final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", true, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);

public static final TimeValue DEFAULT_PUBLISH_TIMEOUT = TimeValue.timeValueSeconds(30);

DiscoveryNode localNode();

void addListener(InitialStateDiscoveryListener listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public LocalDiscovery(Settings settings, ClusterName clusterName, TransportServi
this.discoveryNodeService = discoveryNodeService;
this.version = version;

this.publishTimeout = settings.getAsTime("discovery.zen.publish_timeout", TimeValue.timeValueSeconds(5));
this.publishTimeout = settings.getAsTime("discovery.zen.publish_timeout", DEFAULT_PUBLISH_TIMEOUT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public PublishClusterStateAction(Settings settings, TransportService transportSe
this.nodesProvider = nodesProvider;
this.listener = listener;

this.publishTimeout = settings.getAsTime("discovery.zen.publish_timeout", TimeValue.timeValueSeconds(5));
this.publishTimeout = settings.getAsTime("discovery.zen.publish_timeout", Discovery.DEFAULT_PUBLISH_TIMEOUT);

transportService.registerHandler(PublishClusterStateRequestHandler.ACTION, new PublishClusterStateRequestHandler());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import java.io.IOException;

import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
import static org.elasticsearch.rest.RestStatus.OK;

Expand All @@ -50,7 +49,7 @@ public void handleRequest(final RestRequest request, final RestChannel channel)
final String index = request.param("index");
String alias = request.param("name");
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
indicesAliasesRequest.timeout(request.paramAsTime("timeout", timeValueSeconds(10)));
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
indicesAliasesRequest.removeAlias(index, alias);
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.io.IOException;
import java.util.Map;

import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.rest.RestStatus.OK;

Expand Down Expand Up @@ -107,7 +106,7 @@ public void handleRequest(final RestRequest request, final RestChannel channel)
}

IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
indicesAliasesRequest.timeout(request.paramAsTime("timeout", timeValueSeconds(10)));
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
AliasAction aliasAction = new AliasAction(AliasAction.Type.ADD, index, alias);
indicesAliasesRequest.addAliasAction(aliasAction);
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
Expand Down
Loading

0 comments on commit 037bf6a

Please sign in to comment.