Package io.microraft

Enum QueryPolicy

java.lang.Object
java.lang.Enum<QueryPolicy>
io.microraft.QueryPolicy
All Implemented Interfaces:
Serializable, Comparable<QueryPolicy>, java.lang.constant.Constable

public enum QueryPolicy extends Enum<QueryPolicy>
Policies to decide how a query operation will be executed on the state machine. Each policy offers different consistency guarantees.
  • Enum Constant Details

    • EVENTUAL_CONSISTENCY

      public static final QueryPolicy EVENTUAL_CONSISTENCY
      Runs the query on the local state machine of any Raft node.

      Reading stale value is highly likely if queries are issued on follower or learner Raft nodes when the leader Raft node is committing new operations.

    • BOUNDED_STALENESS

      public static final QueryPolicy BOUNDED_STALENESS
      Runs the query on the local state machine of any Raft node. The query policy is equivalent to LEADER_LEASE when a query operation is passed to the leader Raft node, If a query operation is passed to a follower or a learner Raft node with this policy, then it is locally executed only if that Raft node has received a heartbeat from the leader Raft node recently. Otherwise, the query operation will fail.

      Reading stale value is possible when a follower or a learner Raft node lags behind the leader but the staleness is bounded by the leader heartbeat timeout configuration.

    • LEADER_LEASE

      public static final QueryPolicy LEADER_LEASE
      Runs the query on the local state machine of the leader Raft node.

      The leader Raft node executes a given query operation with this policy only if it has received AppendEntries RPC responses from the majority of the Raft group in the last leader heartbeat duration.

      This policy is much more likely to hit more recent state when compared to the EVENTUAL_CONSISTENCY policy and BOUNDED_STALENESS policies. However, it cannot guarantee linearizability since other Raft nodes' clocks may move forward in time and they can elect a new leader among themselves while the old leader still considers itself as the leader.

    • LINEARIZABLE

      public static final QueryPolicy LINEARIZABLE
      Runs the query in a linearizable manner on the leader Raft node by using the algorithm defined in the Section: 6.4 Processing read-only queries more efficiently of the Raft dissertation. In short, linearizable queries are handled via a round of AppendEntries RPC between the leader and others without appending an entry to the internal Raft log.

      Since, a given query is executed by the leader Raft node for both LEADER_LEASE and this policy, both policies have the same processing cost. However, this policy guarantees linearizability with an extra cost of 1 RTT latency overhead compared to the LEADER_LEASE policy.

  • Method Details

    • values

      public static QueryPolicy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static QueryPolicy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null