From 86df5a0edb97ecae5a1f8fe2e9d2dc8f285fe5ad Mon Sep 17 00:00:00 2001 From: Sarah Hassan Date: Tue, 2 Apr 2024 14:18:46 -0700 Subject: [PATCH] pass raft_identifier to open_storage callback 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 --- src/wa_raft_storage.erl | 6 +++--- src/wa_raft_storage_ets.erl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wa_raft_storage.erl b/src/wa_raft_storage.erl index 57b37b5..7c24185 100644 --- a/src/wa_raft_storage.erl +++ b/src/wa_raft_storage.erl @@ -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. @@ -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.", diff --git a/src/wa_raft_storage_ets.erl b/src/wa_raft_storage_ets.erl index 5762d12..a45df89 100644 --- a/src/wa_raft_storage_ets.erl +++ b/src/wa_raft_storage_ets.erl @@ -12,7 +12,7 @@ -behaviour(wa_raft_storage). -export([ - storage_open/4, + storage_open/3, storage_close/1, storage_position/1, storage_apply/3, @@ -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}.