Skip to content

Commit

Permalink
pass raft_identifier to open_storage callback
Browse files Browse the repository at this point in the history
Summary:
This change passes the `raft_identifier` to the `open_storage` callback in the `wa_raft_storage` module.
The `raft_identifier` is a struct that contains the table and partition information for the RAFT partition being used alongside the application name as well.

Differential Revision: D55654893

fbshipit-source-id: 964c6c25768f9ced9756b61c211ba56934d58b55
  • Loading branch information
Sarah Hassan authored and facebook-github-bot committed Apr 2, 2024
1 parent 8563bf6 commit 86df5a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/wa_raft_storage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
%%-----------------------------------------------------------------------------

%% Open the storage state for the specified RAFT partition.
-callback storage_open(Name :: atom(), Table :: wa_raft:table(), Partition :: wa_raft:partition(), PartitionPath :: file:filename()) -> Handle :: storage_handle().
-callback storage_open(Name :: atom(), RaftIdentifier :: #raft_identifier{}, PartitionPath :: file:filename()) -> Handle :: storage_handle().

%% Get any custom status to be reported alongside the status reported by the
%% RAFT storage server.
Expand Down Expand Up @@ -366,13 +366,13 @@ registered_name(Table, Partition) ->
%%-------------------------------------------------------------------

-spec init(Options :: #raft_options{}) -> {ok, #state{}}.
init(#raft_options{table = Table, partition = Partition, database = RootDir, storage_name = Name, storage_module = Module}) ->
init(#raft_options{application = App, table = Table, partition = Partition, database = RootDir, storage_name = Name, storage_module = Module}) ->
process_flag(trap_exit, true),

?LOG_NOTICE("Storage[~0p] starting for partition ~0p/~0p at ~0p using ~0p",
[Name, Table, Partition, RootDir, Module], #{domain => [whatsapp, wa_raft]}),

Handle = Module:storage_open(Name, Table, Partition, RootDir),
Handle = Module:storage_open(Name, #raft_identifier{application = App, table = Table, partition = Partition}, RootDir),
LastApplied = Module:storage_position(Handle),

?LOG_NOTICE("Storage[~0p] opened at position ~0p.",
Expand Down
6 changes: 3 additions & 3 deletions src/wa_raft_storage_ets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-behaviour(wa_raft_storage).

-export([
storage_open/4,
storage_open/3,
storage_close/1,
storage_position/1,
storage_apply/3,
Expand All @@ -38,8 +38,8 @@
position = #raft_log_pos{} :: wa_raft_log:log_pos()
}).

-spec storage_open(atom(), wa_raft:table(), wa_raft:partition(), file:filename()) -> #state{}.
storage_open(Name, Table, Partition, _RootDir) ->
-spec storage_open(atom(), #raft_identifier{}, file:filename()) -> #state{}.
storage_open(Name, #raft_identifier{table = Table, partition = Partition}, _RootDir) ->
Name = ets:new(Name, [set, named_table, public, {read_concurrency, true}, {write_concurrency, true}]),
#state{name = Name, table = Table, partition = Partition}.

Expand Down

0 comments on commit 86df5a0

Please sign in to comment.