Skip to content

Commit

Permalink
Revise system_conf and cluster_info to fix leo-project/leofs/issues/645
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Apr 18, 2017
1 parent 077326a commit 0ef27b3
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 64 deletions.
99 changes: 65 additions & 34 deletions include/leo_redundant_manager.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -292,67 +292,98 @@
%% Configure of Redundancies and Consistency Level
-record(system_conf, {
version = 0 :: non_neg_integer(),
n = 0 :: non_neg_integer(),
r = 1 :: non_neg_integer(),
w = 1 :: non_neg_integer(),
d = 1 :: non_neg_integer(),
bit_of_ring = 128 :: non_neg_integer(),
level_1 = 0 :: non_neg_integer(),
n = 1 :: pos_integer(),
r = 1 :: pos_integer(),
w = 1 :: pos_integer(),
d = 1 :: pos_integer(),
bit_of_ring = 128 :: pos_integer(),
level_1 = 1 :: pos_integer(),
level_2 = 0 :: non_neg_integer()
}).
-record(system_conf_1, {
version = 0 :: non_neg_integer(),
cluster_id :: atom()|string(),
dc_id :: atom()|string(),
n = 1 :: non_neg_integer(),
r = 1 :: non_neg_integer(),
w = 1 :: non_neg_integer(),
d = 1 :: non_neg_integer(),
bit_of_ring = 128 :: non_neg_integer(),
num_of_dc_replicas = 0 :: non_neg_integer(),
n = 1 :: pos_integer(),
r = 1 :: pos_integer(),
w = 1 :: pos_integer(),
d = 1 :: pos_integer(),
bit_of_ring = 128 :: pos_integer(),
num_of_dc_replicas = 1 :: pos_integer(),
num_of_rack_replicas = 0 :: non_neg_integer()
}).
-record(system_conf_2, {
version = 1 :: non_neg_integer(), %% version
cluster_id :: atom(), %% cluster-id
dc_id :: atom(), %% dc-id
n = 0 :: non_neg_integer(), %% # of replicas
r = 0 :: non_neg_integer(), %% # of replicas needed for a successful READ operation
w = 0 :: non_neg_integer(), %% # of replicas needed for a successful WRITE operation
d = 0 :: non_neg_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: non_neg_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 0 :: non_neg_integer(), %% # of destination of nodes a cluster for MDC-replication
n = 1 :: pos_integer(), %% # of replicas
r = 1 :: pos_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: pos_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: pos_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: pos_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 1 :: pos_integer(), %% # of destination of nodes a cluster for MDC-replication
num_of_rack_replicas = 0 :: non_neg_integer(), %% # of Rack-awareness replicas
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: non_neg_integer() %% max multi-dc replication targets for MDC-replication
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: pos_integer() %% max multi-dc replication targets for MDC-replication
}).
-define(SYSTEM_CONF, 'system_conf_2').
-record(system_conf_3, {
version = 1 :: non_neg_integer(), %% version
cluster_id :: atom(), %% cluster-id
dc_id :: atom(), %% dc-id
n = 1 :: pos_integer(), %% # of replicas
r = 1 :: pos_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: pos_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: pos_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: pos_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 1 :: pos_integer(), %% # of destination of nodes a cluster for MDC-replication
mdcr_r = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful READ operation
mdcr_w = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful WRITE operation
mdcr_d = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful DELETE operation
num_of_rack_replicas = 0 :: non_neg_integer(), %% # of Rack-awareness replicas
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: pos_integer() %% max multi-dc replication targets for MDC-replication
}).
-define(SYSTEM_CONF, 'system_conf_3').


