Skip to content

Commit fb5fe5e

Browse files
authored
Document Rest*Action and Transport*Action threading model (#135043)
* Documentation : Rest and Transport Action Threading Model
1 parent f8ed310 commit fb5fe5e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/internal/GeneralArchitectureGuide.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ are coordinated.
101101
> does not hold, in those cases you can locate the transport action for a REST action by looking at the `NodeClient` invocation in the
102102
> `Rest*Action`'s `prepareRequest` implementation, it should specify the `ActionType` being invoked which can then be used to locate
103103
> the `Transport*Action` class that handles it.
104+
>
105+
> A netty [EventLoop] thread handles the initial steps of a `Rest*Action` request lifecycle such as decoding, validation and routing.
106+
> Upon entry into the "transport layer", [NodeClient] delegates the decision of execution to individual `TransportAction`. Each action
107+
> determines whether to execute synchronously on invoking thread-an approach reserved for lightweight processing-or to dispatch execution to an appropriate
108+
> thread pool, which is recommended practice for heavy workloads. Comprehensive mechanisms are available for propagating [ThreadContext] when tasks
109+
> are dispatched to alternate thread pools.
110+
>
111+
> `TransportAction` can also be initiated through peer-to-peer communication between nodes. In such cases, the [InboundHandler]
112+
> locates the appropriate `TransportAction` by consulting the [NamedRegistry], then invokes the `TransportAction`'s handleExecution() method. When a `TransportAction`
113+
> is registered, it can specify an executor to control how the action is run. One option is the `DIRECT_EXECUTOR_SERVICE`, which executes the
114+
> action on the calling thread. However, this should be used with caution—it's only appropriate when the action is lightweight.
115+
> Otherwise, it risks blocking the peer-to-peer I/O thread, potentially degrading responsiveness and causing the node to become unresponsive.
116+
> If `TransportAction` elects a separate executor, `InboundHandler` performs message deserialization before delegating execution to the executor,
117+
> refer to [TransportResponseHandler] method executor() for more details.
118+
>
119+
> `TransportAction` requests received from remote nodes are always deserialized on the Netty `EventLoop`. In contrast, `TransportAction` responses are
120+
> deserialized only after being dispatched to the designated executor. Outbound messages, including both requests and responses, are serialized
121+
> synchronously on the calling thread.
104122
105123
### Action registration
106124
Elasticsearch contains many [TransportAction]s, configured statically in [ActionModule#setupActions]. [ActionPlugin]s can
@@ -115,6 +133,17 @@ The actions themselves sometimes dispatch downstream actions to other nodes in t
115133
[TransportService#registerRequestHandler]. [HandledTransportAction] is a common parent class that registers an action with the
116134
`TransportService`.
117135

136+
> [!NOTE]
137+
> `TransportAction` `ActionType` naming conventions encode semantic information about the role, scope, plugins, modules and behaviours.
138+
> [ActionType] instances are mapped to permission privileges via the [ClusterPrivilegeResolver]. Security interceptors enforce access
139+
> control by invoking RBACEngine.checkPrivileges().
140+
> Indices-level [ActionType] strings generally follows the pattern: `indices:[data|admin|monitor]/[read|write|get]/[index|bulk|update]`.
141+
> Cluster-level [ActionType] strings are prefixed by `cluster:` are often followed by a domain-specific such as `autoscaling`, `logstash`, `ingest`,
142+
> `xpack`.
143+
> - `internal:` is meant to executed by `_system` user.
144+
> - `cluster:internal/xpack/..` [ActionType] strings are plugin specific.
145+
> - `internal:transport/proxy/indices:` [ActionType] strings are automatically wrapped actions when requests for CCR/CCS in proxy mode.
146+
118147
> [!NOTE]
119148
> The name [TransportAction] can be misleading, as it suggests they are all invoke-able and invoked via the TCP transport. In fact,
120149
> a majority of transport actions are only ever invoked locally via the [NodeClient]. The two key features of a `TransportAction` are:
@@ -179,6 +208,13 @@ capabilities.
179208
[TransportService]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/transport/TransportService.java
180209
[TransportSingleShardAction]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/action/support/single/shard/TransportSingleShardAction.java
181210
[Transport]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/transport/Transport.java
211+
[EventLoop]:https://www.elastic.co/docs/reference/elasticsearch/configuration-reference/networking-settings#modules-network-threading-model
212+
[TaskManager]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/tasks/TaskManager.java
213+
[InboundHandler]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/transport/InboundHandler.java
214+
[NamedRegistry]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/common/NamedRegistry.java
215+
[IndexPrivilege]:https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java
216+
[ClusterPrivilegeResolver]:https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java
217+
[TransportResponseHandler]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/transport/TransportResponseHandler.java
182218

183219
## Serializations
184220

0 commit comments

Comments
 (0)