-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
wait_for_index
option to leader and local queries
[Why] It allows to wait for a specific index to be applied locally (or on the leader) before a query is evaluated. It is useful when the caller wants to be sure that the result of the previous command is "visible" by the next query. By default, it's not guarantied because the command will be considered successfully applied as long as a quorum of Ra servers applied it. This list of Ra servers may not include the local node for instance. [How] If the `wait_for_index` option is specified with a `{Index, Term}` tuple, the query will be evaluated right away if that index is already applied, or it will be added to a list of pending queries. Pending queries are evaluated after each applied batch of commands by the local node. If a pending query's target index was reached or passed, it is evaluated. If a pending query's target term ended, an error is returned. Here is an example: ra:local_query(ServerId, QueryFun, #{wait_for_index => {Index, Term}}). The `local_query` tuple sent to the Ra server changes format. The old one was: {local_query, QueryFun} The new one is: {local_query, QueryFun, Options} If the remote Ra server that receives the query runs a version of Ra older than the one having this change and thus doesn't understand the new tuple, it will ignore and drop the query. This will lead to a timeout of the query, or an indefinitely hanging call if the timeout was set to `infinity`. Note in the opposite situation, i.e. if a Ra server that knows the new query tuple receives an old tuple, it will evaluate the query as if the options was an empty map. V2: Rename the option from `limit` to `wait_for_index` which is more explicit.
- Loading branch information
Showing
5 changed files
with
285 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.