Class RaftStorageCompleter

java.lang.Object
org.opendaylight.controller.cluster.raft.spi.RaftStorageCompleter

@NonNullByDefault public final class RaftStorageCompleter extends Object
Meeting point for dispatching completions from 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 Details

    • RaftStorageCompleter

      public RaftStorageCompleter(String memberId, ExecuteInSelfActor actor)
      Default constructor.
      Parameters:
      memberId - the memberId
      actor - the actor servicing this completer
  • Method Details

    • memberId

      public String memberId()
      Returns the memberId.
      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 via ExecuteInSelfActor.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 ControlMessages 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

      public void completeUntilSynchronized() throws InterruptedException
      Run all enqueued completions until all callbacks registered with syncWithCurrentMessage(RaftCallback) have completed. If there are no such callbacks, this method does nothing.
      Throws:
      InterruptedException - if the thread is interrupted
    • enqueueCompletion

      public void enqueueCompletion(Runnable completion)
      Enqueue a single Runnable completion.
      Parameters:
      completion - the completion
    • enqueueCompletions

      public void enqueueCompletions(List<Runnable> completions)
      Enqueue a multiple Runnable completions.
      Parameters:
      completions - the completion
    • toString

      public String toString()
      Overrides:
      toString in class Object