|
57 | 57 | %% </ul> |
58 | 58 | %% </td> |
59 | 59 | %% </tr> |
| 60 | +%% <tr> |
| 61 | +%% <td style="text-align: right; vertical-align: top;">2</td> |
| 62 | +%% <td> |
| 63 | +%% <ul> |
| 64 | +%% <li>Added support for multi-table projections (see {@link |
| 65 | +%% khepri_projection}).</li> |
| 66 | +%% </ul> |
| 67 | +%% </td> |
| 68 | +%% </tr> |
60 | 69 | %% </table> |
61 | 70 |
|
62 | 71 | -module(khepri_machine). |
@@ -668,14 +677,26 @@ register_projection( |
668 | 677 | ets_options = EtsOptions} = Projection, |
669 | 678 | Options) |
670 | 679 | when is_atom(Name) andalso |
671 | | - is_list(EtsOptions) andalso |
| 680 | + ?ARE_PROJECTION_ETS_OPTIONS(EtsOptions) andalso |
672 | 681 | (?IS_HORUS_STANDALONE_FUN(ProjectionFun) orelse |
673 | 682 | ProjectionFun =:= copy) -> |
674 | | - PathPattern = khepri_path:from_string(PathPattern0), |
675 | | - khepri_path:ensure_is_valid(PathPattern), |
676 | | - Command = #register_projection{pattern = PathPattern, |
677 | | - projection = Projection}, |
678 | | - process_command(StoreId, Command, Options). |
| 683 | + Timeout = get_timeout(Options), |
| 684 | + T0 = khepri_utils:start_timeout_window(Timeout), |
| 685 | + Compatible = khepri_projection:check_compatibility_with_store( |
| 686 | + StoreId, Projection, Timeout), |
| 687 | + case Compatible of |
| 688 | + ok -> |
| 689 | + NewTimeout = khepri_utils:end_timeout_window(Timeout, T0), |
| 690 | + Options1 = Options#{timeout => NewTimeout}, |
| 691 | + |
| 692 | + PathPattern = khepri_path:from_string(PathPattern0), |
| 693 | + khepri_path:ensure_is_valid(PathPattern), |
| 694 | + Command = #register_projection{pattern = PathPattern, |
| 695 | + projection = Projection}, |
| 696 | + process_command(StoreId, Command, Options1); |
| 697 | + {error, _Reason} = Error -> |
| 698 | + Error |
| 699 | + end. |
679 | 700 |
|
680 | 701 | -spec unregister_projections(StoreId, Names, Options) -> Ret when |
681 | 702 | StoreId :: khepri:store_id(), |
@@ -1957,17 +1978,18 @@ overview(State) -> |
1957 | 1978 | keep_while_conds => KeepWhileConds}. |
1958 | 1979 |
|
1959 | 1980 | -spec version() -> MacVer when |
1960 | | - MacVer :: 2. |
| 1981 | + MacVer :: 3. |
1961 | 1982 | %% @doc Returns the state machine version. |
1962 | 1983 |
|
1963 | 1984 | version() -> |
1964 | | - 2. |
| 1985 | + 3. |
1965 | 1986 |
|
1966 | 1987 | -spec which_module(MacVer) -> Module when |
1967 | | - MacVer :: 0..2, |
| 1988 | + MacVer :: 0..3, |
1968 | 1989 | Module :: ?MODULE. |
1969 | 1990 | %% @doc Returns the state machine module corresponding to the given version. |
1970 | 1991 |
|
| 1992 | +which_module(3) -> ?MODULE; |
1971 | 1993 | which_module(2) -> ?MODULE; |
1972 | 1994 | which_module(1) -> ?MODULE; |
1973 | 1995 | which_module(0) -> ?MODULE. |
@@ -2041,6 +2063,7 @@ api_behaviour_to_machine_version(dedup_protection) -> 1; |
2041 | 2063 | api_behaviour_to_machine_version(delete_reason_in_node_props) -> 2; |
2042 | 2064 | api_behaviour_to_machine_version(indirect_deletes_in_ret) -> 2; |
2043 | 2065 | api_behaviour_to_machine_version(uniform_write_ret) -> 2; |
| 2066 | +api_behaviour_to_machine_version(multi_table_projections) -> 3; |
2044 | 2067 | api_behaviour_to_machine_version(Behaviour) when is_atom(Behaviour) -> |
2045 | 2068 | undefined. |
2046 | 2069 |
|
@@ -2830,7 +2853,9 @@ convert_state1(State, 0, 1) -> |
2830 | 2853 | convert_state1(State, 1, 2) -> |
2831 | 2854 | Tree = get_tree(State), |
2832 | 2855 | Tree1 = khepri_tree:convert_tree(Tree, 1, 2), |
2833 | | - set_tree(State, Tree1). |
| 2856 | + set_tree(State, Tree1); |
| 2857 | +convert_state1(State, 2, 3) -> |
| 2858 | + State. |
2834 | 2859 |
|
2835 | 2860 | -spec update_projections(OldState, NewState) -> ok when |
2836 | 2861 | OldState :: khepri_machine:state(), |
|
0 commit comments