@@ -358,7 +358,7 @@ create_snapshot(ServiceRef) ->
358358create_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 ().
362362make_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
495493handle_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