Skip to content

Apply without generating response #1266

Open
@m-mueller678

Description

@m-mueller678

When applying requests to the state machine, responses are always produced, even though they are only used on the leader as far as I can tell. In the project I am working on, there are many requests to the state machine that are read only, but are expensive to compute. On the followers, I would like to avoid this computation, as the response will be discarded anyway and the requests do not change the state machine.

I would like a variation of RaftStateMachine::apply that produces no response and is called whenever the response would be discarded anyway. It could defer to the normal apply implementation by default to not complicate implementing RaftStateMachine:

async fn apply_without_response<I>(
    &mut self,
    entries: I,
) -> Result<(), StorageError<C::NodeId>>{
    self.apply().await.map(|_|())
}

Alternatively, an extra parameter could be added to apply to control response generation, but that would put more burden on a minimal state machine implementation.

A way for the leader to read directly from the state machine without writing a log would be preferred for my specific use case, but there could also be write-requests where the response is expensive to generate.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions