Skip to content

Commit 2bb31fe

Browse files
committed
reafactor how actions handle failures, better response when non active shards exists, also, default logging to have action set to DEBUG so exceptions in actions are logged in the server
1 parent 1a9c5d6 commit 2bb31fe

File tree

42 files changed

+628
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+628
-239
lines changed

config/logging.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rootLogger: INFO, console, file
22
logger:
33
jgroups: WARN
4+
# log action execution errors for easier debugging
5+
action : DEBUG
46

57
appender:
68
console:

modules/elasticsearch/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
*/
2828
public class NoShardAvailableActionException extends IndexShardException {
2929

30+
public NoShardAvailableActionException(ShardId shardId, String msg) {
31+
super(shardId, msg);
32+
}
33+
3034
public NoShardAvailableActionException(ShardId shardId, String msg, Throwable cause) {
3135
super(shardId, msg, cause);
3236
}

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/BroadcastPingResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class BroadcastPingResponse extends BroadcastOperationResponse {
3636

3737
}
3838

39-
public BroadcastPingResponse(int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
40-
super(successfulShards, failedShards, shardFailures);
39+
public BroadcastPingResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
40+
super(totalShards, successfulShards, failedShards, shardFailures);
4141
}
4242

4343
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/TransportBroadcastPingAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class TransportBroadcastPingAction extends TransportBroadcastOperationAct
8383
successfulShards++;
8484
}
8585
}
86-
return new BroadcastPingResponse(successfulShards, failedShards, shardFailures);
86+
return new BroadcastPingResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
8787
}
8888

8989
@Override protected BroadcastShardPingRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/ShardReplicationPingRequest.java

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ public int shardId() {
5858
super.writeTo(out);
5959
out.writeVInt(shardId);
6060
}
61+
62+
@Override public String toString() {
63+
return "[" + index + "][" + shardId + "]";
64+
}
6165
}

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class ClearIndicesCacheResponse extends BroadcastOperationResponse {
3838

3939
}
4040

41-
ClearIndicesCacheResponse(int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42-
super(successfulShards, failedShards, shardFailures);
41+
ClearIndicesCacheResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42+
super(totalShards, successfulShards, failedShards, shardFailures);
4343
}
4444

4545
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
6666
return new ClearIndicesCacheRequest();
6767
}
6868

69+
@Override protected boolean ignoreNonActiveExceptions() {
70+
return true;
71+
}
72+
6973
@Override protected ClearIndicesCacheResponse newResponse(ClearIndicesCacheRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
7074
int successfulShards = 0;
7175
int failedShards = 0;
7276
List<ShardOperationFailedException> shardFailures = null;
7377
for (int i = 0; i < shardsResponses.length(); i++) {
7478
Object shardResponse = shardsResponses.get(i);
7579
if (shardResponse == null) {
76-
failedShards++;
80+
// simply ignore non active shards
7781
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
7882
failedShards++;
7983
if (shardFailures == null) {
@@ -84,7 +88,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
8488
successfulShards++;
8589
}
8690
}
87-
return new ClearIndicesCacheResponse(successfulShards, failedShards, shardFailures);
91+
return new ClearIndicesCacheResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
8892
}
8993

9094
@Override protected ShardClearIndicesCacheRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class FlushResponse extends BroadcastOperationResponse {
3838

3939
}
4040

41-
FlushResponse(int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42-
super(successfulShards, failedShards, shardFailures);
41+
FlushResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42+
super(totalShards, successfulShards, failedShards, shardFailures);
4343
}
4444

4545
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ public class TransportFlushAction extends TransportBroadcastOperationAction<Flus
6565
return new FlushRequest();
6666
}
6767

