Skip to content

Commit d5275e1

Browse files
Sarah Hassanfacebook-github-bot
authored andcommitted
Back out "have wa_raft_storage:make_empty_snapshot return last applied log position"
Summary: Original commit changeset: 6e8617b239d5 Original Phabricator Diff: D72344559 Reviewed By: hsun324 Differential Revision: D72418888 fbshipit-source-id: 892bcb6a6239a570cab2a5ab268e85c74215988b
1 parent 324f02b commit d5275e1

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

src/wa_raft_server.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ stalled({call, From}, ?BOOTSTRAP_COMMAND(#raft_log_pos{index = Index, term = Ter
764764
[Name, CurrentTerm, Index, Term, Config, Data, 30], #{domain => [whatsapp, wa_raft]}),
765765
Path = filename:join(PartitionPath, io_lib:format("snapshot.~0p.~0p.bootstrap.tmp", [Index, Term])),
766766
try
767-
{ok, _} = wa_raft_storage:make_empty_snapshot(Storage, Path, Position, Config, Data),
767+
ok = wa_raft_storage:make_empty_snapshot(Storage, Path, Position, Config, Data),
768768
ok = wa_raft_storage:open_snapshot(Storage, Path, Position),
769769
{ok, NewView} = wa_raft_log:reset(View, Position),
770770
State1 = State0#raft_state{log_view = NewView, last_applied = Index, commit_index = Index},

src/wa_raft_storage.erl

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ create_snapshot(ServiceRef) ->
358358
create_snapshot(ServiceRef, Name) ->
359359
gen_server:call(ServiceRef, {snapshot_create, Name}, ?RAFT_STORAGE_CALL_TIMEOUT()).
360360

361-
-spec make_empty_snapshot(ServiceRef :: pid() | atom(), Path :: file:filename(), Position :: wa_raft_log:log_pos(), Config :: wa_raft_server:config(), Data :: dynamic()) -> {ok, Pos :: wa_raft_log:log_pos()} | error().
361+
-spec make_empty_snapshot(ServiceRef :: pid() | atom(), Path :: file:filename(), Position :: wa_raft_log:log_pos(), Config :: wa_raft_server:config(), Data :: term()) -> ok | error().
362362
make_empty_snapshot(ServiceRef, Path, Position, Config, Data) ->
363363
gen_server:call(ServiceRef, {make_empty_snapshot, Path, Position, Config, Data}).
364364

@@ -453,7 +453,7 @@ init(#raft_options{table = Table, partition = Partition, identifier = Identifier
453453
status |
454454
{snapshot_create, Name :: string()} |
455455
{snapshot_open, Path :: file:filename(), LastAppliedPos :: wa_raft_log:log_pos()} |
456-
{make_empty_snapshot, Path :: file:filename(), Position :: wa_raft_log:log_pos(), Config :: wa_raft_server:config(), Data :: dynamic()} |
456+
{make_empty_snapshot, Path :: file:filename(), Position :: wa_raft_log:log_pos(), Config :: wa_raft_server:config(), Data :: term()} |
457457
position |
458458
label |
459459
config.
@@ -467,10 +467,10 @@ handle_call(snapshot_create, From, #state{last_applied = #raft_log_pos{index = L
467467
Name = ?SNAPSHOT_NAME(LastIndex, LastTerm),
468468
handle_call({snapshot_create, Name}, From, State);
469469

470-
handle_call({snapshot_create, Name}, _From, #state{last_applied = LastApplied} = State) ->
470+
handle_call({snapshot_create, Name}, _From, #state{last_applied = #raft_log_pos{index = LastIndex, term = LastTerm}} = State) ->
471471
case create_snapshot_impl(Name, State) of
472472
ok ->
473-
{reply, {ok, LastApplied}, State};
473+
{reply, {ok, #raft_log_pos{index = LastIndex, term = LastTerm}}, State};
474474
{error, _} = Error ->
475475
{reply, Error, State}
476476
end;
@@ -482,14 +482,12 @@ handle_call({snapshot_open, SnapshotPath, LogPos}, _From, #state{name = Name, mo
482482
{error, Reason} -> {reply, {error, Reason}, State}
483483
end;
484484

485-
handle_call({make_empty_snapshot, Path, Position, Config, Data}, _From, #state{name = Name, identifier = Identifier, last_applied = LastApplied} = State) ->
485+
handle_call({make_empty_snapshot, Path, Position, Config, Data}, _From, #state{name = Name, identifier = Identifier, module = Module} = State) ->
486486
?LOG_NOTICE("Storage[~0p] making bootstrap snapshot ~0p at ~0p with config ~0p and data ~0P.",
487487
[Name, Path, Position, Config, Data, 30], #{domain => [whatsapp, wa_raft]}),
488-
case create_empty_snapshot_impl(Name, Identifier, Path, Position, Config, Data, State) of
489-
ok ->
490-
{reply, {ok, LastApplied}, State};
491-
{error, _} = Error ->
492-
{reply, Error, State}
488+
case erlang:function_exported(Module, storage_make_empty_snapshot, 6) of
489+
true -> {reply, Module:storage_make_empty_snapshot(Name, Identifier, Path, Position, Config, Data), State};
490+
false -> {reply, {error, not_supported}, State}
493491
end;
494492

495493
handle_call(config, _From, #state{module = Module, handle = Handle} = State) ->
@@ -639,21 +637,6 @@ create_snapshot_impl(SnapName, #state{name = Name, root_dir = RootDir, module =
639637
Module:storage_create_snapshot(SnapshotPath, Handle)
640638
end.
641639

642-
-spec create_empty_snapshot_impl(
643-
Name :: atom(),
644-
Identifier :: #raft_identifier{},
645-
Path :: file:filename(),
646-
Position :: wa_raft_log:log_pos(),
647-
Config :: wa_raft_server:config(),
648-
Data :: #{virtual_partition_range := kvdb_core:virtual_partition_range()},
649-
Storage :: #state{}
650-
) -> ok | error().
651-
create_empty_snapshot_impl(Name, Identifier, Path, Position, Config, Data, #state{module = Module}) ->
652-
case erlang:function_exported(Module, storage_make_empty_snapshot, 6) of
653-
true -> Module:storage_make_empty_snapshot(Name, Identifier, Path, Position, Config, Data);
654-
false -> {error, not_supported}
655-
end.
656-
657640
-define(MAX_RETAINED_SNAPSHOT, 1).
658641

659642
-spec cleanup_snapshots(#state{}) -> ok.

0 commit comments

Comments
 (0)