Class RaftStorageCompleter
RaftStorage
callbacks in the context of an actor. While
ExecuteInSelfActor
is sufficient for purely-asynchronous tasks, EntryStore
has at least two method
which require the callback to resolve before we process any other messages.
This acts as a replacement for Pekko Persistence's synchronous operations, supported by stash()
mechanics.
Rather than relying on Pekko semantics, we have this completer and its queue and trackers. RaftActor
calls
completeUntilSynchronized()
before it starts processing the next message, ensuring any completions are
observed before we process any message. RaftActor
also calls completeUntilSynchronized()
after it
has handled a message and before in returns control back to Pekko.
At the end of the day, this acknowledges the special relationship RaftActor
has with RaftStorage
:
storage operations' completions take precedence over whatever is delivered to the actor via its mailbox.
-
Constructor Summary
ConstructorsConstructorDescriptionRaftStorageCompleter
(String memberId, ExecuteInSelfActor actor) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Run all enqueued completions until the queue is observed to be empty.void
Run all enqueued completions until all callbacks registered withsyncWithCurrentMessage(RaftCallback)
have completed.void
enqueueCompletion
(Runnable completion) Enqueue a singleRunnable
completion.void
enqueueCompletions
(List<Runnable> completions) Enqueue a multipleRunnable
completions.memberId()
Returns thememberId
.toString()
-
Constructor Details
-
RaftStorageCompleter
Default constructor.- Parameters:
memberId
- the memberIdactor
- the actor servicing this completer
-
-
Method Details
-
memberId
Returns thememberId
.- Returns:
- the
memberId
-
completeUntilEmpty
public void completeUntilEmpty()Run all enqueued completions until the queue is observed to be empty. Normally this method is called automatically when the queue becomes non-empty viaExecuteInSelfActor.executeInSelf(Runnable)
, but this method is exposed to allow eager calls from the actor itself.Normally we would not expose this method, but in current actor implementation normal delivery of those calls compete with
ControlMessage
s and we effectively want completions to preempt any other messages, so as to provide most up-to-date storage state. This improves latency of both forward progress reporting and error propagation.WARNING: This method must be invoked from actor containment matching
ExecuteInSelfActor
provided to constructor. Bad things will happen otherwise. -
completeUntilSynchronized
Run all enqueued completions until all callbacks registered withsyncWithCurrentMessage(RaftCallback)
have completed. If there are no such callbacks, this method does nothing.- Throws:
InterruptedException
- if the thread is interrupted
-
enqueueCompletion
Enqueue a singleRunnable
completion.- Parameters:
completion
- the completion
-
enqueueCompletions
Enqueue a multipleRunnable
completions.- Parameters:
completions
- the completion
-
toString
-