Hi tison,

This is a good question.  We recently added the following javadoc
(RATIS-1642) to clarify the thread safety requirements.

// StateMachine.java
 *  A {@link StateMachine} implementation must be threadsafe.
 *  For example, the {@link #applyTransaction(TransactionContext)} method
and the {@link #query(Message)} method
 *  can be invoked in parallel.

Tsz-Wo

On Fri, Sep 30, 2022 at 6:21 PM tison <[email protected]> wrote:

> Hi,
>
> I can imagine `applyTransaction' exclusive each other, and queries can
> safely concurrent.
>
> But I read some code snippets:
>
>     synchronized (transactionFutures)
>
> ... in BaseStateMachine source code. This guides me to this question.
>
> Suppose I hold an in-memory map in the state machine, and update an
> intermediate state during applyTransaction. Of course, I don't want my
> users to see the intermediate state. Is it my responsibility to do lock
> guards?
>
> Best,
> tison.
>

Reply via email to