Add set_consistency_mode() to projection store API, use it
This commit is contained in:
parent
833463f20d
commit
e8f3ab381d
3 changed files with 31 additions and 5 deletions
|
@ -232,12 +232,18 @@ init({MyName, InitMembersDict, MgrOpts}) ->
|
|||
random:seed(now()),
|
||||
init_remember_partition_hack(),
|
||||
Opt = fun(Key, Default) -> proplists:get_value(Key, MgrOpts, Default) end,
|
||||
CMode = Opt(consistency_mode, ap_mode),
|
||||
InitWitness_list = Opt(witnesses, []),
|
||||
ZeroAll_list = [P#p_srvr.name || {_,P} <- orddict:to_list(InitMembersDict)],
|
||||
ZeroProj = make_none_projection(MyName, ZeroAll_list,
|
||||
InitWitness_list, InitMembersDict),
|
||||
ok = store_zeroth_projection_maybe(ZeroProj, MgrOpts),
|
||||
CMode = Opt(consistency_mode, ap_mode),
|
||||
case get_projection_store_regname(MgrOpts) of
|
||||
undefined ->
|
||||
ok;
|
||||
PS ->
|
||||
ok = set_consistency_mode(PS, CMode)
|
||||
end,
|
||||
|
||||
%% Using whatever is the largest epoch number in our local private
|
||||
%% store, this manager starts out using the "none" projection. If
|
||||
|
@ -309,6 +315,7 @@ handle_call({set_chain_members, MembersDict, Witness_list}, _From,
|
|||
Witness_list /= [] ->
|
||||
cp_mode
|
||||
end,
|
||||
ok = set_consistency_mode(machi_flu_psup:make_proj_supname(MyName), CMode),
|
||||
NewProj = machi_projection:update_checksum(
|
||||
OldProj#projection_v1{author_server=MyName,
|
||||
creation_time=now(),
|
||||
|
@ -442,7 +449,7 @@ get_my_proj_boot_info(MgrOpts, DefaultDict, DefaultProj, ProjType) ->
|
|||
%% 0th epoch is already written, there's no problem.
|
||||
|
||||
store_zeroth_projection_maybe(ZeroProj, MgrOpts) ->
|
||||
case proplists:get_value(projection_store_registered_name, MgrOpts) of
|
||||
case get_projection_store_regname(MgrOpts) of
|
||||
undefined ->
|
||||
ok;
|
||||
Store ->
|
||||
|
@ -451,6 +458,14 @@ store_zeroth_projection_maybe(ZeroProj, MgrOpts) ->
|
|||
ok
|
||||
end.
|
||||
|
||||
get_projection_store_regname(MgrOpts) ->
|
||||
proplists:get_value(projection_store_registered_name, MgrOpts).
|
||||
|
||||
set_consistency_mode(undefined, CMode) ->
|
||||
ok;
|
||||
set_consistency_mode(ProjStore, CMode) ->
|
||||
machi_projection_store:set_consistency_mode(ProjStore, CMode).
|
||||
|
||||
set_active_timer(#ch_mgr{name=MyName, members_dict=MembersDict}=S) ->
|
||||
FLU_list = [P#p_srvr.name || {_,P} <- orddict:to_list(MembersDict)],
|
||||
%% Perturb the order a little bit, to avoid near-lock-step
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
get_all_projections/2, get_all_projections/3,
|
||||
list_all_projections/2, list_all_projections/3
|
||||
]).
|
||||
-export([set_wedge_notify_pid/2]).
|
||||
-export([set_wedge_notify_pid/2, set_consistency_mode/2]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
|
@ -72,7 +72,8 @@
|
|||
private_dir = "" :: string(),
|
||||
wedge_notify_pid :: pid() | atom(),
|
||||
max_public_epochid = ?NO_EPOCH :: {-1 | non_neg_integer(), binary()},
|
||||
max_private_epochid = ?NO_EPOCH :: {-1 | non_neg_integer(), binary()}
|
||||
max_private_epochid = ?NO_EPOCH :: {-1 | non_neg_integer(), binary()},
|
||||
consistency_mode=ap_mode :: 'ap_mode' | 'cp_mode'
|
||||
}).
|
||||
|
||||
%% @doc Start a new projection store server.
|
||||
|
@ -159,7 +160,12 @@ list_all_projections(PidSpec, ProjType, Timeout)
|
|||
g_call(PidSpec, {list_all_projections, ProjType}, Timeout).
|
||||
|
||||
set_wedge_notify_pid(PidSpec, NotifyWedgeStateChanges) ->
|
||||
gen_server:call(PidSpec, {set_wedge_notify_pid, NotifyWedgeStateChanges}).
|
||||
gen_server:call(PidSpec, {set_wedge_notify_pid, NotifyWedgeStateChanges},
|
||||
infinity).
|
||||
|
||||
set_consistency_mode(PidSpec, CMode)
|
||||
when CMode == ap_mode; CMode == cp_mode ->
|
||||
gen_server:call(PidSpec, {set_consistency_mode, CMode}, infinity).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
@ -224,6 +230,8 @@ handle_call({{list_all_projections, ProjType}, LC1}, _From, S) ->
|
|||
{reply, {{ok, find_all(Dir)}, LC2}, S};
|
||||
handle_call({set_wedge_notify_pid, NotifyWedgeStateChanges}, _From, S) ->
|
||||
{reply, ok, S#state{wedge_notify_pid=NotifyWedgeStateChanges}};
|
||||
handle_call({set_consistency_mode, CMode}, _From, S) ->
|
||||
{reply, ok, S#state{consistency_mode=CMode}};
|
||||
handle_call(_Request, _From, S) ->
|
||||
Reply = {whaaaaaaaaaaaaazz, _Request},
|
||||
{reply, Reply, S}.
|
||||
|
|
|
@ -54,6 +54,9 @@ smoke_test() ->
|
|||
ok = ?PS:write(a_pstore, private, P1c),
|
||||
{error, written} = ?PS:write(a_pstore, private, P1a),
|
||||
|
||||
ok = ?PS:set_consistency_mode(a_pstore, ap_mode),
|
||||
ok = ?PS:set_consistency_mode(a_pstore, cp_mode),
|
||||
|
||||
ok
|
||||
after
|
||||
machi_flu_psup:stop_flu_package(a),
|
||||
|
|
Loading…
Reference in a new issue