68+
@Override protected boolean ignoreNonActiveExceptions() {
69+
return true;
70+
}
71+
6872
@Override protected FlushResponse newResponse(FlushRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
6973
int successfulShards = 0;
7074
int failedShards = 0;
7175
List<ShardOperationFailedException> shardFailures = null;
7276
for (int i = 0; i < shardsResponses.length(); i++) {
7377
Object shardResponse = shardsResponses.get(i);
7478
if (shardResponse == null) {
75-
failedShards++;
79+
// a non active shard, ignore
7680
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
7781
failedShards++;
7882
if (shardFailures == null) {
@@ -83,7 +87,7 @@ public class TransportFlushAction extends TransportBroadcastOperationAction<Flus
8387
successfulShards++;
8488
}
8589
}
86-
return new FlushResponse(successfulShards, failedShards, shardFailures);
90+
return new FlushResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
8791
}
8892

8993
@Override protected ShardFlushRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/ShardGatewaySnapshotRequest.java

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ public int shardId() {
5858
super.writeTo(out);
5959
out.writeVInt(shardId);
6060
}
61+
62+
@Override public String toString() {
63+
return "[" + index + "][" + shardId + "]";
64+
}
6165
}

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class OptimizeResponse extends BroadcastOperationResponse {
3838

3939
}
4040

41-
OptimizeResponse(int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42-
super(successfulShards, failedShards, shardFailures);
41+
OptimizeResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42+
super(totalShards, successfulShards, failedShards, shardFailures);
4343
}
4444

4545
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
6666
return new OptimizeRequest();
6767
}
6868

