From 7e4ea4fe0d23af82214e7efbe25a0a5149f9ccc3 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 | 11 ++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index fe461fe7..04be98ae 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ESCRIPT_EMU_ARGS = -noinput -setcookie ra_fifo_cli dep_gen_batch_server = hex 0.8.8 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 a4b1d8fb..b4175256 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,8 @@ {deps, [ {gen_batch_server, "0.8.8"}, {aten, "0.6.0"}, - {seshat, "0.6.0"} + {seshat, {git, "https://github.com/rabbitmq/seshat", + {ref, "2b09eab1e1ec2e97de744236fad98fdb6c3897fa"}}} ]}. {profiles, diff --git a/rebar.lock b/rebar.lock index d8dc784a..3c4869a1 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,14 +1,15 @@ {"1.2.0", [{<<"aten">>,{pkg,<<"aten">>,<<"0.6.0">>},0}, {<<"gen_batch_server">>,{pkg,<<"gen_batch_server">>,<<"0.8.8">>},0}, - {<<"seshat">>,{pkg,<<"seshat">>,<<"0.6.0">>},0}]}. + {<<"seshat">>, + {git,"https://github.com/rabbitmq/seshat", + {ref,"2b09eab1e1ec2e97de744236fad98fdb6c3897fa"}}, + 0}]}. [ {pkg_hash,[ {<<"aten">>, <<"7A57B275A6DAF515AC3683FB9853E280B4D0DCDD74292FD66AC4A01C8694F8C7">>}, - {<<"gen_batch_server">>, <<"7840A1FA63EE1EFFC83E8A91D22664847A2BA1192D30EAFFFD914ACB51578068">>}, - {<<"seshat">>, <<"3172EB1D7A2A4F66108CD6933A4E465AFF80F84AA90ED83F047B92F636123CCD">>}]}, + {<<"gen_batch_server">>, <<"7840A1FA63EE1EFFC83E8A91D22664847A2BA1192D30EAFFFD914ACB51578068">>}]}, {pkg_hash_ext,[ {<<"aten">>, <<"5F39A164206AE3F211EF5880B1F7819415686436E3229D30B6A058564FBAA168">>}, - {<<"gen_batch_server">>, <<"C3E6A1A2A0FB62AEE631A98CFA0FD8903E9562422CBF72043953E2FB1D203017">>}, - {<<"seshat">>, <<"7CEF700F92831DD7CAE6A6DD223CCC55AC88ECCE0631EE9AB0F2B5FB70E79B90">>}]} + {<<"gen_batch_server">>, <<"C3E6A1A2A0FB62AEE631A98CFA0FD8903E9562422CBF72043953E2FB1D203017">>}]} ]. From c087c3bce2a4cf010fa95ac00e75f95a6389f55e 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 aef777518cef9ce050c41f100ebd1d023e1fdfa7 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 6ae440ac..914396fe 100644 --- a/src/ra_server.erl +++ b/src/ra_server.erl @@ -206,7 +206,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() @@ -214,6 +216,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 94b605bf..c61cd960 100644 --- a/src/ra_server_proc.erl +++ b/src/ra_server_proc.erl @@ -302,9 +302,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 := 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), @@ -1709,20 +1722,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() }.