Skip to content

Commit

Permalink
Merge branch 'release/1.2.20'
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Mar 23, 2016
2 parents 52cbe88 + eff4bc0 commit 98bba00
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 305 deletions.
96 changes: 66 additions & 30 deletions include/leo_manager.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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").
Expand All @@ -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").
Expand All @@ -127,15 +134,14 @@
-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").
-define(CMD_DUMP_RING, "dump-ring").
-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").
Expand All @@ -149,15 +155,15 @@
-define(COMMANDS, [{?CMD_HELP, "help"},
{?CMD_QUIT, "quit"},
{?CMD_VERSION, "version"},
{?CMD_STATUS, "status [<storage-node>|<gateway-node>]"},
{?CMD_HISTORY, "history"},
{?CMD_DUMP_RING, "dump-ring (<manager-node>|<storage-node>|<gateway-node>)"},
{?CMD_STATUS, "status [<storage-node>|<gateway-node>]"},
{?CMD_DUMP_RING, "dump-ring <manager-node>|<storage-node>|<gateway-node>"},
{?CMD_UPDATE_LOG_LEVEL, "update-log-level (<storage-node>|<gateway-node>) (debug|info|warn|error)"},
{?CMD_UPDATE_CONSISTENCY_LEVEL, "update-consistency-level (<storage-node>|<gateway-node>) <write-quorum> <read-quorum> <delete-quorum>"},
%% for Cluster
{?CMD_WHEREIS, "whereis <path>"},
{?CMD_RECOVER, lists:append(
["recover file <path>", ?CRLF,
"recover dir [<path>]", ?CRLF,
"recover node <storage-node>", ?CRLF,
"recover ring <storage-node>", ?CRLF,
"recover cluster <cluster-id>"
Expand All @@ -170,14 +176,14 @@
{?CMD_REBALANCE, "rebalance"},
%% for Storage
{?CMD_COMPACT, lists:append(
["compact start <storage-node> (all|<num_of_targets>) [<num_of_compact_procs>]", ?CRLF,
["compact start <storage-node> all|<num_of_targets> [<num_of_compact_procs>]", ?CRLF,
"compact suspend <storage-node>", ?CRLF,
"compact resume <storage-node>", ?CRLF,
"compact status <storage-node>"
"compact resume <storage-node>", ?CRLF,
"compact status <storage-node>"
])},
{?CMD_DIAGNOSE_DATA, "diagnose-data <storage-node>"},
{?CMD_DU, "du <storage-node>"},
%% for Storage-mq
%% for Storage MQ
{?CMD_MQ_STATS, "mq-stats <storage-node>"},
{?CMD_MQ_SUSPEND, "mq-suspend <storage-node> <mq-id>"},
{?CMD_MQ_RESUME, "mq-resume <storage-node> <mq-id>"},
Expand All @@ -204,6 +210,8 @@
{?CMD_GET_BUCKETS, "get-buckets"},
{?CMD_GET_BUCKET_BY_ACCESS_KEY, "get-bucket <access-key-id>"},
{?CMD_CHANGE_BUCKET_OWNER, "chown-bucket <bucket> <new-access-key-id>"},
{?CMD_SET_RED_METHOD, "set-redundancy-method <bucket> <access-key-id> <redundancy-method>"},
{?CMD_GEN_NFS_MNT_KEY, "gen-nfs-mnt-key <bucket> <access-key-id> <client-ip-address>"},
%% - acl-related
{?CMD_UPDATE_ACL, "update-acl <bucket> <access-key-id> private|public-read|public-read-write"},
%% - multi-dc replication
Expand All @@ -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).
Expand Down Expand Up @@ -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").
Expand All @@ -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">>).
Expand All @@ -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).
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}|_]} ->
Expand All @@ -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} ->
Expand All @@ -474,8 +500,6 @@
?DEF_QUEUE_DIR
end).

-define(DEF_MNESIA_DIR, "./work/mnesia/127.0.0.1").


%% @doc Plugin-related macros
%%
Expand All @@ -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).
2 changes: 1 addition & 1 deletion priv/leo_manager_0.schema
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"leo_manager.system_version",
[
{datatype, string},
{default, "1.2.18"}
{default, "1.2.20"}
]}.

%% @doc Mode of Manager: [master|slave]
Expand Down
2 changes: 1 addition & 1 deletion priv/leo_manager_1.schema
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"leo_manager.system_version",
[
{datatype, string},
{default, "1.2.18"}
{default, "1.2.20"}
]}.

%% @doc Mode of Manager: [master, slave]
Expand Down
18 changes: 10 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}}}
]}.

Expand All @@ -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, []}.
6 changes: 3 additions & 3 deletions src/leo_manager.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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},
Expand Down
30 changes: 25 additions & 5 deletions src/leo_manager_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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..." >>),
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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} =
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 98bba00

Please sign in to comment.