public class QueryState extends Object
Section 6.4 of Raft Dissertation: ... Linearizability requires the results of a read to reflect a state of the system sometime after the read was initiated; each read must at least return the results of the latest committed write. ... Fortunately, it is possible to bypass the Raft log for read-only queries and still preserve linearizability.
Constructor and Description |
---|
QueryState() |
Modifier and Type | Method and Description |
---|---|
int |
addQuery(long commitIndex,
Object operation,
InternalCompletableFuture resultFuture)
Adds the given query to the collection of queries and returns the number
of queries waiting to be executed.
|
boolean |
isAckNeeded(RaftEndpoint follower,
int majority) |
boolean |
isMajorityAcked(long commitIndex,
int majority)
Returns
true if there are queries waiting and acks are received
from the majority. |
Collection<BiTuple<Object,InternalCompletableFuture>> |
operations()
Returns the queries waiting to be executed.
|
int |
queryCount()
Returns the number of queries waiting for execution.
|
long |
queryRound()
Returns the index of the heartbeat round to execute the currently
waiting queries.
|
boolean |
removeAck(RaftEndpoint follower)
Returns
true if the given follower is removed from the ack list. |
void |
reset()
Resets the collection of waiting queries and acknowledged followers.
|
String |
toString() |
boolean |
tryAck(long queryRound,
RaftEndpoint follower)
Returns
true if the given follower is accepted as an acker
for the current query round. |
public int addQuery(long commitIndex, Object operation, InternalCompletableFuture resultFuture)
public boolean tryAck(long queryRound, RaftEndpoint follower)
true
if the given follower is accepted as an acker
for the current query round. It is accepted only if there are
waiting queries to be executed and the queryRound
argument
matches to the current query round.public boolean removeAck(RaftEndpoint follower)
true
if the given follower is removed from the ack list.public int queryCount()
public long queryRound()
public boolean isMajorityAcked(long commitIndex, int majority)
true
if there are queries waiting and acks are received
from the majority. Fails with IllegalStateException
if
the given commit index is smaller than queryCommitIndex
.public boolean isAckNeeded(RaftEndpoint follower, int majority)
public Collection<BiTuple<Object,InternalCompletableFuture>> operations()
public void reset()
Copyright © 2019 Hazelcast, Inc.. All rights reserved.