Skip to content

Convert exchange and keystore gen_fsms to gen_statem - #17

Open
hmmr wants to merge 11 commits into
OpenRiak:openriak-3.4from
TI-Tokyo:tiot/openriak-3.4/gen_statemise
Open

hmmr wants to merge 11 commits into
OpenRiak:openriak-3.4from
TI-Tokyo:tiot/openriak-3.4/gen_statemise

Conversation

@hmmr

@hmmr hmmr commented Sep 10, 2026

Copy link
Copy Markdown

Two instances of gen_fsm (aae_keystore and aae_exchange) have been converted to gen_statem.

@hmmr hmmr changed the title WIP Convert exchange and keystore gen_fsms to gen_statem Convert exchange and keystore gen_fsms to gen_statem Sep 12, 2026
@martinsumner

martinsumner commented Sep 16, 2026

Copy link
Copy Markdown

Just wanted to confirm my understanding why it is necessary to include the handling of an info message {gen_event , Reply}.

When the exchange is initiated it is passed an AAE send fun (to be used by remote processes to reply to the exchange), within Riak this is generated from:

https://github.com/OpenRiak/riak_kv/blob/openriak-3.4/src/riak_kv_vnode.erl#L619-632

When this is called by the exchange, it creates the sender to be used for response messages as {fsm, undefined, self()}. So the exchange is identified as an FSM (not a STATEM) within Riak.

When the vnode processes an AAE message (e.g. a request to fetch_root), it will response with riak_core_vnode:reply/2 :

https://github.com/OpenRiak/riak_core/blob/openriak-3.4/src/riak_core_vnode.erl#L1134-L1135

This will use https://github.com/OpenRiak/riak_core/blob/openriak-3.4/src/riak_core_send_msg.erl#L50-L56.

So when used in Riak the responses that are expected in the waiting_all_results state will be received as messages to a gen_fsm not a gen_statem. Hence they arrive as standard process info messages, which then need to be considered as cast responses used when kv_index_tictcatree is tested as a standalone application.

Is that the correct understanding?

Although this is a bit hacky ... riak_core doesn't have message handling for gen_statem at present; and also during transition an exchange could be either a gen_fsm or a gen_statem. So it probably makes sense to use this workaround for now. Although we should add a test within this repo where gen_fsm style replies are used to make sure we have this approach covered within this repo - not just in the riak_test tests.

Does this seem reasonable?

@hmmr hmmr changed the title Convert exchange and keystore gen_fsms to gen_statem WIP Convert exchange and keystore gen_fsms to gen_statem Sep 18, 2026
@hmmr hmmr changed the title WIP Convert exchange and keystore gen_fsms to gen_statem Convert exchange and keystore gen_fsms to gen_statem Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants