Skip to content

Commit 94c9bcc

Browse files
Alexander Shturmmeta-codesync[bot]
authored andcommitted
wa_raft is open-source and cannot depend on WA specific applications
Summary: wa_pt back to persistent_term Reviewed By: jaher, robertoaloi Differential Revision: D85642877 fbshipit-source-id: cf9805e3f79e145538d6169af7d1c4b9d46b36b8
1 parent efb2ade commit 94c9bcc

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

include/wa_raft.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
%%-------------------------------------------------------------------
8181

8282
-define(RAFT_METRICS_MODULE_KEY, {?RAFT_APPLICATION, raft_metrics_module}).
83-
-define(RAFT_METRICS_MODULE, (wa_pt:get(?RAFT_METRICS_MODULE_KEY, wa_raft_metrics))).
83+
-define(RAFT_METRICS_MODULE, (persistent_term:get(?RAFT_METRICS_MODULE_KEY, wa_raft_metrics))).
8484
-define(RAFT_COUNT(Metric), ?RAFT_METRICS_MODULE:count(Metric)).
8585
-define(RAFT_COUNTV(Metric, Value), ?RAFT_METRICS_MODULE:countv(Metric, Value)).
8686
-define(RAFT_GATHER(Metric, Value), ?RAFT_METRICS_MODULE:gather(Metric, Value)).

src/wa_raft_log_catchup.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
-spec init_tables() -> term().
9999
init_tables() ->
100-
wa_pt:put(?COUNTER_KEY, counters:new(?COUNTER_COUNT, [atomics])),
100+
persistent_term:put(?COUNTER_KEY, counters:new(?COUNTER_COUNT, [atomics])),
101101
?MODULE = ets:new(?MODULE, [set, public, named_table, {read_concurrency, true}]).
102102

103103
-spec child_spec(Options :: #raft_options{}) -> supervisor:child_spec().
@@ -228,7 +228,7 @@ send_logs(Peer, NextLogIndex, LeaderTerm, LeaderCommitIndex, Witness, #state{nam
228228
LockoutMillis = maps:get(Peer, Lockouts, 0),
229229
NewState = case LockoutMillis =< StartMillis of
230230
true ->
231-
Counters = wa_pt:get(?COUNTER_KEY),
231+
Counters = persistent_term:get(?COUNTER_KEY),
232232
case counters:get(Counters, ?COUNTER_CONCURRENT_CATCHUP) < ?RAFT_MAX_CONCURRENT_LOG_CATCHUP() of
233233
true ->
234234
counters:add(Counters, ?COUNTER_CONCURRENT_CATCHUP, 1),
@@ -241,7 +241,7 @@ send_logs(Peer, NextLogIndex, LeaderTerm, LeaderCommitIndex, Witness, #state{nam
241241
[Name, LeaderTerm, Peer, T, E, S]
242242
)
243243
after
244-
counters:sub(wa_pt:get(?COUNTER_KEY), ?COUNTER_CONCURRENT_CATCHUP, 1)
244+
counters:sub(persistent_term:get(?COUNTER_KEY), ?COUNTER_CONCURRENT_CATCHUP, 1)
245245
end,
246246
EndMillis = erlang:system_time(millisecond),
247247
?RAFT_GATHER('raft.leader.catchup.duration', (EndMillis - StartMillis) * 1000),

src/wa_raft_metrics.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
%% RAFT metrics with the provided module.
5959
-spec install(Module :: module()) -> ok.
6060
install(Module) ->
61-
wa_pt:put(?RAFT_METRICS_MODULE_KEY, Module).
61+
persistent_term:put(?RAFT_METRICS_MODULE_KEY, Module).
6262

6363
%%-------------------------------------------------------------------
6464
%% Default Implementation

src/wa_raft_part_sup.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ start_link(Application, Spec) ->
8585
%% The RAFT options for a table are not expected to change during the
8686
%% runtime of the RAFT application and so repeated updates should not
8787
%% result in any GC load. Warn if this is case.
88-
PrevOptions = wa_pt:get(?OPTIONS_KEY(Table, Partition), Options),
88+
PrevOptions = persistent_term:get(?OPTIONS_KEY(Table, Partition), Options),
8989
PrevOptions =/= Options andalso
9090
?RAFT_LOG_WARNING(
9191
?MODULE_STRING " storing changed options for RAFT partitition ~0p/~0p",
9292
[Table, Partition]
9393
),
94-
ok = wa_pt:put(?OPTIONS_KEY(Table, Partition), Options),
94+
ok = persistent_term:put(?OPTIONS_KEY(Table, Partition), Options),
9595

9696
supervisor:start_link({local, Name}, ?MODULE, Options).
9797

@@ -131,7 +131,7 @@ registered_partition_path(Table, Partition) ->
131131

132132
-spec options(Table :: wa_raft:table(), Partition :: wa_raft:partition()) -> #raft_options{} | undefined.
133133
options(Table, Partition) ->
134-
wa_pt:get(?OPTIONS_KEY(Table, Partition), undefined).
134+
persistent_term:get(?OPTIONS_KEY(Table, Partition), undefined).
135135

136136
-spec normalize_spec(Application :: atom(), Spec :: wa_raft:args()) -> #raft_options{}.
137137
normalize_spec(Application, #{table := Table, partition := Partition} = Spec) ->
@@ -174,7 +174,7 @@ normalize_spec(Application, #{table := Table, partition := Partition} = Spec) ->
174174
-spec prepare_spec(Application :: atom(), Spec :: wa_raft:args()) -> #raft_options{}.
175175
prepare_spec(Application, Spec) ->
176176
Options = #raft_options{table = Table, partition = Partition} = normalize_spec(Application, Spec),
177-
ok = wa_pt:put(?OPTIONS_KEY(Table, Partition), Options),
177+
ok = persistent_term:put(?OPTIONS_KEY(Table, Partition), Options),
178178
Options.
179179

180180
%%-------------------------------------------------------------------

src/wa_raft_sup.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ child_spec(Application, RaftArgs, Options) ->
9494

9595
-spec start_link(Application :: atom(), Specs :: [wa_raft:args()], Options :: options()) -> supervisor:startlink_ret().
9696
start_link(Application, RaftArgs, Options) ->
97-
ok = wa_pt:put(?OPTIONS_KEY(Application), normalize_spec(Application, Options)),
97+
ok = persistent_term:put(?OPTIONS_KEY(Application), normalize_spec(Application, Options)),
9898
case supervisor:start_link({local, default_name(Application)}, ?MODULE, Application) of
9999
{ok, Pid} = Result ->
100100
[
@@ -160,7 +160,7 @@ registered_config_apps(Application) ->
160160

161161
-spec options(Application :: atom()) -> #raft_application{} | undefined.
162162
options(Application) ->
163-
wa_pt:get(?OPTIONS_KEY(Application), undefined).
163+
persistent_term:get(?OPTIONS_KEY(Application), undefined).
164164

165165
-spec normalize_spec(Application :: atom(), Options :: options()) -> #raft_application{}.
166166
normalize_spec(Application, Options) ->
@@ -180,7 +180,7 @@ prepare_application(Application) ->
180180
-spec prepare_application(Application :: atom(), Options :: options()) -> ok.
181181
prepare_application(Application, Options) ->
182182
RaftApplication = normalize_spec(Application, Options),
183-
ok = wa_pt:put(?OPTIONS_KEY(Application), RaftApplication).
183+
ok = persistent_term:put(?OPTIONS_KEY(Application), RaftApplication).
184184

185185
%%-------------------------------------------------------------------
186186
%% Supervisor callbacks

0 commit comments

Comments
 (0)