Skip to content

Commit d015af0

Browse files
javannaareek
authored andcommitted
Internal: made it possible to disable the main transport handler in TransportShardSingleOperationAction
TransportShardSingleOperationAction is currently subclassed by different transport actions. Some of them are internal only, meaning that their execution will take place only in the same node where their parent execution took place. That means that their main transport handler doesn't need to be registered, the only transport handler that's needed is the shard level one. Added `isSubAction` method (defaults to false) to the parent class that tells whether the action is a main one or a subaction, used to decide whether we need to register the main transport handler. Closes #7285
1 parent da68765 commit d015af0

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

src/main/java/org/elasticsearch/action/get/TransportShardMultiGetAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public TransportShardMultiGetAction(Settings settings, ClusterService clusterSer
5757
this.realtime = settings.getAsBoolean("action.get.realtime", true);
5858
}
5959

60+
@Override
61+
protected boolean isSubAction() {
62+
return true;
63+
}
64+
6065
@Override
6166
protected String executor() {
6267
return ThreadPool.Names.GET;

src/main/java/org/elasticsearch/action/percolate/TransportShardMultiPercolateAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public TransportShardMultiPercolateAction(Settings settings, ThreadPool threadPo
5959
this.percolatorService = percolatorService;
6060
}
6161

62+
@Override
63+
protected boolean isSubAction() {
64+
return true;
65+
}
66+
6267
@Override
6368
protected String executor() {
6469
return ThreadPool.Names.PERCOLATE;

src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,21 @@ protected TransportShardSingleOperationAction(Settings settings, String actionNa
6767
this.transportShardAction = actionName + "[s]";
6868
this.executor = executor();
6969

70-
transportService.registerHandler(actionName, new TransportHandler());
70+
if (!isSubAction()) {
71+
transportService.registerHandler(actionName, new TransportHandler());
72+
}
7173
transportService.registerHandler(transportShardAction, new ShardTransportHandler());
7274
}
7375

76+
/**
77+
* Tells whether the action is a main one or a subaction. Used to decide whether we need to register
78+
* the main transport handler. In fact if the action is a subaction, its execute method
79+
* will be called locally to its parent action.
80+
*/
81+
protected boolean isSubAction() {
82+
return false;
83+
}
84+
7485
@Override
7586
protected void doExecute(Request request, ActionListener<Response> listener) {
7687
new AsyncSingleAction(request, listener).start();

src/main/java/org/elasticsearch/action/termvector/TransportSingleShardMultiTermsVectorAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public TransportSingleShardMultiTermsVectorAction(Settings settings, ClusterServ
4949
this.indicesService = indicesService;
5050
}
5151

52+
@Override
53+
protected boolean isSubAction() {
54+
return true;
55+
}
56+
5257
@Override
5358
protected String executor() {
5459
return ThreadPool.Names.GET;

src/main/java/org/elasticsearch/transport/ActionNames.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private static ImmutableBiMap<String, String> createActionNamesMap() {
230230
addShardAction(ExplainAction.NAME, "explain", builder);
231231
addShardAction(GetAction.NAME, "get", builder);
232232
builder.put(MultiGetAction.NAME, "mget");
233-
addShardAction(MultiGetAction.NAME + "[shard]", "mget/shard", builder);
233+
builder.put(MultiGetAction.NAME + "[shard][s]", "mget/shard/s");
234234

235235
builder.put(GetIndexedScriptAction.NAME, "getIndexedScript");
236236
builder.put(PutIndexedScriptAction.NAME, "putIndexedScript");
@@ -239,12 +239,12 @@ private static ImmutableBiMap<String, String> createActionNamesMap() {
239239
builder.put(MoreLikeThisAction.NAME, "mlt");
240240

241241
builder.put(MultiPercolateAction.NAME, "mpercolate");
242-
addShardAction(MultiPercolateAction.NAME + "[shard]", "mpercolate/shard", builder);
242+
builder.put(MultiPercolateAction.NAME + "[shard][s]", "mpercolate/shard/s");
243243

244244
builder.put(MultiSearchAction.NAME, "msearch");
245245

246246
builder.put(MultiTermVectorsAction.NAME, "mtv");
247-
addShardAction(MultiTermVectorsAction.NAME + "[shard]", "mtv/shard", builder);
247+
builder.put(MultiTermVectorsAction.NAME + "[shard][s]", "mtv/shard/s");
248248

249249
addShardAction(PercolateAction.NAME, "percolate", builder);
250250

0 commit comments

Comments
 (0)