Skip to content

Commit 3235041

Browse files
committed
MB-47561 eliminate extra ns_config:get from ns_storage_comf:do_cluster_storage_info
Change-Id: I10f50cd3d1327b8a989c4e17e60778aebae4dd70 Reviewed-on: http://review.couchbase.org/c/ns_server/+/158071 Tested-by: Artem Stemkovski <[email protected]> Well-Formed: Restriction Checker Reviewed-by: Aliaksey Artamonau <[email protected]>
1 parent ac137fa commit 3235041

File tree

5 files changed

+48
-33
lines changed

5 files changed

+48
-33
lines changed

src/menelaus_web_buckets.erl

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ build_durability_min_level(BucketConfig) ->
261261
<<"persistToMajority">>
262262
end.
263263

264+
build_storage_totals(Config) ->
265+
StorageTotals =
266+
[{Key, {struct, StoragePList}}
267+
|| {Key, StoragePList} <-
268+
ns_storage_conf:cluster_storage_info(Config)],
269+
270+
{storageTotals, {struct, StorageTotals}}.
271+
264272
build_bucket_info(Id, undefined, InfoLevel, LocalAddr, MayExposeAuth,
265273
SkipMap, Config) ->
266274
{ok, BucketConfig} = ns_bucket:get_bucket(Id, Config),
@@ -292,14 +300,12 @@ build_bucket_info(Id, BucketConfig, InfoLevel, LocalAddr, MayExposeAuth,
292300
_ ->
293301
BasicStats0 = menelaus_stats:basic_stats(Id),
294302

295-
BasicStats = case InfoLevel of
296-
for_ui ->
297-
StorageTotals = [{Key, {struct, StoragePList}}
298-
|| {Key, StoragePList} <- ns_storage_conf:cluster_storage_info()],
299-
300-
[{storageTotals, {struct, StorageTotals}} | BasicStats0];
301-
_ -> BasicStats0
302-
end,
303+
BasicStats =
304+
case InfoLevel of
305+
for_ui ->
306+
[build_storage_totals(Config) | BasicStats0];
307+
_ -> BasicStats0
308+
end,
303309

304310
BucketParams =
305311
[{replicaNumber, ns_bucket:num_replicas(BucketConfig)},
@@ -553,12 +559,14 @@ init_bucket_validation_context(IsNew, BucketName, Req) ->
553559
init_bucket_validation_context(IsNew, BucketName, ValidateOnly, IgnoreWarnings).
554560

555561
init_bucket_validation_context(IsNew, BucketName, ValidateOnly, IgnoreWarnings) ->
556-
init_bucket_validation_context(IsNew, BucketName,
557-
ns_bucket:get_buckets(),
558-
extended_cluster_storage_info(),
559-
ValidateOnly, IgnoreWarnings,
560-
cluster_compat_mode:get_compat_version(),
561-
cluster_compat_mode:is_enterprise()).
562+
Config = ns_config:get(),
563+
init_bucket_validation_context(
564+
IsNew, BucketName,
565+
ns_bucket:get_buckets(Config),
566+
extended_cluster_storage_info(Config),
567+
ValidateOnly, IgnoreWarnings,
568+
cluster_compat_mode:get_compat_version(Config),
569+
cluster_compat_mode:is_enterprise()).
562570

563571
init_bucket_validation_context(IsNew, BucketName, AllBuckets, ClusterStorageTotals,
564572
ValidateOnly, IgnoreWarnings,
@@ -1588,9 +1596,10 @@ parse_validate_conflict_resolution_type(_Other) ->
15881596
{error, conflictResolutionType,
15891597
<<"Conflict resolution type must be 'seqno' or 'lww'">>}.
15901598

1591-
extended_cluster_storage_info() ->
1592-
[{nodesCount, length(ns_cluster_membership:service_active_nodes(kv))}
1593-
| ns_storage_conf:cluster_storage_info()].
1599+
extended_cluster_storage_info(Config) ->
1600+
[{nodesCount,
1601+
length(ns_cluster_membership:service_active_nodes(Config, kv))}
1602+
| ns_storage_conf:cluster_storage_info(Config)].
15941603

15951604

15961605
handle_compact_bucket(_PoolId, Bucket, Req) ->

src/menelaus_web_node.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ build_full_node_info(Config, Node, LocalAddr) ->
107107
{sizeKBytes, SizeKBytes},
108108
{usagePercent, UsagePercent}]}
109109
|| {Path, SizeKBytes, UsagePercent} <- DiskData]}]}},
110-
{storageTotals, {struct, [{Type, {struct, PropList}}
111-
|| {Type, PropList} <- ns_storage_conf:nodes_storage_info([Node])]}},
110+
{storageTotals,
111+
{struct,
112+
[{Type, {struct, PropList}}
113+
|| {Type, PropList} <- ns_storage_conf:nodes_storage_info(
114+
[Node], Config)]}},
112115
{storage, R}] ++ KV ++ build_memory_quota_info(Config),
113116
{struct, lists:filter(fun (X) -> X =/= undefined end,
114117
Fields)}.

