|
@@ -69,6 +69,7 @@ prepare(Index, State) ->
|
|
|
-spec write(_SnapshotDir :: file:filename(), ra_snapshot:meta(), _State :: ra_state()) ->
|
|
-spec write(_SnapshotDir :: file:filename(), ra_snapshot:meta(), _State :: ra_state()) ->
|
|
|
ok | {ok, _BytesWritten :: non_neg_integer()} | {error, ra_snapshot:file_err()}.
|
|
ok | {ok, _BytesWritten :: non_neg_integer()} | {error, ra_snapshot:file_err()}.
|
|
|
write(Dir, Meta, MachineState) ->
|
|
write(Dir, Meta, MachineState) ->
|
|
|
|
|
+ ?tp(dsrepl_snapshot_write, #{meta => Meta, state => MachineState}),
|
|
|
ra_log_snapshot:write(Dir, Meta, MachineState).
|
|
ra_log_snapshot:write(Dir, Meta, MachineState).
|
|
|
|
|
|
|
|
%% Reading a snapshot.
|
|
%% Reading a snapshot.
|
|
@@ -165,6 +166,7 @@ complete_read(RS = #rs{reader = SnapReader, started_at = StartedAt}) ->
|
|
|
-spec begin_accept(_SnapshotDir :: file:filename(), ra_snapshot:meta()) ->
|
|
-spec begin_accept(_SnapshotDir :: file:filename(), ra_snapshot:meta()) ->
|
|
|
{ok, ws()}.
|
|
{ok, ws()}.
|
|
|
begin_accept(Dir, Meta) ->
|
|
begin_accept(Dir, Meta) ->
|
|
|
|
|
+ ?tp(dsrepl_snapshot_accept_started, #{meta => Meta}),
|
|
|
WS = #ws{
|
|
WS = #ws{
|
|
|
phase = machine_state,
|
|
phase = machine_state,
|
|
|
started_at = erlang:monotonic_time(millisecond),
|
|
started_at = erlang:monotonic_time(millisecond),
|
|
@@ -207,7 +209,7 @@ complete_accept(Chunk, WS = #ws{phase = storage_snapshot, writer = SnapWriter0})
|
|
|
?tp(dsrepl_snapshot_write_complete, #{writer => SnapWriter}),
|
|
?tp(dsrepl_snapshot_write_complete, #{writer => SnapWriter}),
|
|
|
_ = emqx_ds_storage_snapshot:release_writer(SnapWriter),
|
|
_ = emqx_ds_storage_snapshot:release_writer(SnapWriter),
|
|
|
Result = complete_accept(WS#ws{writer = SnapWriter}),
|
|
Result = complete_accept(WS#ws{writer = SnapWriter}),
|
|
|
- ?tp(dsrepl_snapshot_accepted, #{shard => shard_id(WS)}),
|
|
|
|
|
|
|
+ ?tp(dsrepl_snapshot_accepted, #{shard => shard_id(WS), state => WS#ws.state}),
|
|
|
Result;
|
|
Result;
|
|
|
{error, Reason} ->
|
|
{error, Reason} ->
|
|
|
?tp(dsrepl_snapshot_write_error, #{reason => Reason, writer => SnapWriter0}),
|
|
?tp(dsrepl_snapshot_write_error, #{reason => Reason, writer => SnapWriter0}),
|
|
@@ -218,7 +220,7 @@ complete_accept(Chunk, WS = #ws{phase = storage_snapshot, writer = SnapWriter0})
|
|
|
complete_accept(WS = #ws{started_at = StartedAt, writer = SnapWriter}) ->
|
|
complete_accept(WS = #ws{started_at = StartedAt, writer = SnapWriter}) ->
|
|
|
ShardId = shard_id(WS),
|
|
ShardId = shard_id(WS),
|
|
|
logger:info(#{
|
|
logger:info(#{
|
|
|
- msg => "dsrepl_snapshot_read_complete",
|
|
|
|
|
|
|
+ msg => "dsrepl_snapshot_write_complete",
|
|
|
shard => ShardId,
|
|
shard => ShardId,
|
|
|
duration_ms => erlang:monotonic_time(millisecond) - StartedAt,
|
|
duration_ms => erlang:monotonic_time(millisecond) - StartedAt,
|
|
|
bytes_written => emqx_ds_storage_snapshot:writer_info(bytes_written, SnapWriter)
|
|
bytes_written => emqx_ds_storage_snapshot:writer_info(bytes_written, SnapWriter)
|