Skip to content

Commit b91fedc

Browse files
committed
WIP
1 parent e9902b1 commit b91fedc

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/khepri_machine.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,20 @@ register_projection(
680680
?ARE_PROJECTION_ETS_OPTIONS(EtsOptions) andalso
681681
(?IS_HORUS_STANDALONE_FUN(ProjectionFun) orelse
682682
ProjectionFun =:= copy) ->
683+
Timeout = get_timeout(Options),
684+
T0 = khepri_utils:start_timeout_window(Timeout),
683685
Compatible = khepri_projection:check_compatibility_with_store(
684-
StoreId, Projection),
686+
StoreId, Projection, Timeout),
685687
case Compatible of
686688
ok ->
689+
NewTimeout = khepri_utils:end_timeout_window(Timeout, T0),
690+
Options1 = Options#{timeout => NewTimeout},
691+
687692
PathPattern = khepri_path:from_string(PathPattern0),
688693
khepri_path:ensure_is_valid(PathPattern),
689694
Command = #register_projection{pattern = PathPattern,
690695
projection = Projection},
691-
process_command(StoreId, Command, Options);
696+
process_command(StoreId, Command, Options1);
692697
{error, _Reason} = Error ->
693698
Error
694699
end.

src/khepri_projection.erl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
-export([new/2, new/3, name/1]).
201201

202202
%% For internal use only
203-
-export([check_compatibility_with_store/2, init/1, trigger/4, delete/1]).
203+
-export([check_compatibility_with_store/3, init/1, trigger/4, delete/1]).
204204

205205
-type name() :: atom().
206206
%% The name of a projection.
@@ -510,33 +510,24 @@ to_ets_options(Key, Value, _Acc) ->
510510
name(#khepri_projection{name = Name}) ->
511511
Name.
512512

513-
-spec check_compatibility_with_store(StoreId, Projection) -> Ret when
513+
-spec check_compatibility_with_store(StoreId, Projection, Timeout) -> Ret when
514514
StoreId :: khepri:store_id(),
515515
Projection :: khepri_projection:projection(),
516+
Timeout :: timeout(),
516517
Ret :: ok | {error, any()}.
517518
%% @doc Checks if a projection is compatible with the given store.
518519
%%
519520
%% @private
520521

521-
check_compatibility_with_store(StoreId, Projection) ->
522+
check_compatibility_with_store(StoreId, Projection, Timeout) ->
522523
case is_single_table_projection(Projection) of
523524
true ->
524525
ok;
525526
false ->
526527
%% Ensure the Khepri cluster runs a new enough version to support
527528
%% multi-table projections.
528-
Compatible = khepri_machine:does_api_comply_with(
529-
multi_table_projections, StoreId),
530-
case Compatible of
531-
true ->
532-
ok;
533-
false ->
534-
Reason = ?khepri_error(
535-
cluster_incompatible_with_multi_table_projection,
536-
#{store_id => StoreId,
537-
projection => Projection}),
538-
{error, Reason}
539-
end
529+
khepri_machine:wait_for_effective_behaviour(
530+
StoreId, multi_table_projections, Timeout)
540531
end.
541532

542533
-spec init(Projection) -> Ret when

0 commit comments

Comments
 (0)