diff --git a/include/leo_manager.hrl b/include/leo_manager.hrl index 04364d9..10e13cd 100644 --- a/include/leo_manager.hrl +++ b/include/leo_manager.hrl @@ -21,6 +21,13 @@ %% ------------------------------------------------------------------- -include_lib("eunit/include/eunit.hrl"). +-ifdef(namespaced_types). +-type mgr_dict() :: dict:dict(). +-else. +-type mgr_dict() :: dict(). +-endif. + + %% constants -define(SHUTDOWN_WAITING_TIME, 2000). -define(MAX_RESTART, 5). @@ -99,6 +106,7 @@ -define(CMD_ADD_BUCKET, "add-bucket"). -define(CMD_GET_BUCKETS, "get-buckets"). -define(CMD_GET_BUCKET_BY_ACCESS_KEY, "get-bucket"). +-define(CMD_SET_RED_METHOD, "set-redundancy-method"). -define(CMD_DELETE_BUCKET, "delete-bucket"). -define(CMD_CHANGE_BUCKET_OWNER, "chown-bucket"). -define(CMD_UPDATE_ACL, "update-acl"). @@ -115,8 +123,7 @@ -define(CMD_DIAGNOSE_DATA, "diagnose-data"). -define(CMD_DU, "du"). -define(CMD_WHEREIS, "whereis"). - -%% For Storage-MQ +%% For Storage MQ -define(CMD_MQ_STATS, "mq-stats"). -define(CMD_MQ_SUSPEND, "mq-suspend"). -define(CMD_MQ_RESUME, "mq-resume"). @@ -127,7 +134,6 @@ -define(CMD_BACKUP_MNESIA, "backup-mnesia"). -define(CMD_RESTORE_MNESIA, "restore-mnesia"). -define(CMD_UPDATE_MANAGERS, "update-managers"). - %% For Maintenance -define(CMD_RECOVER, "recover"). -define(CMD_HISTORY, "history"). @@ -135,7 +141,7 @@ -define(CMD_UPDATE_LOG_LEVEL, "update-log-level"). -define(CMD_UPDATE_CONSISTENCY_LEVEL, "update-consistency-level"). -define(CMD_UPDATE_PROP, "update-property"). - +-define(CMD_GEN_NFS_MNT_KEY, "gen-nfs-mnt-key"). %% For MDC-Replication -define(CMD_JOIN_CLUSTER, "join-cluster"). -define(CMD_REMOVE_CLUSTER, "remove-cluster"). @@ -149,15 +155,15 @@ -define(COMMANDS, [{?CMD_HELP, "help"}, {?CMD_QUIT, "quit"}, {?CMD_VERSION, "version"}, - {?CMD_STATUS, "status [|]"}, - {?CMD_HISTORY, "history"}, - {?CMD_DUMP_RING, "dump-ring (||)"}, + {?CMD_STATUS, "status [|]"}, + {?CMD_DUMP_RING, "dump-ring ||"}, {?CMD_UPDATE_LOG_LEVEL, "update-log-level (|) (debug|info|warn|error)"}, {?CMD_UPDATE_CONSISTENCY_LEVEL, "update-consistency-level (|) "}, %% for Cluster {?CMD_WHEREIS, "whereis "}, {?CMD_RECOVER, lists:append( ["recover file ", ?CRLF, + "recover dir []", ?CRLF, "recover node ", ?CRLF, "recover ring ", ?CRLF, "recover cluster " @@ -170,14 +176,14 @@ {?CMD_REBALANCE, "rebalance"}, %% for Storage {?CMD_COMPACT, lists:append( - ["compact start (all|) []", ?CRLF, + ["compact start all| []", ?CRLF, "compact suspend ", ?CRLF, - "compact resume ", ?CRLF, - "compact status " + "compact resume ", ?CRLF, + "compact status " ])}, {?CMD_DIAGNOSE_DATA, "diagnose-data "}, {?CMD_DU, "du "}, - %% for Storage-mq + %% for Storage MQ {?CMD_MQ_STATS, "mq-stats "}, {?CMD_MQ_SUSPEND, "mq-suspend "}, {?CMD_MQ_RESUME, "mq-resume "}, @@ -204,6 +210,8 @@ {?CMD_GET_BUCKETS, "get-buckets"}, {?CMD_GET_BUCKET_BY_ACCESS_KEY, "get-bucket "}, {?CMD_CHANGE_BUCKET_OWNER, "chown-bucket "}, + {?CMD_SET_RED_METHOD, "set-redundancy-method "}, + {?CMD_GEN_NFS_MNT_KEY, "gen-nfs-mnt-key "}, %% - acl-related {?CMD_UPDATE_ACL, "update-acl private|public-read|public-read-write"}, %% - multi-dc replication @@ -230,12 +238,12 @@ -define(COMPACT_STATUS, "status"). -define(COMPACT_TARGET_ALL, "all"). - %% recover type -define(RECOVER_FILE, "file"). -define(RECOVER_NODE, "node"). -define(RECOVER_RING, "ring"). -define(RECOVER_REMOTE_CLUSTER, "cluster"). +-define(RECOVER_DIR, "dir"). %% membership -define(DEF_NUM_OF_ERROR_COUNT, 2). @@ -286,16 +294,16 @@ -define(ERROR_FAILED_UPDATE_MANAGERS, "Failed to update the manager nodes"). -define(ERROR_COULD_NOT_GET_CONF, "Could not get the system-config"). -define(ERROR_MEMBER_NOT_FOUND, "Member not found"). --define(ERROR_COULD_NOT_GET_MEMBER, "Could not get member"). +-define(ERROR_COULD_NOT_GET_MEMBER, "Could not get members (storage-nodes)"). -define(ERROR_COULD_NOT_GET_GATEWAY, "Could not get gateway(s)"). -define(ERROR_NOT_NEED_REBALANCE, "Not need rebalance"). --define(ERROR_FAIL_REBALANCE, "Failed to do data-rebalance"). --define(ERROR_FAIL_TO_ASSIGN_NODE, "Failed to assign node(s)"). --define(ERROR_FAIL_TO_REMOVE_NODE, "Failed to remove a node"). --define(ERROR_FAIL_TO_SYNCHRONIZE_RING, "Failed to synchronize RING"). --define(ERROR_FAIL_TO_UPDATE_ACL, "Failed to update acl of a bucket"). --define(ERROR_FAIL_ACCESS_MNESIA, "Failed to access mnesia"). --define(ERROR_ALREADY_HAS_SAME_CLUSTER, "Already has a same name of cluster"). +-define(ERROR_FAIL_REBALANCE, "Fail rebalance"). +-define(ERROR_FAIL_TO_ASSIGN_NODE, "Fail to assign node(s)"). +-define(ERROR_FAIL_TO_REMOVE_NODE, "Fail to remove a node"). +-define(ERROR_FAIL_TO_SYNCHRONIZE_RING, "Fail to synchronize RING"). +-define(ERROR_FAIL_TO_UPDATE_ACL, "Fail to update acl of a bucket"). +-define(ERROR_FAIL_ACCESS_MNESIA, "Fail to access mnesia"). +-define(ERROR_ALREADY_HAS_SAME_CLUSTER, "Already has a same neme of cluster"). -define(ERROR_COULD_NOT_GET_CLUSTER_INFO,"Could not get cluster info"). -define(ERROR_OVER_MAX_CLUSTERS, "Over max number of clusters"). -define(ERROR_UPDATED_SYSTEM_CONF, "Updated the system configuration"). @@ -307,7 +315,6 @@ -define(MOD_TEXT_FORMATTER, 'leo_manager_formatter_text'). -define(MOD_JSON_FORMATTER, 'leo_manager_formatter_json'). - %% test values and default values -define(TEST_USER_ID, <<"_test_leofs">>). -define(TEST_ACCESS_KEY, <<"05236">>). @@ -317,14 +324,35 @@ -define(DEF_ENDPOINT_2, <<"s3.amazonaws.com">>). -define(PROP_MNESIA_NODES, 'leo_manager_mnesia_nodes'). +-define(DEF_MNESIA_DIR, "./work/mnesia/127.0.0.1"). +-define(DEF_QUEUE_DIR, "./work/queue/"). +-define(DEF_LOG_DIR, "./log/"). + +%% Command history related +-define(LOG_GROUP_ID_HISTORY, 'log_grp_history_log'). +-define(LOG_ID_HISTORY, 'log_id_history_log'). +-define(LOG_FILENAME_HISTORY, "cmd_history"). +-define(put_cmd_history(_CmdBody), + begin + leo_logger_client_base:append( + {?LOG_ID_HISTORY, + #message_log{format = "~s\t~w\t~s", + message = [leo_date:date_format(), + leo_date:clock(), + binary_to_list(_CmdBody) + ]} + }) + end). + %% MQ related: -define(QUEUE_ID_FAIL_REBALANCE, 'mq_fail_rebalance'). -%% records -%% +%% --------------------------------------------------------- +%% RECORDS +%% --------------------------------------------------------- -define(AUTH_NOT_YET, 0). -define(AUTH_USERID_1, 1). -define(AUTH_USERID_2, 2). @@ -373,9 +401,9 @@ timestamp = 0 :: pos_integer() }). - -%% macros -%% +%% --------------------------------------------------------- +%% MACROS +%% --------------------------------------------------------- -define(env_mode_of_manager(), case application:get_env(leo_manager, manager_mode) of {ok, EnvModeOfManager} -> EnvModeOfManager; @@ -456,7 +484,6 @@ _ -> true end). --define(DEF_LOG_DIR, "./log/"). -define(env_log_dir(), case application:get_env(leo_manager, log_appender) of {ok, [{file, Options}|_]} -> @@ -465,7 +492,6 @@ ?DEF_LOG_DIR end). --define(DEF_QUEUE_DIR, "./work/queue/"). -define(env_queue_dir(), case application:get_env(leo_manager, queue_dir) of {ok, _EnvQueueDir} -> @@ -474,8 +500,6 @@ ?DEF_QUEUE_DIR end). --define(DEF_MNESIA_DIR, "./work/mnesia/127.0.0.1"). - %% @doc Plugin-related macros %% @@ -496,3 +520,15 @@ %% -define(BOOL_TO_ENABLE, [{true, enabled}, {false, disabled}]). + +%% @doc Retrieve tokens +%% +-define(get_tokens(_Option,_ErrMsg), + begin + case string:tokens(binary_to_list(_Option), ?COMMAND_DELIMITER) of + [] -> + {error,_ErrMsg}; + _Tokens -> + {ok, _Tokens} + end + end). diff --git a/priv/leo_manager_0.schema b/priv/leo_manager_0.schema index 3bb627c..adbfa4f 100644 --- a/priv/leo_manager_0.schema +++ b/priv/leo_manager_0.schema @@ -97,7 +97,7 @@ "leo_manager.system_version", [ {datatype, string}, - {default, "1.2.18"} + {default, "1.2.20"} ]}. %% @doc Mode of Manager: [master|slave] diff --git a/priv/leo_manager_1.schema b/priv/leo_manager_1.schema index 140cc32..5a3a039 100644 --- a/priv/leo_manager_1.schema +++ b/priv/leo_manager_1.schema @@ -97,7 +97,7 @@ "leo_manager.system_version", [ {datatype, string}, - {default, "1.2.18"} + {default, "1.2.20"} ]}. %% @doc Mode of Manager: [master, slave] diff --git a/rebar.config b/rebar.config index 75feb3e..ab1e624 100644 --- a/rebar.config +++ b/rebar.config @@ -3,7 +3,7 @@ %% %% Leo Manager %% -%% Copyright (c) 2012-2015 Rakuten, Inc. +%% Copyright (c) 2012-2016 Rakuten, Inc. %% %% This file is provided to you under the Apache License, %% Version 2.0 (the "License"); you may not use this file @@ -20,17 +20,17 @@ %% under the License. %% %%====================================================================== -{require_otp_vsn, "R16B*|17"}. +{require_otp_vsn, "R16B*|17|18"}. {deps, [ {leo_commons, ".*", {git, "https://github.com/leo-project/leo_commons.git", {tag, "1.1.6"}}}, {leo_logger, ".*", {git, "https://github.com/leo-project/leo_logger.git", {tag, "1.2.2"}}}, - {leo_object_storage, ".*", {git, "https://github.com/leo-project/leo_object_storage.git", {tag, "1.2.12"}}}, - {leo_redundant_manager, ".*", {git, "https://github.com/leo-project/leo_redundant_manager.git", {tag, "1.9.22"}}}, + {leo_object_storage, ".*", {git, "https://github.com/leo-project/leo_object_storage.git", {tag, "1.2.21"}}}, + {leo_redundant_manager, ".*", {git, "https://github.com/leo-project/leo_redundant_manager.git", {tag, "1.9.25"}}}, {leo_rpc, ".*", {git, "https://github.com/leo-project/leo_rpc.git", {tag, "0.10.7"}}}, - {leo_statistics, ".*", {git, "https://github.com/leo-project/leo_statistics.git", {tag, "1.1.10"}}}, - {leo_s3_libs, ".*", {git, "https://github.com/leo-project/leo_s3_libs.git", {tag, "1.1.10"}}}, - {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.14.4"}}}, + {leo_statistics, ".*", {git, "https://github.com/leo-project/leo_statistics.git", {tag, "1.1.11"}}}, + {leo_s3_libs, ".*", {git, "https://github.com/leo-project/leo_s3_libs.git", {tag, "1.1.12"}}}, + {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.14.7"}}}, {meck, ".*", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.2"}}} ]}. @@ -40,7 +40,9 @@ %% warnings_as_errors, warn_shadow_vars, warn_export_vars, - warn_export_all]}. + warn_export_all, + {platform_define, "^[0-9]+", namespaced_types} + ]}. {xref_checks, [undefined_function_calls]}. {cover_enabled, true}. {clean_files, []}. diff --git a/src/leo_manager.app.src b/src/leo_manager.app.src index eefcd0c..fa54d5e 100644 --- a/src/leo_manager.app.src +++ b/src/leo_manager.app.src @@ -3,7 +3,7 @@ %% %% Leo Manager %% -%% Copyright (c) 2012-2015 Rakuten, Inc. +%% Copyright (c) 2012-2016 Rakuten, Inc. %% %% This file is provided to you under the Apache License, %% Version 2.0 (the "License"); you may not use this file @@ -23,12 +23,12 @@ {application, leo_manager, [ {description, "LeoFS Manager"}, - {vsn, "1.2.18"}, + {vsn, "1.2.20"}, {id, "leo_manager"}, {registered, []}, {applications, [kernel, stdlib, crypto]}, {mod, {leo_manager_app, []}}, - {env, [{system_version,"1.0.0"}, + {env, [{system_version,"1.2.20"}, {system, [{dc_id,'dc_1'}, {cluster_id,'leofs_1'}, {n, 1}, diff --git a/src/leo_manager_api.erl b/src/leo_manager_api.erl index 738629e..e8ad4ea 100644 --- a/src/leo_manager_api.erl +++ b/src/leo_manager_api.erl @@ -904,6 +904,22 @@ rebalance(Socket) -> {error, _} -> {error, ?ERROR_NOT_NEED_REBALANCE}; {State, Nodes} -> + {CanTakeover, TookOverNode} = + case (erlang:length(Nodes) == 2) of + true -> + [{State_1,Node_1},{State_2,Node_2}] = Nodes, + case State_1 of + attached when State_2 == detached -> + {true, Node_1}; + detached when State_2 == attached -> + {true, Node_2}; + _ -> + {false, undefined} + end; + false -> + {false, undefined} + end, + %% Execute the data-reblanace ok = output_message_to_console( Socket, << "Generating rebalance-list..." >>), @@ -924,7 +940,8 @@ rebalance(Socket) -> ok = output_message_to_console( Socket, <<"Distributing rebalance-list to the storage nodes">>), ok = rebalance_4(self(), MembersCur, RebalanceProcInfo), - rebalance_4_loop(Socket, 0, length(MembersCur)); + rebalance_4_loop(Socket, 0, length(MembersCur), + {CanTakeover, TookOverNode}); {error, Cause}-> {error, Cause} end; @@ -966,7 +983,7 @@ rebalance_1(true, Nodes) -> end. %% @private --spec(rebalance_2(dict(), [{integer(), atom()}]) -> +-spec(rebalance_2(mgr_dict(), [{integer(), atom()}]) -> {ok, [{integer(), atom()}]} | {erorr, any()}). rebalance_2(TblDict, []) -> Ret = case dict:to_list(TblDict) of @@ -1079,9 +1096,12 @@ rebalance_4(Pid, [#member{node = Node}|T], RebalanceProcInfo) -> %% @doc receive the results of rebalance %% @private -rebalance_4_loop(_Socket, TotalMembers, TotalMembers) -> +rebalance_4_loop(_Socket, TotalMembers, TotalMembers, + {true, TookOverNode}) -> + recover(?RECOVER_NODE, TookOverNode, true); +rebalance_4_loop(_Socket, TotalMembers, TotalMembers,_TakeoverInfo) -> ok; -rebalance_4_loop(Socket, NumOfNodes, TotalMembers) -> +rebalance_4_loop(Socket, NumOfNodes, TotalMembers, TakeoverInfo) -> receive Msg -> {Node_1, State} = @@ -1116,7 +1136,7 @@ rebalance_4_loop(Socket, NumOfNodes, TotalMembers) -> Ratio = lists:append([integer_to_list(round((NewNumOfNodes / TotalMembers) * 100)), "%"]), SendMsg = lists:append([string:right(Ratio, 5), " - ", atom_to_list(Node_1)]), ok = output_message_to_console(Socket, State, list_to_binary(SendMsg)), - rebalance_4_loop(Socket, NewNumOfNodes, TotalMembers) + rebalance_4_loop(Socket, NewNumOfNodes, TotalMembers, TakeoverInfo) after infinity -> ok diff --git a/src/leo_manager_console.erl b/src/leo_manager_console.erl index 3aee6f1..455a4e3 100644 --- a/src/leo_manager_console.erl +++ b/src/leo_manager_console.erl @@ -33,6 +33,7 @@ %% API -export([start_link/2, start_link/3, stop/0]). -export([init/1, handle_call/3]). +-export([whereis/1]). %%---------------------------------------------------------------------- @@ -98,9 +99,9 @@ handle_call(_Socket, ?AUTHORIZED, #state{formatter = Formatter} = State) -> %% Command: "_authorized_" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = case login(Command, Option) of + Reply = case login(Option) of {ok, User, Credential} -> Formatter:login(User, Credential); {error, Cause} -> @@ -111,10 +112,10 @@ handle_call(_Socket, <> = Command, %% Command: "status" %% Command: "status ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case status(Command, Option) of + case get_status(Option) of {ok, {node_list, Props}} -> Formatter:system_info_and_nodes_stat(Props); {ok, {?SERVER_TYPE_GATEWAY = Type, NodeStatus}} -> @@ -130,10 +131,10 @@ handle_call(_Socket, <> = Command, %% Command : "detach ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case detach(Command, Option) of + case detach(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -145,10 +146,10 @@ handle_call(_Socket, <> = Command, %% Command: "suspend ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case suspend(Command, Option) of + case suspend(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -160,10 +161,10 @@ handle_call(_Socket, <> = Command, %% Command: "resume ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case resume(Command, Option) of + case resume(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -175,10 +176,10 @@ handle_call(_Socket, <> = Command, %% Command: "rollback ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case rollback(Command, Option) of + case rollback(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -190,32 +191,32 @@ handle_call(_Socket, <> = Command, %% Command: "start" -handle_call(Socket, <> = Command, +handle_call(Socket, <>, #state{formatter = Formatter} = State) -> - Reply = start(Socket, Command, Formatter), + Reply = start(Socket, Formatter), {reply, Reply, State}; -handle_call(Socket, <> = Command, +handle_call(Socket, <>, #state{formatter = Formatter} = State) -> - Reply = start(Socket, Command, Formatter), + Reply = start(Socket, Formatter), {reply, Reply, State}; %% Command: "rebalance" -handle_call(Socket, <> = Command, +handle_call(Socket, <>, #state{formatter = Formatter} = State) -> - Reply = rebalance(Socket, Command, Formatter), + Reply = rebalance(Socket, Formatter), {reply, Reply, State}; -handle_call(Socket, <> = Command, +handle_call(Socket, <>, #state{formatter = Formatter} = State) -> - Reply = rebalance(Socket, Command, Formatter), + Reply = rebalance(Socket, Formatter), {reply, Reply, State}; %% Command: "update-property" for watchdog -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_property(Command, Option) of + case update_property(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -229,10 +230,10 @@ handle_call(_Socket, <> = Command, %% Operation-2 %%---------------------------------------------------------------------- %% Command: "du ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case du(Command, Option) of + case du(Option) of {ok, {Option1, StorageStats}} -> Formatter:du(Option1, StorageStats); {error, Cause} -> @@ -244,10 +245,10 @@ handle_call(_Socket, <> = Command, %% Command: "compact ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case compact(Command, Option) of + case compact(Option) of ok -> Formatter:ok(); {ok, Status} -> @@ -260,10 +261,10 @@ handle_call(_Socket, <> = Command, {reply, Reply, State}; %% Command: "diagnose-data ${NODE_NAME}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case diagnose_data(Command, Option) of + case diagnose_data(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -277,10 +278,10 @@ handle_call(_Socket, <> = Command, %%---------------------------------------------------------------------- %% Operation for MQ %%---------------------------------------------------------------------- -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case mq_stats(Command, Option) of + case mq_stats(Option) of {ok, Stats} -> Formatter:mq_stats(Stats); {error, Cause} -> @@ -290,10 +291,10 @@ handle_call(_Socket, <> = Command, Reply = invoke(?CMD_MQ_STATS, Formatter, Fun), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case mq_suspend(Command, Option) of + case mq_suspend(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -303,10 +304,10 @@ handle_call(_Socket, <> = Command, Reply = invoke(?CMD_MQ_SUSPEND, Formatter, Fun), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case mq_resume(Command, Option) of + case mq_resume(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -321,10 +322,10 @@ handle_call(_Socket, <> = Command, %% Operation-3 %%---------------------------------------------------------------------- %% Command: "create-user ${USER_ID} ${PASSWORD}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case create_user(Command, Option) of + case create_user(Option) of {ok, PropList} -> AccessKeyId = leo_misc:get_value('access_key_id', PropList), SecretAccessKey = leo_misc:get_value('secret_access_key', PropList), @@ -338,10 +339,10 @@ handle_call(_Socket, <> = Command, %% Command: "update-user-role ${USER_ID} ${ROLE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_user_role(Command, Option) of + case update_user_role(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -353,10 +354,10 @@ handle_call(_Socket, <> = Command, %% Command: "update-user-password ${USER_ID} ${PASSWORD}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_user_password(Command, Option) of + case update_user_password(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -368,10 +369,10 @@ handle_call(_Socket, <> = Command, %% Command: "delete-user ${USER_ID} ${PASSWORD}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case delete_user(Command, Option) of + case delete_user(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -383,21 +384,21 @@ handle_call(_Socket, <> = Command, %% Command: "get-users" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_users(Command, Formatter), + Reply = get_users(Formatter), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_users(Command, Formatter), + Reply = get_users(Formatter), {reply, Reply, State}; %% Command: "end-endpoint ${END_POINT}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case set_endpoint(Command, Option) of + case set_endpoint(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -407,10 +408,10 @@ handle_call(_Socket, <> = Command, Reply = invoke(?CMD_ADD_ENDPOINT, Formatter, Fun), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case set_endpoint(Command, Option) of + case set_endpoint(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -422,21 +423,21 @@ handle_call(_Socket, <> = Command, %% Command: "get-endpoints" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_endpoints(Command, Formatter), + Reply = get_endpoints(Formatter), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_endpoints(Command, Formatter), + Reply = get_endpoints(Formatter), {reply, Reply, State}; %% Command: "del-endpoint ${end_point}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case delete_endpoint(Command, Option) of + case delete_endpoint(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -448,10 +449,10 @@ handle_call(_Socket, <> = Command, %% Command: "add-buckets ${bucket} ${access-key-id}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case add_bucket(Command, Option) of + case add_bucket(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -463,10 +464,10 @@ handle_call(_Socket, <> = Command, %% Command: "delete-buckets ${bucket} ${access-key-id}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case delete_bucket(Command, Option) of + case delete_bucket(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -478,21 +479,21 @@ handle_call(_Socket, <> = Command, %% Command: "get-buckets" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_buckets(Command, Formatter), + Reply = get_buckets(Formatter), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = get_buckets(Command, Formatter), + Reply = get_buckets(Formatter), {reply, Reply, State}; %% Command: "get-bucket ${access-key-id}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case get_bucket_by_access_key(Command, Option) of + case get_bucket_by_access_key(Option) of {ok, Buckets} -> Formatter:bucket_by_access_key(Buckets); not_found -> @@ -506,10 +507,10 @@ handle_call(_Socket, <> = %% Command: "chown-bucket ${bucket} ${new-access-key-id}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case change_bucket_owner(Command, Option) of + case change_bucket_owner(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -521,10 +522,10 @@ handle_call(_Socket, <> = Comma %% Command: "update-acl ${bucket} ${canned_acl}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_acl(Command, Option) of + case update_acl(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -536,10 +537,10 @@ handle_call(_Socket, <> = Command, %% Command: "whereis ${PATH}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case whereis(Command, Option) of + case ?MODULE:whereis(Option) of {ok, AssignedInfo} -> Formatter:whereis(AssignedInfo); {error, Cause} -> @@ -551,10 +552,10 @@ handle_call(_Socket, <> = Command, %% Command: "recover file|node ${PATH}|${NODE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case recover(Command, Option) of + case recover(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -566,10 +567,10 @@ handle_call(_Socket, <> = Command, %% Command: "purge ${PATH}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case purge(Command, Option) of + case purge(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -581,10 +582,10 @@ handle_call(_Socket, <> = Command, %% Command: "remove ${GATEWAY_NODE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case remove(Command, Option) of + case remove(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -596,10 +597,10 @@ handle_call(_Socket, <> = Command, %% Command: "backup-mnesia ${MNESIA_BACKUPFILE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case backup_mnesia(Command, Option) of + case backup_mnesia(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -611,10 +612,10 @@ handle_call(_Socket, <> = Command, %% Command: "restore-mnesia ${MNESIA_BACKUPFILE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case restore_mnesia(Command, Option) of + case restore_mnesia(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -626,10 +627,10 @@ handle_call(_Socket, <> = Command, %% Command: "update-managers ${MANAGER_MASTER} ${MANAGER_SLAVE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_manager_nodes(Command, Option) of + case update_manager_nodes(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -657,10 +658,10 @@ handle_call(_Socket, <>, #state{formatter = Formatter} = St %% Command: "dump-ring ${NODE}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case dump_ring(Command, Option) of + case dump_ring(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -672,10 +673,10 @@ handle_call(_Socket, <> = Command, %% Command: "update-log-level ${NODE} ${LOG_LEVEL}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_log_level(Command, Option) of + case update_log_level(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -686,10 +687,10 @@ handle_call(_Socket, <> = Command, {reply, Reply, State}; %% Command: "update-consistency-level ${NODE} ${WRITE_QUORUM} ${READ_QUORUM} ${DELETE_QUORUM}" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case update_consistency_level(Command, Option) of + case update_consistency_level(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -704,10 +705,10 @@ handle_call(_Socket, <> = %% Operation-4 %%---------------------------------------------------------------------- %% Command: "join-cluster [${REMOTE_MANAGER_NODE}, ${REMOTE_MANAGER_NODE}, ...]" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case join_cluster(Command, Option) of + case join_cluster(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -719,10 +720,10 @@ handle_call(_Socket, <> = Command, %% Command: "remove-cluster [${REMOTE_MANAGER_NODE}, ${REMOTE_MANAGER_NODE}, ...]" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> Fun = fun() -> - case remove_cluster(Command, Option) of + case remove_cluster(Option) of ok -> Formatter:ok(); {error, Cause} -> @@ -734,13 +735,13 @@ handle_call(_Socket, <> = Command, %% Command: "cluster-status" -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = cluster_status(Command, Formatter), + Reply = cluster_status(Formatter), {reply, Reply, State}; -handle_call(_Socket, <> = Command, +handle_call(_Socket, <>, #state{formatter = Formatter} = State) -> - Reply = cluster_status(Command, Formatter), + Reply = cluster_status(Formatter), {reply, Reply, State}; @@ -787,14 +788,14 @@ version(Formatter) -> %% @doc Launch the LeoFS %% @private -start(Socket, Command, Formatter) -> +start(Socket, Formatter) -> Socket_1 = case Formatter of ?MOD_TEXT_FORMATTER -> Socket; _ -> null end, Fun = fun() -> - case start(Socket_1, Command) of + case start(Socket_1) of ok -> Formatter:ok(); {error, {bad_nodes, BadNodes}} -> @@ -808,8 +809,7 @@ start(Socket, Command, Formatter) -> %% @doc Execute the rebalance %% @private -rebalance(Socket, Command, Formatter) -> - _ = leo_manager_mnesia:insert_history(Command), +rebalance(Socket, Formatter) -> Socket_1 = case Formatter of ?MOD_TEXT_FORMATTER -> Socket; _ -> null @@ -844,8 +844,7 @@ rebalance(Socket, Command, Formatter) -> %% $ leofs-adm update-property watchdog.cluster_interval %%

%% @private -update_property(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +update_property(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node, PropertyName, PropertyValue|_] -> update_property_1(Node, PropertyName, PropertyValue); @@ -986,10 +985,9 @@ update_property_2(Node, Method, Args) -> %% @doc Backup files of manager's mnesia %% @private --spec(backup_mnesia(binary(), binary()) -> +-spec(backup_mnesia(binary()) -> ok | {error, any()}). -backup_mnesia(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +backup_mnesia(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1000,10 +998,9 @@ backup_mnesia(CmdBody, Option) -> %% @doc Restore mnesia from backup files %% @private --spec(restore_mnesia(binary(), binary()) -> +-spec(restore_mnesia(binary()) -> ok | {error, any()}). -restore_mnesia(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +restore_mnesia(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1014,10 +1011,9 @@ restore_mnesia(CmdBody, Option) -> %% @doc Update manager's node to alternate node %% @private --spec(update_manager_nodes(binary(), binary()) -> +-spec(update_manager_nodes(binary()) -> ok | {error, any()}). -update_manager_nodes(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +update_manager_nodes(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Master, Slave|_] -> leo_manager_api:update_manager_nodes( @@ -1029,8 +1025,7 @@ update_manager_nodes(CmdBody, Option) -> %% @doc Output ring of a targe node %% @private -dump_ring(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +dump_ring(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node|_] -> rpc:call(list_to_atom(Node), leo_redundant_manager_api, dump, [both]); @@ -1041,8 +1036,7 @@ dump_ring(CmdBody, Option) -> %% @doc Updaet a log level of a node %% @private -update_log_level(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +update_log_level(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node, LogLevel|_] -> {CanSendMsg, LogLevel_1} = @@ -1071,8 +1065,7 @@ update_log_level(CmdBody, Option) -> %% @doc Update a consistency level of a node %% @private -update_consistency_level(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +update_consistency_level(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [WStr, RStr, DStr|_] -> Ret = case catch list_to_integer(WStr) of @@ -1114,9 +1107,7 @@ update_consistency_level_1({ok, {W, R, D} = ConsistencyLevel}) -> %% @doc Join a cluster %% @private -join_cluster(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +join_cluster(Option) -> case leo_cluster_tbl_conf:get() of {ok, #?SYSTEM_CONF{max_mdc_targets = MaxTargets}} -> case leo_mdcr_tbl_cluster_stat:all() of @@ -1214,8 +1205,7 @@ join_cluster_2([Node|Rest] = RemoteNodes) -> %% @doc Remove a cluster %% @private -remove_cluster(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +remove_cluster(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1237,8 +1227,7 @@ remove_cluster_1([Node|Rest]) -> %% @doc Retrieve cluster-statuses %% @private -cluster_status(Command, Formatter) -> - _ = leo_manager_mnesia:insert_history(Command), +cluster_status(Formatter) -> Fun = fun() -> case cluster_status_1() of {ok, ResL} -> @@ -1306,10 +1295,9 @@ version() -> %% @doc Exec login %% @private --spec(login(binary(), binary()) -> +-spec(login(binary()) -> {ok, #?S3_USER{}, [tuple()]} | {error, any()}). -login(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +login(Option) -> Token = string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER), case (erlang:length(Token) == 2) of @@ -1336,10 +1324,11 @@ login(CmdBody, Option) -> %% @doc Retrieve state of each node %% @private --spec(status(binary(), binary()) -> +-spec(get_status(binary()) -> {ok, any()} | {error, any()}). -status(_CmdBody, Option) -> - Token = string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER), +get_status(Option) -> + Token = string:tokens( + binary_to_list(Option), ?COMMAND_DELIMITER), case (erlang:length(Token) == 0) of true -> @@ -1363,6 +1352,7 @@ status(_CmdBody, Option) -> status({node_state, Node}) end. +%% @private status(node_list) -> case leo_cluster_tbl_conf:get() of {ok, SystemConf} -> @@ -1413,7 +1403,6 @@ status(node_list) -> {error, Cause} -> {error, Cause} end; - status({node_state, Node}) -> case leo_manager_api:get_node_status(Node) of {ok, {Type, State}} -> @@ -1425,11 +1414,9 @@ status({node_state, Node}) -> %% @doc Launch the storage cluster %% @private --spec(start(port()|null, binary()) -> +-spec(start(port()|null) -> ok | {error, any()}). -start(Socket, CmdBody) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +start(Socket) -> case leo_manager_mnesia:get_storage_nodes_all() of {ok, _} -> case leo_manager_api:get_system_status() of @@ -1457,10 +1444,9 @@ start(Socket, CmdBody) -> %% @doc Detach a storage-node %% @private --spec(detach(binary(), binary()) -> +-spec(detach(binary()) -> ok | {error, {atom(), string()}} | {error, any()}). -detach(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +detach(Option) -> {ok, SystemConf} = leo_cluster_tbl_conf:get(), case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of @@ -1552,11 +1538,9 @@ allow_to_detach_node_2(N, NodeAtom) -> %% @doc Suspend a storage-node %% @private --spec(suspend(binary(), binary()) -> +-spec(suspend(binary()) -> ok | {error, any()}). -suspend(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +suspend(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1573,11 +1557,9 @@ suspend(CmdBody, Option) -> %% @doc Resume a storage-node %% @private --spec(resume(binary(), binary()) -> +-spec(resume(binary()) -> ok | {error, any()}). -resume(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +resume(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1600,11 +1582,9 @@ resume(CmdBody, Option) -> %% @doc Rollback storage-node from detach to running %% @private --spec(rollback(binary(), binary()) -> +-spec(rollback(binary()) -> ok | {error, any()}). -rollback(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +rollback(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1623,11 +1603,9 @@ rollback(CmdBody, Option) -> %% @doc Purge an object from the cache %% @private --spec(purge(binary(), binary()) -> +-spec(purge(binary()) -> ok | {error, any()}). -purge(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +purge(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_INVALID_PATH}; @@ -1638,11 +1616,9 @@ purge(CmdBody, Option) -> %% @doc remove a gateway-node %% @private --spec(remove(binary(), binary()) -> +-spec(remove(binary()) -> ok | {error, any()}). -remove(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +remove(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_INVALID_PATH}; @@ -1653,11 +1629,9 @@ remove(CmdBody, Option) -> %% @doc Retrieve the storage stats %% @private --spec(du(binary(), binary()) -> +-spec(du(binary()) -> ok | {error, any()}). -du(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +du(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NOT_SPECIFIED_NODE}; @@ -1691,11 +1665,9 @@ du(CmdBody, Option) -> %% @doc Compact target node of objects into the object-storages %% @private --spec(compact(binary(), binary()) -> +-spec(compact(binary()) -> ok | {ok,_} | {error, any()}). -compact(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +compact(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_NO_CMODE_SPECIFIED}; @@ -1753,8 +1725,7 @@ compact(_,_,_,_) -> %% @doc Execute data-diagnosis -diagnose_data(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +diagnose_data(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node|_] -> leo_manager_api:diagnose_data(list_to_atom(Node)); @@ -1764,8 +1735,7 @@ diagnose_data(CmdBody, Option) -> %% @doc Execute data-diagnosis -mq_stats(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +mq_stats(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node|_] -> leo_manager_api:mq_stats(list_to_atom(Node)); @@ -1775,8 +1745,7 @@ mq_stats(CmdBody, Option) -> %% @doc Execute data-diagnosis -mq_suspend(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +mq_suspend(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node, MQId|_] -> leo_manager_api:mq_suspend( @@ -1787,8 +1756,7 @@ mq_suspend(CmdBody, Option) -> %% @doc Execute data-diagnosis -mq_resume(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +mq_resume(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Node, MQId|_] -> leo_manager_api:mq_resume( @@ -1800,10 +1768,9 @@ mq_resume(CmdBody, Option) -> %% @doc Retrieve information of an Assigned object %% @private --spec(whereis(binary(), binary()) -> +-spec(whereis(binary()) -> ok | {error, any()}). -whereis(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), +whereis(Option) -> case string:tokens(binary_to_list(Option), ?CRLF) of [] -> {error, ?ERROR_INVALID_PATH}; @@ -1833,11 +1800,9 @@ escape_large_obj_sep(SrcKey) -> %% @doc Recover object(s) by a key/node %% @private --spec(recover(binary(), binary()) -> +-spec(recover(binary()) -> ok | {error, any()}). -recover(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +recover(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_INVALID_PATH}; @@ -1857,11 +1822,9 @@ recover(CmdBody, Option) -> %% @doc Create a user account (S3) %% @private --spec(create_user(binary(), binary()) -> +-spec(create_user(binary()) -> {ok, [tuple()]} | {error, any()}). -create_user(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +create_user(Option) -> Ret = case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [UserId] -> {ok, {list_to_binary(UserId), <<>>}}; @@ -1899,11 +1862,9 @@ create_user(CmdBody, Option) -> %% @doc Update user's role-id %% @private --spec(update_user_role(binary(), binary()) -> +-spec(update_user_role(binary()) -> ok | {error, any()}). -update_user_role(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +update_user_role(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [UserId, RoleId|_] -> case leo_s3_user:update(#?S3_USER{id = list_to_binary(UserId), @@ -1921,11 +1882,9 @@ update_user_role(CmdBody, Option) -> %% @doc Update user's password %% @private --spec(update_user_password(binary(), binary()) -> +-spec(update_user_password(binary()) -> ok | {error, any()}). -update_user_password(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +update_user_password(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [UserId, Password|_] -> UserIdBin = list_to_binary(UserId), @@ -1947,11 +1906,9 @@ update_user_password(CmdBody, Option) -> %% @doc Remove a user %% @private --spec(delete_user(binary(), binary()) -> +-spec(delete_user(binary()) -> ok | {error, any()}). -delete_user(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +delete_user(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [UserId|_] -> case leo_s3_user:delete(list_to_binary(UserId)) of @@ -1967,8 +1924,7 @@ delete_user(CmdBody, Option) -> %% @doc Retrieve Users %% @private -get_users(Command, Formatter) -> - _ = leo_manager_mnesia:insert_history(Command), +get_users(Formatter) -> Fun = fun() -> case get_users_1() of {ok, List} -> @@ -1996,11 +1952,9 @@ get_users_1() -> %% @doc Insert an Endpoint into the manager %% @private --spec(set_endpoint(binary(), binary()) -> +-spec(set_endpoint(binary()) -> ok | {error, any()}). -set_endpoint(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +set_endpoint(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_INVALID_ARGS}; @@ -2012,8 +1966,7 @@ set_endpoint(CmdBody, Option) -> %% @doc Retrieve an Endpoint from the manager %% @private -get_endpoints(Command, Formatter) -> - _ = leo_manager_mnesia:insert_history(Command), +get_endpoints(Formatter) -> Fun = fun() -> case get_endpoints_1() of {ok, EndPoints} -> @@ -2040,11 +1993,9 @@ get_endpoints_1() -> %% @doc Remove an Endpoint from the manager %% @private --spec(delete_endpoint(binary(), binary()) -> +-spec(delete_endpoint(binary()) -> ok | {error, any()}). -delete_endpoint(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +delete_endpoint(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [] -> {error, ?ERROR_INVALID_ARGS}; @@ -2056,11 +2007,9 @@ delete_endpoint(CmdBody, Option) -> %% @doc Insert a Buckets in the manager %% @private --spec(add_bucket(binary(), binary()) -> +-spec(add_bucket(binary()) -> ok | {error, any()}). -add_bucket(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +add_bucket(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Bucket, AccessKey] -> BucketBin = list_to_binary(Bucket), @@ -2073,11 +2022,9 @@ add_bucket(CmdBody, Option) -> %% @doc Remove a Buckets from the manager %% @private --spec(delete_bucket(binary(), binary()) -> +-spec(delete_bucket(binary()) -> ok | {error, any()}). -delete_bucket(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +delete_bucket(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Bucket, AccessKey] -> BucketBin = list_to_binary(Bucket), @@ -2090,8 +2037,7 @@ delete_bucket(CmdBody, Option) -> %% @doc Retrieve a Buckets from the manager %% @private -get_buckets(Command, Formatter) -> - _ = leo_manager_mnesia:insert_history(Command), +get_buckets(Formatter) -> Fun = fun() -> case get_buckets_1() of {ok, Buckets} -> @@ -2117,11 +2063,9 @@ get_buckets_1() -> %% @doc Retrieve a Buckets from the manager %% @private --spec(get_bucket_by_access_key(binary(), binary()) -> +-spec(get_bucket_by_access_key(binary()) -> ok | {error, any()}). -get_bucket_by_access_key(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +get_bucket_by_access_key(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [AccessKey] -> leo_s3_bucket:find_buckets_by_id(list_to_binary(AccessKey)); @@ -2132,11 +2076,9 @@ get_bucket_by_access_key(CmdBody, Option) -> %% @doc Change owner of a bucket %% @private --spec(change_bucket_owner(binary(), binary()) -> +-spec(change_bucket_owner(binary()) -> ok | {error, any()}). -change_bucket_owner(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +change_bucket_owner(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Bucket, NewAccessKeyId] -> case leo_s3_bucket:change_bucket_owner(list_to_binary(NewAccessKeyId), @@ -2155,11 +2097,9 @@ change_bucket_owner(CmdBody, Option) -> %% @doc Update ACLs of the specified bucket with the Canned ACL in the manager %% @private --spec(update_acl(binary(), binary()) -> +-spec(update_acl(binary()) -> ok | {error, any()}). -update_acl(CmdBody, Option) -> - _ = leo_manager_mnesia:insert_history(CmdBody), - +update_acl(Option) -> case string:tokens(binary_to_list(Option), ?COMMAND_DELIMITER) of [Bucket, AccessKey, Permission] -> BucketBin = list_to_binary(Bucket), diff --git a/src/leo_manager_mnesia.erl b/src/leo_manager_mnesia.erl index 579306b..b920e27 100644 --- a/src/leo_manager_mnesia.erl +++ b/src/leo_manager_mnesia.erl @@ -545,27 +545,20 @@ update_rebalance_info(RebalanceInfo) -> ok | {error, any()}). insert_history(Command) -> [NewCommand|_] = string:tokens(binary_to_list(Command), "\r\n"), - Id = case get_histories_all() of - {ok, List} -> length(List) + 1; - not_found -> 1; - {_, Cause} -> {error, Cause} - end, - - case Id of - {error, Reason} -> - {error, Reason}; - _ -> - Tbl = ?TBL_HISTORIES, - - case catch mnesia:table_info(Tbl, all) of - {'EXIT', _Cause} -> - {error, ?ERROR_MNESIA_NOT_START}; - _ -> - F = fun() -> mnesia:write(?TBL_HISTORIES, #history{id = Id, - command = NewCommand, - created = leo_date:now()}, write) end, - leo_mnesia:write(F) - end + + Tbl = ?TBL_HISTORIES, + case catch mnesia:table_info(Tbl, size) of + {'EXIT', _Cause} -> + {error, ?ERROR_MNESIA_NOT_START}; + Size -> + Id = Size + 1, + F = fun() -> + mnesia:write(?TBL_HISTORIES, + #history{id = Id, + command = NewCommand, + created = leo_date:now()}, write) + end, + leo_mnesia:write(F) end. diff --git a/src/leo_manager_sup.erl b/src/leo_manager_sup.erl index e4adca6..e9c6f87 100644 --- a/src/leo_manager_sup.erl +++ b/src/leo_manager_sup.erl @@ -85,10 +85,12 @@ start_link() -> ok = leo_manager_console:start_link(leo_manager_formatter_json, JSON_Console, PluginModConsole), %% Launch Logger - LogDir = ?env_log_dir(), + LogDir = ?env_log_dir(), LogLevel = ?env_log_level(leo_manager), ok = leo_logger_client_message:new( LogDir, LogLevel, log_file_appender()), + ok = leo_logger_client_base:new(?LOG_GROUP_ID_HISTORY, ?LOG_ID_HISTORY, + LogDir, ?LOG_FILENAME_HISTORY), %% Launch MQ ok = leo_manager_mq_client:start(?MODULE, [], ?env_queue_dir()), diff --git a/src/tcp_server_acceptor.erl b/src/tcp_server_acceptor.erl index d8e318c..bcdaa1b 100644 --- a/src/tcp_server_acceptor.erl +++ b/src/tcp_server_acceptor.erl @@ -159,12 +159,15 @@ call(Active, Socket, Data, #state{plugin_mod = PluginMod} = State, Module, Optio call_1(HasCommand, Active, Socket, Data, State, Module, Option) -> Module_1 = case HasCommand of - true -> State#state.plugin_mod; - false -> Module + true -> + State#state.plugin_mod; + false -> + Module end, case Module_1:handle_call(Socket, Data, State) of {reply, DataToSend, NewState} -> + ?put_cmd_history(Data), gen_tcp:send(Socket, DataToSend), recv(Active, Socket, NewState, Module, Option); {noreply, NewState} ->