etrap_server_impl.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,740 行 · 第 1/5 页
ERL
1,740 行
send_decision({Env, NewL2}, 'VoteRollback', rollback) end; _-> ?etr_log(?tr_get_etrap(Env), {pre_vote, rollback, NewL2}), %% timeout, reply rollback. send_decision({Env, NewL2}, 'VoteRollback', rollback) end; {rollback, VC} -> %% Rollback vote received. %% Send rollback to commit voters. N2 = ?etr_set_vc(NewL, VC), NewL2 = ?etr_set_status(N2,'StatusRolledBack'), ?etr_log(?tr_get_etrap(Env), {pre_vote, rollback, NewL2}), send_decision({Env, NewL2}, 'VoteRollback', rollback); {'EXCEPTION', E, VC, Obj} -> NewL2 = case is_heuristic(E) of true -> N2 = ?etr_set_vc(NewL, VC), N3 = ?etr_set_exc(N2, E), ?etr_set_raisedH(N3, Obj); _-> ?etr_set_vc(NewL, VC) end, ?etr_log(?tr_get_etrap(Env),{pre_vote,rollback, NewL2}), ?eval_debug_fun({?tr_get_etrap(Env), prepare2}, Env), send_decision({Env, NewL2}, {'EXCEPTION', E}, rollback); {failed, VC} -> NewL2 = ?etr_set_vc(NewL, VC), ?etr_log(?tr_get_etrap(Env),{pre_vote, rollback, NewL2}), send_decision({Env, NewL2}, {'EXCEPTION', ?tr_hazard}, rollback) end.%%-----------------------------------------------------------%%% function : rollback%% Arguments: Self - the servers own objref.%% {Env, Local} - the servers internal state.%% Returns : ok%% Effect : Rollback the transaction. If its status is%% "StatusRolledBack", this is not the first%% rollback call to this server. Might occur if%% the parent coordinator just recoeverd from a crasch.%% Exception: HeuristicCommit, HeuristicMixed, HeuristicHazard%%------------------------------------------------------------rollback(Self, {Env, Local}) -> case ?etr_get_status(Local) of 'StatusRolledBack' -> case ?etr_get_exc(Local) of void -> {stop, normal, ok, {Env, Local}}; %% Replace the reply above if allow synchronization %% Rolled back successfullly earlier.% case ?etr_get_sync(Local) of% [] ->% {stop, normal, ok, {Env, Local}};% _ ->% {reply, ok, {Env, Local}}% end; E -> %% Already rolledback with heuristic decision corba:raise(E) end; 'StatusPrepared' -> NewL = ?etr_set_status(Local, 'StatusRolledBack'), ?eval_debug_fun({?tr_get_etrap(Env), rollback}, Env), ?etr_log(?tr_get_etrap(Env), rollback), ?eval_debug_fun({?tr_get_etrap(Env), rollback2}, Env), send_decision({Env, NewL}, ok, rollback); 'StatusActive' -> NewL = ?etr_set_status(Local, 'StatusRolledBack'), ?etr_log(?tr_get_etrap(Env), {rollback, NewL}), send_info(?etr_get_members(NewL), 'CosTransactions_Resource', rollback), notify_subtrAware(rollback, ?etr_get_subAw(NewL), Self), {stop, normal, ok, {Env, NewL}}%% Replace the reply above if allow synchronization% case ?etr_get_sync(Local) of% [] ->% {stop, normal, ok, {NewEnv, NewL}};% _ ->% {reply, ok, {NewEnv, NewL}}% end; end.%%-----------------------------------------------------------%%% function : commit%% Arguments: Self - the servers own objref.%% {Env, Local} - the servers internal state.%% Returns : ok%% Effect : Commit the transaction.%% Exception: HeuristicRollback, HeuristicMixed, HeuristicHazard,%% NotPrepared%%------------------------------------------------------------commit(_Self, {Env, Local}) -> case ?etr_get_status(Local) of 'StatusPrepared' -> ?eval_debug_fun({?tr_get_etrap(Env), commit}, Env), NewL = ?etr_set_status(Local, 'StatusCommitted'), ?etr_log(?tr_get_etrap(Env),commit), ?eval_debug_fun({?tr_get_etrap(Env), commit2}, Env), send_decision({Env, NewL}, ok, commit); 'StatusCommitted' -> case ?etr_get_exc(Local) of void -> {stop, normal, ok, {Env, Local}}; %% Replace the reply above if allow synchronization% case ?etr_get_sync(Local) of% [] ->% {stop, normal, ok, {Env, Local}};% _ ->% {reply, ok, {Env, Local}}% end; E-> corba:raise(E) end; _ -> corba:raise(?tr_unprepared) end.%%-----------------------------------------------------------%%% function : commit_one_phase%% Arguments: Self - the servers own objref.%% {Env, Local} - the servers internal state.%% Returns : ok%% Effect : Commit the transaction using one-phase commit.%% Use ONLY when there is only one registered Resource.%% Exception: HeuristicRollback, HeuristicMixed, HeuristicHazard,%% TRANSACTION_ROLLEDBACK%%------------------------------------------------------------commit_one_phase(_Self, {Env, Local}) -> case ?etr_get_members(Local) of [Resource] -> case ?etr_get_status(Local) of 'StatusActive' -> %% Set status as prepared. No new Resources are allowed to register. NewL = ?etr_set_status(Local, 'StatusPrepared'), ?eval_debug_fun({?tr_get_etrap(Env), onePC}, Env), case try_timeout(?tr_get_alarm(Env)) of false -> case catch 'CosTransactions_Resource':prepare(Resource) of 'VoteCommit' -> case try_timeout(?tr_get_alarm(Env)) of false -> send_decision({Env, NewL}, ok, commit, [Resource]); _-> %% Timeout, rollback. send_decision({Env, NewL}, {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, rollback, [Resource]) end; 'VoteRollback' -> {stop, normal, {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, {Env, NewL}}; 'VoteReadOnly' -> {stop, normal, ok, {Env, NewL}}; {'EXCEPTION', E} when record(E, 'CosTransactions_HeuristicMixed') -> {reply, {'EXCEPTION', E}, {Env, NewL}}; {'EXCEPTION', E} when record(E, 'CosTransactions_HeuristicHazard') -> {reply, {'EXCEPTION', E}, {Env, NewL}}; Other -> ?tr_error_msg("Coordinator:prepare( ~p ) failed. REASON ~p~n", [Resource, Other]), {stop, normal, {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, {Env, NewL}} end; _-> NewL2 = ?etr_set_status(NewL, 'StatusRolledBack'), send_info(Resource, 'CosTransactions_Resource', rollback), {stop, normal, {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, {Env, NewL2}} %% Replace the reply above if allow synchronization% case ?etr_get_sync(NewL2) of% [] ->% send_info(Resource, 'CosTransactions_Resource', rollback),% {stop, normal, % {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, % {Env, NewL2}};% _ ->% send_info(Resource, 'CosTransactions_Resource', rollback),% {reply, % {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, % {Env, NewL2}}% end end; _ -> case evaluate_status(?etr_get_status(Local)) of commit -> test_exc(set_exception(?etr_get_exc_init(), ?etr_get_exc(Local)), commit, ok, {Env, Local}); _-> test_exc(set_exception(?etr_get_exc_init(), ?etr_get_exc(Local)), rollback, {'EXCEPTION', #'TRANSACTION_ROLLEDBACK'{completion_status=?COMPLETED_YES}}, {Env, Local}) end end; _-> {reply, {'EXCEPTION', #'NO_PERMISSION'{completion_status=?COMPLETED_NO}}, {Env, Local}} end.%%-----------------------------------------------------------%%% function : forget%% Arguments: Self - the servers own objref.%% State - the servers internal state.%% Returns : ok%% Effect : The resource can forget all knowledge about the%% transaction. Terminate this server.%%------------------------------------------------------------forget(_Self, {Env, Local}) -> ?etr_log(?tr_get_etrap(Env), forget_phase), send_forget(?etr_get_raisedH(Local), ?tr_get_etrap(Env)), {stop, normal, ok, {Env, ?etr_set_exc(Local, void)}}.%% Replace the reply above if allow synchronization% case ?etr_get_sync(Local) of% [] ->% {stop, normal, ok, {Env, ?etr_set_exc(Local, void)}};% _ ->% {reply, ok, {Env, ?etr_set_exc(Local, void)}}% end.%%--------------- Inherrit from CosTransactions::Coordinator - %%-----------------------------------------------------------%%% function : get_status%% Arguments: Self - its own object reference.%% State - Gen-Server State%% Returns : Status%% Effect : Returns the status of the transaction associated%% with the target object.%%------------------------------------------------------------get_status(_Self, {Env, Local}) -> {reply, ?etr_get_status(Local), {Env, Local}}.%%-----------------------------------------------------------%%% function : get_parent_status%% Arguments: Self - its own object reference.%% State - Gen-Server State%% Returns : Status%% Effect : Returns the status of the parent transaction%% associated with the target object. If top-level%% transaction equal to get_status.%%------------------------------------------------------------get_parent_status(_Self, {Env, Local}) -> case catch ?tr_get_parents(Env) of [] -> {reply, ?etr_get_status(Local), {Env, Local}}; [Parent|_] -> case catch 'CosTransactions_Coordinator':get_status(Parent) of {'EXCEPTION', _E} -> corba:raise(?tr_unavailable); {'EXIT', _} -> corba:raise(?tr_unavailable); Status -> {reply, Status, {Env, Local}} end end.%%-----------------------------------------------------------%%% function : get_top_level_status%% Arguments: Self - its own object reference.%% State - Gen-Server State%% Returns : Status%% Effect : Returns the status of the top-level transaction%% associated with the target object. If top-level%% transaction equal to get_status.%%------------------------------------------------------------get_top_level_status(_Self, {Env, Local}) -> case catch ?tr_get_parents(Env) of [] -> {reply, ?etr_get_status(Local), {Env, Local}}; Ancestrors -> case catch 'CosTransactions_Coordinator':get_status(lists:last(Ancestrors)) of {'EXCEPTION', _E} -> corba:raise(?tr_unavailable); {'EXIT', _} -> corba:raise(?tr_unavailable); Status -> {reply, Status, {Env, Local}} end end.%%-----------------------------------------------------------%%% function : is_same_transaction%% Arguments: Self - its own object reference.%% State - Gen-Server State%% Coordinator object reference%% Returns : boolean%% Effect : %%------------------------------------------------------------is_same_transaction(Self, {Env, Local}, Coordinator) -> type_check(?tr_get_typeCheck(Env), ?tr_Coordinator, "Coordinator:is_same_transaction", Coordinator), {reply, corba_object:is_equivalent(Self, Coordinator), {Env, Local}}.%%------------------------------------------------------------%% function : is_related_transaction%% Arguments: Self - its own object reference.%% State - Gen-Server State%% Coordinator object reference%% Returns : boolean%% Effect :%%------------------------------------------------------------is_related_transaction(_Self, {_Env, _Local}, _Coordinator) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_YES}).% type_check(?tr_get_typeCheck(Env), ?tr_Coordinator,% "Coordinator:is_related_transaction", Coordinator),% {reply, false, {Env, Local}}.%%------------------------------------------------------------%% function : is_ancestor_transaction%% Coordinator object reference%% Returns : boolean%% Effect :%%------------------------------------------------------------is_ancestor_transaction(_Self, {_Env, _Local}, _Coordinator) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_YES}).% type_check(?tr_get_typeCheck(Env), ?tr_Coordinator,% "Coordinator:is_ancestor_transaction", Coordinator),% {reply, false, {Env, Local}}.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?