%% Configuration of a remote cluster
-record(cluster_info, {
cluster_id :: atom()|string(), %% cluster-id
dc_id :: atom()|string(), %% dc-id
n = 1 :: non_neg_integer(), %% # of replicas
r = 1 :: non_neg_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: non_neg_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: non_neg_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: non_neg_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 0 :: non_neg_integer(), %% # of replicas a DC for MDC-replication
n = 1 :: pos_integer(), %% # of replicas
r = 1 :: pos_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: pos_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: pos_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: pos_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 1 :: pos_integer(), %% # of replicas a DC for MDC-replication
num_of_rack_replicas = 0 :: non_neg_integer() %% # of Rack-awareness replicas
}).
-record(cluster_info_1, {
cluster_id :: atom(), %% cluster-id
dc_id :: atom(), %% dc-id
n = 0 :: non_neg_integer(), %% # of replicas
r = 0 :: non_neg_integer(), %% # of replicas needed for a successful READ operation
w = 0 :: non_neg_integer(), %% # of replicas needed for a successful WRITE operation
d = 0 :: non_neg_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: non_neg_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 0 :: non_neg_integer(), %% # of replicas a DC for MDC-replication
n = 1 :: pos_integer(), %% # of replicas
r = 1 :: pos_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: pos_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: pos_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: pos_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 1 :: pos_integer(), %% # of replicas a DC for MDC-replication
num_of_rack_replicas = 0 :: non_neg_integer(), %% # of Rack-awareness replicas
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: pos_integer() %% max multi-dc replication targets for MDC-replication
}).
-record(cluster_info_2, {
cluster_id :: atom(), %% cluster-id
dc_id :: atom(), %% dc-id
n = 1 :: pos_integer(), %% # of replicas
r = 1 :: pos_integer(), %% # of replicas needed for a successful READ operation
w = 1 :: pos_integer(), %% # of replicas needed for a successful WRITE operation
d = 1 :: pos_integer(), %% # of replicas needed for a successful DELETE operation
bit_of_ring = 128 :: pos_integer(), %% # of bits for the hash-ring (fixed 128bit)
num_of_dc_replicas = 1 :: pos_integer(), %% # of replicas a DC for MDC-replication
mdcr_r = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful READ operation
mdcr_w = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful WRITE operation
mdcr_d = 1 :: pos_integer(), %% mdc-replication / # of replicas needed for a successful DELETE operation
num_of_rack_replicas = 0 :: non_neg_integer(), %% # of Rack-awareness replicas
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: non_neg_integer() %% max multi-dc replication targets for MDC-replication
max_mdc_targets = ?DEF_MAX_MDC_TARGETS :: pos_integer() %% max multi-dc replication targets for MDC-replication
}).
-define(CLUSTER_INFO, 'cluster_info_1').
-define(CLUSTER_INFO, 'cluster_info_2').


%% For Multi-DC Replication
Expand Down
41 changes: 25 additions & 16 deletions src/leo_cluster_tbl_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%%
%% Leo Redundant Manager
%%
%% Copyright (c) 2012-2015 Rakuten, Inc.
%% Copyright (c) 2012-2017 Rakuten, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -49,21 +49,7 @@ create_table(Mode, Nodes) ->
[{Mode, Nodes},
{type, set},
{record_name, ?SYSTEM_CONF},
{attributes, record_info(fields, ?SYSTEM_CONF)},
{user_properties,
[
{version, pos_integer, primary},
{cluster_id, atom, false},
{dc_id, atom, false},
{n, pos_integer, false},
{r, pos_integer, false},
{w, pos_integer, false},
{d, pos_integer, false},
{bit_of_ring, pos_integer, false},
{num_of_dc_replicas, pos_integer, false},
{num_of_rack_replicas, pos_integer, false},
{max_mdc_targets, pos_integer, false}
]}
{attributes, record_info(fields, ?SYSTEM_CONF)}
]) of
{atomic, ok} ->
ok;
Expand Down Expand Up @@ -299,4 +285,27 @@ transform(#system_conf_1{version = Vsn,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = ?DEF_MAX_MDC_TARGETS
};
transform(#system_conf_2{version = Vsn,
cluster_id = ClusterId,
dc_id = DCId,
n = N,
r = R,
w = W,
d = D,
bit_of_ring = BitOfRing,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = MaxMDCTargets}) ->
#?SYSTEM_CONF{version = Vsn,
cluster_id = ClusterId,
dc_id = DCId,
n = N,
r = R,
w = W,
d = D,
bit_of_ring = BitOfRing,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = MaxMDCTargets
}.
39 changes: 25 additions & 14 deletions src/leo_mdcr_tbl_cluster_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%%
%% Leo Redundant Manager
%%
%% Copyright (c) 2012-2015 Rakuten, Inc.
%% Copyright (c) 2012-2017 Rakuten, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -50,19 +50,7 @@ create_table(Mode, Nodes) ->
[{Mode, Nodes},
{type, set},
{record_name, ?CLUSTER_INFO},
{attributes, record_info(fields, ?CLUSTER_INFO)},
{user_properties,
[{cluster_id, atom, primary},
{dc_id, atom, false },
{n, pos_integer, false },
{r, pos_integer, false },
{w, pos_integer, false },
{d, pos_integer, false },
{bit_of_ring, pos_integer, false },
{num_of_dc_replicas, pos_integer, false },
{num_of_rack_replicas, pos_integer, false },
{max_mdc_targets, pos_integer, false }
]}
{attributes, record_info(fields, ?CLUSTER_INFO)}
]) of
{atomic, ok} ->
ok;
Expand Down Expand Up @@ -324,8 +312,31 @@ transform(#cluster_info{cluster_id = ClusterId,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = ?DEF_MAX_MDC_TARGETS
};
transform(#cluster_info_1{cluster_id = ClusterId,
dc_id = DCId,
n = N,
r = R,
w = W,
d = D,
bit_of_ring = BitOfRing,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = MaxMDCTargets
}) ->
#?CLUSTER_INFO{cluster_id = ClusterId,
dc_id = DCId,
n = N,
r = R,
w = W,
d = D,
bit_of_ring = BitOfRing,
num_of_dc_replicas = Level1,
num_of_rack_replicas = Level2,
max_mdc_targets = MaxMDCTargets
}.


%% @private
transform_2() ->
case all() of
Expand Down

0 comments on commit 0ef27b3

Please sign in to comment.