From 79af3228ad41ac1f2e246b33bb22854b21f6cab8 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 26 Jun 2014 14:16:24 +0200 Subject: [PATCH] Thread pool rejection status code should be 429 Thread rejection should return too many requests status code, and not 503, which is used to also show that the cluster is not available relates to #6627, but only for rejections for now closes #6629 --- .../util/concurrent/EsRejectedExecutionException.java | 2 +- .../java/org/elasticsearch/http/netty/NettyHttpChannel.java | 4 ++++ src/main/java/org/elasticsearch/rest/RestStatus.java | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java b/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java index d5be2dc3253..7c5e7812089 100644 --- a/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java @@ -40,6 +40,6 @@ public class EsRejectedExecutionException extends ElasticsearchException { @Override public RestStatus status() { - return RestStatus.SERVICE_UNAVAILABLE; + return RestStatus.TOO_MANY_REQUESTS; } } diff --git a/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java b/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java index 13f7aa3bc1e..26dc8c6629c 100644 --- a/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java +++ b/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java @@ -185,6 +185,8 @@ public class NettyHttpChannel extends HttpChannel { } } + private static final HttpResponseStatus TOO_MANY_REQUESTS = new HttpResponseStatus(429, "Too Many Requests"); + private HttpResponseStatus getStatus(RestStatus status) { switch (status) { case CONTINUE: @@ -264,6 +266,8 @@ public class NettyHttpChannel extends HttpChannel { return HttpResponseStatus.BAD_REQUEST; case FAILED_DEPENDENCY: return HttpResponseStatus.BAD_REQUEST; + case TOO_MANY_REQUESTS: + return TOO_MANY_REQUESTS; case INTERNAL_SERVER_ERROR: return HttpResponseStatus.INTERNAL_SERVER_ERROR; case NOT_IMPLEMENTED: diff --git a/src/main/java/org/elasticsearch/rest/RestStatus.java b/src/main/java/org/elasticsearch/rest/RestStatus.java index e5a66637ed0..5b1c1ef9ed2 100644 --- a/src/main/java/org/elasticsearch/rest/RestStatus.java +++ b/src/main/java/org/elasticsearch/rest/RestStatus.java @@ -428,6 +428,10 @@ public enum RestStatus { * PROPPATCH method fails, then, at minimum, the rest of the commands will also fail with 424 (Failed Dependency). */ FAILED_DEPENDENCY(424), + /** + * 429 Too Many Requests (RFC6585) + */ + TOO_MANY_REQUESTS(429), /** * The server encountered an unexpected condition which prevented it from fulfilling the request. */ @@ -490,4 +494,4 @@ public enum RestStatus { public static void writeTo(StreamOutput out, RestStatus status) throws IOException { out.writeString(status.name()); } -} \ No newline at end of file +}