Add set_consistency_mode() to projection store API, use it

This commit is contained in:
Scott Lystig Fritchie 2015-08-26 14:54:01 +09:00
parent 833463f20d
commit e8f3ab381d
3 changed files with 31 additions and 5 deletions

View file

@ -232,12 +232,18 @@ init({MyName, InitMembersDict, MgrOpts}) ->
random:seed(now()), random:seed(now()),
init_remember_partition_hack(), init_remember_partition_hack(),
Opt = fun(Key, Default) -> proplists:get_value(Key, MgrOpts, Default) end, Opt = fun(Key, Default) -> proplists:get_value(Key, MgrOpts, Default) end,
CMode = Opt(consistency_mode, ap_mode),
InitWitness_list = Opt(witnesses, []), InitWitness_list = Opt(witnesses, []),
ZeroAll_list = [P#p_srvr.name || {_,P} <- orddict:to_list(InitMembersDict)], ZeroAll_list = [P#p_srvr.name || {_,P} <- orddict:to_list(InitMembersDict)],
ZeroProj = make_none_projection(MyName, ZeroAll_list, ZeroProj = make_none_projection(MyName, ZeroAll_list,
InitWitness_list, InitMembersDict), InitWitness_list, InitMembersDict),
ok = store_zeroth_projection_maybe(ZeroProj, MgrOpts), 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 %% Using whatever is the largest epoch number in our local private
%% store, this manager starts out using the "none" projection. If %% 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 /= [] -> Witness_list /= [] ->
cp_mode cp_mode
end, end,
ok = set_consistency_mode(machi_flu_psup:make_proj_supname(MyName), CMode),
NewProj = machi_projection:update_checksum( NewProj = machi_projection:update_checksum(
OldProj#projection_v1{author_server=MyName, OldProj#projection_v1{author_server=MyName,
creation_time=now(), 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. %% 0th epoch is already written, there's no problem.
store_zeroth_projection_maybe(ZeroProj, MgrOpts) -> store_zeroth_projection_maybe(ZeroProj, MgrOpts) ->
case proplists:get_value(projection_store_registered_name, MgrOpts) of case get_projection_store_regname(MgrOpts) of
undefined -> undefined ->
ok; ok;
Store -> Store ->
@ -451,6 +458,14 @@ store_zeroth_projection_maybe(ZeroProj, MgrOpts) ->
ok ok
end. 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) -> set_active_timer(#ch_mgr{name=MyName, members_dict=MembersDict}=S) ->
FLU_list = [P#p_srvr.name || {_,P} <- orddict:to_list(MembersDict)], FLU_list = [P#p_srvr.name || {_,P} <- orddict:to_list(MembersDict)],
%% Perturb the order a little bit, to avoid near-lock-step %% Perturb the order a little bit, to avoid near-lock-step

View file

@ -59,7 +59,7 @@
get_all_projections/2, get_all_projections/3, get_all_projections/2, get_all_projections/3,
list_all_projections/2, list_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 %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@ -72,7 +72,8 @@
private_dir = "" :: string(), private_dir = "" :: string(),
wedge_notify_pid :: pid() | atom(), wedge_notify_pid :: pid() | atom(),
max_public_epochid = ?NO_EPOCH :: {-1 | non_neg_integer(), binary()}, 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. %% @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). g_call(PidSpec, {list_all_projections, ProjType}, Timeout).
set_wedge_notify_pid(PidSpec, NotifyWedgeStateChanges) -> 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}; {reply, {{ok, find_all(Dir)}, LC2}, S};
handle_call({set_wedge_notify_pid, NotifyWedgeStateChanges}, _From, S) -> handle_call({set_wedge_notify_pid, NotifyWedgeStateChanges}, _From, S) ->
{reply, ok, S#state{wedge_notify_pid=NotifyWedgeStateChanges}}; {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) -> handle_call(_Request, _From, S) ->
Reply = {whaaaaaaaaaaaaazz, _Request}, Reply = {whaaaaaaaaaaaaazz, _Request},
{reply, Reply, S}. {reply, Reply, S}.

View file

@ -54,6 +54,9 @@ smoke_test() ->
ok = ?PS:write(a_pstore, private, P1c), ok = ?PS:write(a_pstore, private, P1c),
{error, written} = ?PS:write(a_pstore, private, P1a), {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 ok
after after
machi_flu_psup:stop_flu_package(a), machi_flu_psup:stop_flu_package(a),