|
86 | 86 | clear_many_payloads/1, clear_many_payloads/2,
|
87 | 87 |
|
88 | 88 | abort/1,
|
89 |
| - is_transaction/0]). |
| 89 | + is_transaction/0, |
| 90 | + api_version/0]). |
90 | 91 |
|
91 | 92 | -compile({no_auto_import, [get/1, put/2, erase/1]}).
|
92 | 93 |
|
| 94 | +-define(TX_API_VERSION, 1). |
| 95 | + |
93 | 96 | %% FIXME: Dialyzer complains about several functions with "optional" arguments
|
94 | 97 | %% (but not all). I believe the specs are correct, but can't figure out how to
|
95 | 98 | %% please Dialyzer. So for now, let's disable this specific check for the
|
|
106 | 109 | -type tx_abort() :: khepri:error(any()).
|
107 | 110 | %% Return value after a transaction function aborted.
|
108 | 111 |
|
| 112 | +-type api_version() :: pos_integer(). |
| 113 | +%% Version of the transaction API. |
| 114 | + |
109 | 115 | -export_type([tx_fun/0,
|
110 | 116 | tx_fun_result/0,
|
111 |
| - tx_abort/0]). |
| 117 | + tx_abort/0, |
| 118 | + api_version/0]). |
112 | 119 |
|
113 | 120 | %% -------------------------------------------------------------------
|
114 | 121 | %% is_empty().
|
@@ -1009,3 +1016,26 @@ is_transaction() ->
|
1009 | 1016 | {_State, _SideEffects} -> true;
|
1010 | 1017 | _ -> false
|
1011 | 1018 | end.
|
| 1019 | + |
| 1020 | +%% ------------------------------------------------------------------- |
| 1021 | +%% api_version(). |
| 1022 | +%% ------------------------------------------------------------------- |
| 1023 | + |
| 1024 | +-spec api_version() -> khepri_tx:api_version(). |
| 1025 | +%% @doc Returns the version of the transaction API for the Khepri instance |
| 1026 | +%% that execute the transaction. |
| 1027 | +%% |
| 1028 | +%% The transaction code is compiled on one Erlang node with a specific version |
| 1029 | +%% of Khepri. However, it is executed on all members of the Khepri cluster. |
| 1030 | +%% Some Erlang nodes might use another version of Khepri, newer or older, and |
| 1031 | +%% the transaction API may differ. |
| 1032 | +%% |
| 1033 | +%% For instance in Khepri 0.17.x, the return values of the {@link |
| 1034 | +%% khepri_tx_adv} functions changed. The transaction code will have to handle |
| 1035 | +%% voth versions of the API to work correctly. Thus it can use this function |
| 1036 | +%% to adapt its behaviour. |
| 1037 | +%% |
| 1038 | +%% @returns the version of the Khepri transaction API. |
| 1039 | + |
| 1040 | +api_version() -> |
| 1041 | + ?TX_API_VERSION. |
0 commit comments