src/menelaus_web_pools.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ do_build_pool_info(Id, InfoLevel, Stability, LocalAddr) ->
231231
menelaus_web_node:build_memory_quota_info(Config),
232232
build_ui_params(InfoLevel),
233233
build_internal_params(InfoLevel),
234-
build_unstable_params(Stability)],
234+
build_unstable_params(Stability, Config)],
235235
{struct, lists:flatten(PropList)}.
236236

237237
build_rebalance_params(Id, UUID) ->
@@ -265,12 +265,13 @@ build_ui_params(for_ui) ->
265265
build_ui_params(_) ->
266266
[].
267267

268-
build_unstable_params(stable) ->
268+
build_unstable_params(stable, _) ->
269269
[];
270-
build_unstable_params(unstable) ->
270+
build_unstable_params(unstable, Config) ->
271271
[{storageTotals,
272272
{[{Key, {StoragePList}} ||
273-
{Key, StoragePList} <- ns_storage_conf:cluster_storage_info()]}}].
273+
{Key, StoragePList} <-
274+
ns_storage_conf:cluster_storage_info(Config)]}}].
274275

275276
build_buckets_info(Config, Id, UUID, Nodes) ->
276277
BucketsVer =

src/menelaus_web_samples.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ validate_post_sample_buckets(Samples) ->
105105
end.
106106

107107
check_quota(Samples) ->
108-
NodesCount = length(ns_cluster_membership:service_active_nodes(kv)),
109-
StorageInfo = ns_storage_conf:cluster_storage_info(),
108+
Config = ns_config:get(),
109+
NodesCount = length(ns_cluster_membership:service_active_nodes(Config, kv)),
110+
StorageInfo = ns_storage_conf:cluster_storage_info(Config),
110111
RamQuotas = proplists:get_value(ram, StorageInfo),
111112
QuotaUsed = proplists:get_value(quotaUsed, RamQuotas),
112113
QuotaTotal = proplists:get_value(quotaTotal, RamQuotas),

src/ns_storage_conf.erl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
this_node_java_home/0,
3939
update_java_home/1]).
4040

41-
-export([cluster_storage_info/0, nodes_storage_info/1]).
41+
-export([cluster_storage_info/1, nodes_storage_info/2]).
4242

4343
-export([extract_disk_stats_for_path/2]).
4444

@@ -440,15 +440,15 @@ extract_disk_totals(DiskPaths, DiskStats) ->
440440
{DiskTotal, DiskUsed}.
441441

442442
%% returns cluster_storage_info for subset of nodes
443-
nodes_storage_info(NodeNames) ->
443+
nodes_storage_info(NodeNames, Config) ->
444444
NodesDict = ns_doctor:get_nodes(),
445445
NodesInfos = lists:foldl(fun (N, A) ->
446446
case dict:find(N, NodesDict) of
447447
{ok, V} -> [{N, V} | A];
448448
_ -> A
449449
end
450450
end, [], NodeNames),
451-
do_cluster_storage_info(NodesInfos).
451+
do_cluster_storage_info(NodesInfos, Config).
452452

453453
%% returns cluster storage info. This is aggregation of various
454454
%% storage related metrics across active nodes of cluster.
@@ -466,8 +466,10 @@ nodes_storage_info(NodeNames) ->
466466
%% quotaUsed - amount of quota already allocated
467467
%%
468468
%% usedByData - amount of this resource used by our data
469-
cluster_storage_info() ->
470-
nodes_storage_info(ns_cluster_membership:service_active_nodes(kv)).
469+
cluster_storage_info(Config) ->
470+
nodes_storage_info(
471+
ns_cluster_membership:service_active_nodes(Config, kv),
472+
Config).
471473

472474
extract_subprop(NodeInfos, Key, SubKey) ->
473475
[proplists:get_value(SubKey, proplists:get_value(Key, NodeInfo, [])) ||
@@ -483,9 +485,8 @@ interesting_stats_total_rec([ThisStats | RestStats], Key, Acc) ->
483485
interesting_stats_total_rec(RestStats, Key, Acc + V)
484486
end.
485487

486-
do_cluster_storage_info([]) -> [];
487-
do_cluster_storage_info(NodeInfos) ->
488-
Config = ns_config:get(),
488+
do_cluster_storage_info([], _) -> [];
489+
do_cluster_storage_info(NodeInfos, Config) ->
489490
NodesCount = length(NodeInfos),
490491
RAMQuotaUsedPerNode = memory_quota:get_total_buckets_ram_quota(Config),
491492
RAMQuotaUsed = RAMQuotaUsedPerNode * NodesCount,

0 commit comments

Comments
 (0)