@@ -64,9 +64,9 @@ message handlers for its methods, then run the flux reactor. It should
6464use event driven (reactive) programming techniques to remain responsive
6565while juggling work from multiple clients.
6666
67- Keepalive messages are sent to the broker via pre-registered reactor
67+ Status messages are sent to the broker via pre-registered reactor
6868watchers to indicate when the module is initializing, running, finalizing,
69- or exited. At initialization, a module MAY also manually send a keepalive
69+ or exited. At initialization, a module MAY also manually send a status
7070message to indicate to the broker when initialization is complete. This
7171provides synchronization to the broker module loader as well as useful
7272runtime debug information that can be reported by ``flux module list ``.
@@ -91,35 +91,59 @@ A broker module SHALL export the following global symbols:
9191 type of error on failure.
9292
9393
94- Keepalive Values
95- ~~~~~~~~~~~~~~~~
94+ Status Messages
95+ ~~~~~~~~~~~~~~~
9696
97- A broker module SHALL send RFC 3 keepalive messages containing status
98- integers to the broker over its broker handle. Status integers are
99- enumerated as follows:
97+ A broker module SHALL be considered to be in one of the following states,
98+ represented by the integer values shown in parenthesis:
10099
101100- FLUX_MODSTATE_INIT (0) - initializing
102-
103101- FLUX_MODSTATE_RUNNING (1) - running
104-
105102- FLUX_MODSTATE_FINALIZING (2) - finalizing
106-
107103- FLUX_MODSTATE_EXITED (3) - ``mod_main() `` exited
108104
109- Modules SHALL send a keepalive message of ``FLUX_MODSTATE_RUNNING ``
110- after initialization to notify the broker that the module has started
111- successfully. In order to ensure this happens for all modules, A keepalive
112- message SHALL be sent via a pre-registered reactor watcher upon a module's
113- first entry to the reactor if the module has not otherwise entered the
114- RUNNING state. In addition, keepalive messages MAY be sent to the broker
115- at regular intervals. The keepalive ``errnum `` field SHALL be zero except
116- when ``mod_main() `` returns a value of -1 indicating failure and state
117- transitions to FLUX_MODSTATE_EXITED. In this case ``errnum `` SHALL be
118- set to the value of POSIX ``errno `` set by ``mod_main() `` before returning.
105+ Upon loading the module, the broker SHALL initialize the broker state
106+ to ``FLUX_MODSTATE_INIT ``.
107+
108+ After initialization is complete, a module SHALL send an RPC to the
109+ ``broker.module-status `` service with the FLUX_RPC_NORESPONSE flag to
110+ notify the broker that the module has started successfully. In order to
111+ ensure this happens for all modules, the RPC SHALL be sent via a
112+ pre-registered reactor watcher upon a module's first entry to the reactor
113+ if the module has not already sent the message.
114+
115+ Example payload:
116+
117+ .. code :: json
118+
119+ {
120+ "status" :1
121+ }
119122
120- The broker MAY track the number of session heartbeats since a
121- module last sent a message and report this as "idle time"
122- for the module.
123+ After exiting the reactor and before exiting the module thread, the module
124+ SHALL send an RPC to ``broker.module-status `` indicating that it intends to
125+ exit. The module SHALL wait for a response to this message before exiting
126+ ``mod_main() ``.
127+
128+ Example payload:
129+
130+ .. code :: json
131+
132+ {
133+ "status" :2
134+ }
135+
136+ Finally once ``mod_main() `` has exited, the module thread SHALL send an RPC
137+ to ```broker.module-status `` with the FLUX_RPC_NORESPONSE flag including
138+ the error status of the module: zero if ``mod_main() `` exited with a return
139+ code greater than or equal to zero, otherwise the value of ``errno ``.
140+
141+ .. code :: json
142+
143+ {
144+ "status" :2 ,
145+ "errnum" :0
146+ }
123147
124148
125149 Load Sequence
@@ -137,10 +161,9 @@ Unload Sequence
137161
138162The broker module loader SHALL send a ``<service>.shutdown `` request to the
139163module when the module loader receives a ``broker.rmmod `` request for the
140- module. In response, the broker module SHALL exit ``mod_main() ``, send a
141- keepalive transition to FLUX_MODSTATE_EXITED state, and exit the
142- module’s thread or process. This final state transition indicates to
143- the broker that it MAY clean up the module thread.
164+ module. In response, the broker module SHALL exit ``mod_main() ``, sending
165+ state transition messages as described above, and exit the module’s thread
166+ or process. The final state transition indicates to the broker that it MAY clean up the module thread.
144167
145168
146169Built-in Request Handlers
0 commit comments