From b1d4d078dba1207ed9840e640b43df4f8906dcad Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 3 Sep 2024 16:55:04 -0400 Subject: [PATCH 1/3] TMP: Bump seshat The commit hash should be replaced when a new hex version is cut. --- Makefile | 2 +- rebar.config | 3 ++- rebar.lock | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1a25938b..b483d939 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ESCRIPT_EMU_ARGS = -noinput -setcookie ra_fifo_cli dep_gen_batch_server = hex 0.8.9 dep_aten = hex 0.6.0 -dep_seshat = hex 0.6.0 +dep_seshat = git https://github.com/rabbitmq/seshat.git 2b09eab1e1ec2e97de744236fad98fdb6c3897fa DEPS = aten gen_batch_server seshat TEST_DEPS = proper meck eunit_formatters inet_tcp_proxy diff --git a/rebar.config b/rebar.config index 66b4a050..85046b98 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,8 @@ {deps, [ {gen_batch_server, "0.8.9"}, {aten, "0.6.0"}, - {seshat, "0.6.0"}, + {seshat, {git, "https://github.com/rabbitmq/seshat", + {ref, "2b09eab1e1ec2e97de744236fad98fdb6c3897fa"}}}, {eqwalizer_support, {git_subdir, "https://github.com/whatsapp/eqwalizer.git", diff --git a/rebar.lock b/rebar.lock index ef159cb3..dbbbb4f2 100644 --- a/rebar.lock +++ b/rebar.lock @@ -6,7 +6,10 @@ "eqwalizer_support"}, 0}, {<<"gen_batch_server">>,{pkg,<<"gen_batch_server">>,<<"0.8.9">>},0}, - {<<"seshat">>,{pkg,<<"seshat">>,<<"0.6.0">>},0}]}. + {<<"seshat">>, + {git,"https://github.com/rabbitmq/seshat", + {ref,"2b09eab1e1ec2e97de744236fad98fdb6c3897fa"}}, + 0}]}. [ {pkg_hash,[ {<<"aten">>, <<"7A57B275A6DAF515AC3683FB9853E280B4D0DCDD74292FD66AC4A01C8694F8C7">>}, @@ -15,5 +18,5 @@ {pkg_hash_ext,[ {<<"aten">>, <<"5F39A164206AE3F211EF5880B1F7819415686436E3229D30B6A058564FBAA168">>}, {<<"gen_batch_server">>, <<"C8581FE4A4B6BCCF91E53CE6A8C7E6C27C8C591BAB5408B160166463F5579C22">>}, - {<<"seshat">>, <<"7CEF700F92831DD7CAE6A6DD223CCC55AC88ECCE0631EE9AB0F2B5FB70E79B90">>}]} + {<<"seshat">>, <<"C3E6A1A2A0FB62AEE631A98CFA0FD8903E9562422CBF72043953E2FB1D203017">>}]} ]. From aab0f38e9a53262e4a737ec69e7b8f2ea20642ea Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 3 Sep 2024 16:56:33 -0400 Subject: [PATCH 2/3] Add `ra_counters:new/4` wrapping `seshat:new/4` --- src/ra_counters.erl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ra_counters.erl b/src/ra_counters.erl index 080b4572..759b10e5 100644 --- a/src/ra_counters.erl +++ b/src/ra_counters.erl @@ -10,6 +10,7 @@ -export([ init/0, new/2, + new/3, fetch/1, overview/0, overview/1, @@ -32,6 +33,11 @@ init() -> new(Name, FieldsSpec) -> seshat:new(ra, Name, FieldsSpec). +-spec new(name(), seshat:fields_spec(), seshat:label()) -> + counters:counters_ref(). +new(Name, FieldsSpec, Label) -> + seshat:new(ra, Name, FieldsSpec, Label). + -spec fetch(name()) -> undefined | counters:counters_ref(). fetch(Name) -> seshat:fetch(ra, Name). From 9c5e1f83c1c88e9ffafabd7d61ae2a0e0a0b1abe Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 4 Sep 2024 16:10:44 -0400 Subject: [PATCH 3/3] Add `counter_label` field to Ra server config This new field sets the `seshat:label()` when creating a new counter for a server (via `ra_counters:new/3` and in turn `seshat:new/4`). This also deprecates the `counter` field. Having the creator of a Ra server pass a `counters:counter_ref()` is unergonomic because the caller must know the `seshat:fields_spec()` with which the counter should be created. Also in this change we remove the call to `ra_counters:new/2` from the `ra_server_proc:config_defaults()` helper. By calling that function when creating a default, the server process registered a counter (causing an insertion into an ETS table in seshat) for the server even if the caller specified a `counter` in the config. --- src/ra_server.erl | 3 +++ src/ra_server_proc.erl | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/ra_server.erl b/src/ra_server.erl index 9d93bf9d..aa384693 100644 --- a/src/ra_server.erl +++ b/src/ra_server.erl @@ -229,7 +229,9 @@ await_condition_timeout => non_neg_integer(), max_pipeline_count => non_neg_integer(), ra_event_formatter => {module(), atom(), [term()]}, + %% Deprecated in favor of counter_label: counter => counters:counters_ref(), + counter_label => seshat:label(), membership => ra_membership(), system_config => ra_system:config(), has_changed => boolean() @@ -258,6 +260,7 @@ -type mutable_config() :: #{cluster_name => ra_cluster_name(), metrics_key => term(), + counter_label => seshat:label(), broadcast_time => non_neg_integer(), % ms tick_timeout => non_neg_integer(), % ms install_snap_rpc_timeout => non_neg_integer(), % ms diff --git a/src/ra_server_proc.erl b/src/ra_server_proc.erl index 1c725cbd..c1ea3075 100644 --- a/src/ra_server_proc.erl +++ b/src/ra_server_proc.erl @@ -315,9 +315,22 @@ do_init(#{id := Id, Key = ra_lib:ra_server_id_to_local_name(Id), true = ets:insert(ra_state, {Key, init, unknown}), process_flag(trap_exit, true), - Config = #{counter := Counter, - system_config := #{names := Names} = SysConf} = maps:merge(config_defaults(Id), - Config0), + Config1 = #{system_config := SysConf} = maps:merge(config_defaults(), + Config0), + Counter = case maps:find(counter, Config1) of + {ok, C} -> + C; + error -> + case ra_counters:fetch(Id) of + undefined -> + Label = maps:get(counter_label, Config1, Id), + ra_counters:new( + Id, {persistent_term, ?FIELDSPEC_KEY}, Label); + C -> + C + end + end, + Config = maps:put(counter, Counter, Config1), MsgQData = maps:get(message_queue_data, SysConf, off_heap), MinBinVheapSize = maps:get(server_min_bin_vheap_size, SysConf, ?MIN_BIN_VHEAP_SIZE), @@ -1768,20 +1781,12 @@ gen_statem_safe_call(ServerId, Msg, Timeout) -> do_state_query(QueryName, #state{server_state = State}) -> ra_server:state_query(QueryName, State). -config_defaults(ServerId) -> - Counter = case ra_counters:fetch(ServerId) of - undefined -> - ra_counters:new(ServerId, - {persistent_term, ?FIELDSPEC_KEY}); - C -> - C - end, +config_defaults() -> #{broadcast_time => ?DEFAULT_BROADCAST_TIME, tick_timeout => ?TICK_INTERVAL_MS, install_snap_rpc_timeout => ?INSTALL_SNAP_RPC_TIMEOUT, await_condition_timeout => ?DEFAULT_AWAIT_CONDITION_TIMEOUT, initial_members => [], - counter => Counter, system_config => ra_system:default_config() }.