69+
@Override protected boolean ignoreNonActiveExceptions() {
70+
return true;
71+
}
72+
6973
@Override protected OptimizeResponse newResponse(OptimizeRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
7074
int successfulShards = 0;
7175
int failedShards = 0;
7276
List<ShardOperationFailedException> shardFailures = null;
7377
for (int i = 0; i < shardsResponses.length(); i++) {
7478
Object shardResponse = shardsResponses.get(i);
7579
if (shardResponse == null) {
76-
failedShards++;
80+
// a non active shard, ignore...
7781
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
7882
failedShards++;
7983
if (shardFailures == null) {
@@ -84,7 +88,7 @@ public class TransportOptimizeAction extends TransportBroadcastOperationAction<O
8488
successfulShards++;
8589
}
8690
}
87-
return new OptimizeResponse(successfulShards, failedShards, shardFailures);
91+
return new OptimizeResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
8892
}
8993

9094
@Override protected ShardOptimizeRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class RefreshResponse extends BroadcastOperationResponse {
3838

3939
}
4040

41-
RefreshResponse(int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42-
super(successfulShards, failedShards, shardFailures);
41+
RefreshResponse(int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
42+
super(totalShards, successfulShards, failedShards, shardFailures);
4343
}
4444

4545
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ public class TransportRefreshAction extends TransportBroadcastOperationAction<Re
6666
return new RefreshRequest();
6767
}
6868

69+
@Override protected boolean ignoreNonActiveExceptions() {
70+
return true;
71+
}
72+
6973
@Override protected RefreshResponse newResponse(RefreshRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
7074
int successfulShards = 0;
7175
int failedShards = 0;
7276
List<ShardOperationFailedException> shardFailures = null;
7377
for (int i = 0; i < shardsResponses.length(); i++) {
7478
Object shardResponse = shardsResponses.get(i);
7579
if (shardResponse == null) {
76-
failedShards++;
80+
// non active shard, ignore
7781
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
7882
failedShards++;
7983
if (shardFailures == null) {
@@ -84,7 +88,7 @@ public class TransportRefreshAction extends TransportBroadcastOperationAction<Re
8488
successfulShards++;
8589
}
8690
}
87-
return new RefreshResponse(successfulShards, failedShards, shardFailures);
91+
return new RefreshResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
8892
}
8993

9094
@Override protected ShardRefreshRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusResponse.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.elasticsearch.util.settings.ImmutableSettings.*;
3838

3939
/**
40-
* @author kimchy (Shay Banon)
40+
* @author kimchy (shay.banon)
4141
*/
4242
public class IndicesStatusResponse extends BroadcastOperationResponse {
4343

@@ -50,8 +50,8 @@ public class IndicesStatusResponse extends BroadcastOperationResponse {
5050
IndicesStatusResponse() {
5151
}
5252

53-
IndicesStatusResponse(ShardStatus[] shards, ClusterState clusterState, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
54-
super(successfulShards, failedShards, shardFailures);
53+
IndicesStatusResponse(ShardStatus[] shards, ClusterState clusterState, int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
54+
super(totalShards, successfulShards, failedShards, shardFailures);
5555
this.shards = shards;
5656
indicesSettings = newHashMap();
5757
for (ShardStatus shard : shards) {

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import static com.google.common.collect.Lists.*;
4646

4747
/**
48-
* @author kimchy (Shay Banon)
48+
* @author kimchy (shay.banon)
4949
*/
5050
public class TransportIndicesStatusAction extends TransportBroadcastOperationAction<IndicesStatusRequest, IndicesStatusResponse, TransportIndicesStatusAction.IndexShardStatusRequest, ShardStatus> {
5151

@@ -65,6 +65,10 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct
6565
return new IndicesStatusRequest();
6666
}
6767

68+
@Override protected boolean ignoreNonActiveExceptions() {
69+
return true;
70+
}
71+
6872
@Override protected IndicesStatusResponse newResponse(IndicesStatusRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
6973
int successfulShards = 0;
7074
int failedShards = 0;
@@ -73,7 +77,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct
7377
for (int i = 0; i < shardsResponses.length(); i++) {
7478
Object shardResponse = shardsResponses.get(i);
7579
if (shardResponse == null) {
76-
failedShards++;
80+
// simply ignore non active shards
7781
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
7882
failedShards++;
7983
if (shardFailures == null) {
@@ -85,7 +89,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct
8589
successfulShards++;
8690
}
8791
}
88-
return new IndicesStatusResponse(shards.toArray(new ShardStatus[shards.size()]), clusterState, successfulShards, failedShards, shardFailures);
92+
return new IndicesStatusResponse(shards.toArray(new ShardStatus[shards.size()]), clusterState, shardsResponses.length(), successfulShards, failedShards, shardFailures);
8993
}
9094

9195
@Override protected IndexShardStatusRequest newShardRequest() {

modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,6 @@ public CountRequest types(String... types) {
201201
}
202202

203203
@Override public String toString() {
204-
return "[" + Arrays.toString(indices) + "][" + Arrays.toString(types) + "], querySource[" + Unicode.fromBytes(querySource) + "]";
204+
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", querySource[" + Unicode.fromBytes(querySource) + "]";
205205
}
206206
}

modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountResponse.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class CountResponse extends BroadcastOperationResponse {
4040

4141
}
4242

43-
CountResponse(long count, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
44-
super(successfulShards, failedShards, shardFailures);
43+
CountResponse(long count, int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
44+
super(totalShards, successfulShards, failedShards, shardFailures);
4545
this.count = count;
4646
}
4747

modules/elasticsearch/src/main/java/org/elasticsearch/action/count/TransportCountAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction<Coun
9898
successfulShards++;
9999
}
100100
}
101-
return new CountResponse(count, successfulShards, failedShards, shardFailures);
101+
return new CountResponse(count, shardsResponses.length(), successfulShards, failedShards, shardFailures);
102102
}
103103

104104
@Override protected ShardCountResponse shardOperation(ShardCountRequest request) throws ElasticSearchException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/ShardDeleteByQueryRequest.java

+6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import org.elasticsearch.action.support.replication.ShardReplicationOperationRequest;
2424
import org.elasticsearch.util.Nullable;
2525
import org.elasticsearch.util.Strings;
26+
import org.elasticsearch.util.Unicode;
2627
import org.elasticsearch.util.io.stream.StreamInput;
2728
import org.elasticsearch.util.io.stream.StreamOutput;
2829

2930
import java.io.IOException;
31+
import java.util.Arrays;
3032

3133
import static org.elasticsearch.action.Actions.*;
3234

@@ -115,4 +117,8 @@ public String[] types() {
115117
out.writeUTF(type);
116118
}
117119
}
120+
121+
@Override public String toString() {
122+
return "[" + index + "]" + Arrays.toString(types) + ", query [" + Unicode.fromBytes(querySource) + "]";
123+
}
118124
}

0 commit comments

Comments
 (0)