Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ra_log snapshot_interval parameter to min_snapshot_interval #422

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/ra_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
-include("ra.hrl").

-define(DEFAULT_RESEND_WINDOW_SEC, 20).
-define(SNAPSHOT_INTERVAL, 4096).
-define(MIN_SNAPSHOT_INTERVAL, 4096).
-define(MIN_CHECKPOINT_INTERVAL, 16384).
-define(LOG_APPEND_TIMEOUT, 5000).

Expand Down Expand Up @@ -84,7 +84,7 @@
-record(cfg, {uid :: ra_uid(),
log_id :: unicode:chardata(),
directory :: file:filename(),
snapshot_interval = ?SNAPSHOT_INTERVAL :: non_neg_integer(),
min_snapshot_interval = ?MIN_SNAPSHOT_INTERVAL :: non_neg_integer(),
min_checkpoint_interval = ?MIN_CHECKPOINT_INTERVAL :: non_neg_integer(),
snapshot_module :: module(),
resend_window_seconds = ?DEFAULT_RESEND_WINDOW_SEC :: integer(),
Expand Down Expand Up @@ -115,7 +115,11 @@
-type ra_log_init_args() :: #{uid := ra_uid(),
system_config => ra_system:config(),
log_id => unicode:chardata(),
%% Deprecated in favor of `min_snapshot_interval'
%% but this value is used as a fallback if
%% `min_snapshot_interval' is not provided.
snapshot_interval => non_neg_integer(),
min_snapshot_interval => non_neg_integer(),
min_checkpoint_interval => non_neg_integer(),
resend_window => integer(),
max_open_segments => non_neg_integer(),
Expand Down Expand Up @@ -155,7 +159,9 @@ init(#{uid := UId,
%% this has to be patched by ra_server
LogId = maps:get(log_id, Conf, UId),
ResendWindow = maps:get(resend_window, Conf, ?DEFAULT_RESEND_WINDOW_SEC),
SnapInterval = maps:get(snapshot_interval, Conf, ?SNAPSHOT_INTERVAL),
SnapInterval = maps:get(min_snapshot_interval, Conf,
maps:get(snapshot_interval, Conf,
?MIN_SNAPSHOT_INTERVAL)),
CPInterval = maps:get(min_checkpoint_interval, Conf,
?MIN_CHECKPOINT_INTERVAL),
MaxCheckpoints = maps:get(max_checkpoints, Conf, ?DEFAULT_MAX_CHECKPOINTS),
Expand Down Expand Up @@ -201,7 +207,7 @@ init(#{uid := UId,
Cfg = #cfg{directory = Dir,
uid = UId,
log_id = LogId,
snapshot_interval = SnapInterval,
min_snapshot_interval = SnapInterval,
min_checkpoint_interval = CPInterval,
wal = Wal,
segment_writer = SegWriter,
Expand Down Expand Up @@ -723,7 +729,7 @@ suggest_snapshot0(SnapKind, Idx, Cluster, MacVersion, MacState, State0) ->
end.

should_snapshot(snapshot, Idx,
#?MODULE{cfg = #cfg{snapshot_interval = SnapInter},
#?MODULE{cfg = #cfg{min_snapshot_interval = SnapInter},
reader = Reader,
snapshot_state = SnapState}) ->
SnapLimit = case ra_snapshot:current(SnapState) of
Expand Down
2 changes: 1 addition & 1 deletion test/coordination_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ recover_from_checkpoint(Config) ->
machine => {module, ?MODULE, #{}},
log_init_args => #{uid => UId,
min_checkpoint_interval => 3,
snapshot_interval => 5}}
min_snapshot_interval => 5}}
end || {Name, _Node} = NodeId <- ServerIds],
{ok, Started, []} = ra:start_cluster(?SYS, Configs),
{ok, _, Leader} = ra:members(hd(Started)),
Expand Down
10 changes: 5 additions & 5 deletions test/ra_log_2_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ sparse_read(Config) ->
ok.

written_event_after_snapshot(Config) ->
Log0 = ra_log_init(Config, #{snapshot_interval => 1}),
Log0 = ra_log_init(Config, #{min_snapshot_interval => 1}),
Log1 = ra_log:append({1, 1, <<"one">>}, Log0),
Log1b = ra_log:append({2, 1, <<"two">>}, Log1),
{Log2, _} = ra_log:update_release_cursor(2, #{}, 1,
Expand Down Expand Up @@ -429,7 +429,7 @@ updated_segment_can_be_read(Config) ->
ra_counters:new(?FUNCTION_NAME, ?RA_COUNTER_FIELDS),
Log0 = ra_log_init(Config,
#{counter => ra_counters:fetch(?FUNCTION_NAME),
snapshot_interval => 1}),
min_snapshot_interval => 1}),
%% append a few entries
Log2 = append_and_roll(1, 5, 1, Log0),
% Log2 = deliver_all_log_events(Log1, 200),
Expand Down Expand Up @@ -695,7 +695,7 @@ detect_lost_written_range(Config) ->


snapshot_written_after_installation(Config) ->
Log0 = ra_log_init(Config, #{snapshot_interval => 2}),
Log0 = ra_log_init(Config, #{min_snapshot_interval => 2}),
%% log 1 .. 9, should create a single segment
Log1 = write_and_roll(1, 10, 1, Log0),
{Log2, _} = ra_log:update_release_cursor(5, #{}, 1,
Expand Down Expand Up @@ -734,7 +734,7 @@ snapshot_written_after_installation(Config) ->
%% assert there is no pending snapshot
?assertEqual(undefined, ra_snapshot:pending(ra_log:snapshot_state(Log5))),

_ = ra_log:close(ra_log_init(Config, #{snapshot_interval => 2})),
_ = ra_log:close(ra_log_init(Config, #{min_snapshot_interval => 2})),

ok.

Expand Down Expand Up @@ -931,7 +931,7 @@ update_release_cursor(Config) ->

update_release_cursor_with_machine_version(Config) ->
% ra_log should initiate shapshot if segments can be released
Log0 = ra_log_init(Config, #{snapshot_interval => 64}),
Log0 = ra_log_init(Config, #{min_snapshot_interval => 64}),
% beyond 128 limit - should create two segments
Log1 = append_and_roll(1, 150, 2, Log0),
timer:sleep(300),
Expand Down
Loading