Skip to content

Commit a3abe3e

Browse files
committed
rabbit_khepri: Use low-latency favor for read-only transactions
Read-write transactions behave like commands (for example 'put' or 'delete') but read-only transactions behave like queries (for example 'get' or 'exists'). When a transaction is passed as read-only we can re-use the same default options we use for most Khepri queries and favor low-latency queries. This reads the values from the local node rather than the leader (or a consistent query), making the query faster and preventing timeouts when attempting the query when the cluster is in minority. The child commit will update some read-only transaction callsites that take advantage of this low-latency favor.
1 parent f5d2fd6 commit a3abe3e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,16 @@ transaction(Fun, ReadWrite) ->
974974
transaction(Fun, ReadWrite, #{}).
975975

976976
transaction(Fun, ReadWrite, Options0) ->
977-
Options = maps:merge(?DEFAULT_COMMAND_OPTIONS, Options0),
977+
%% If the transaction is read-only, use the same default options we use
978+
%% for most queries.
979+
DefaultQueryOptions = case ReadWrite of
980+
ro ->
981+
#{favor => low_latency};
982+
_ ->
983+
#{}
984+
end,
985+
Options1 = maps:merge(DefaultQueryOptions, Options0),
986+
Options = maps:merge(?DEFAULT_COMMAND_OPTIONS, Options1),
978987
case khepri:transaction(?STORE_ID, Fun, ReadWrite, Options) of
979988
ok -> ok;
980989
{ok, Result} -> Result;

0 commit comments

Comments
 (0)