Package io.microraft

Enum QueryPolicy

    • Enum Constant Detail

      • EVENTUAL_CONSISTENCY

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

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

        Callers can achieve monotonic reads by keeping track of highest commit index they observed via return values of RaftNode's methods and passing it to queries. In this case, RaftNode executes a given query only if its local commit index is greater than equal to the given commit index.

      • 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. 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 Detail

      • values

        public static QueryPolicy[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (QueryPolicy c : QueryPolicy.values())
            System.out.println(c);
        
        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