Skip to content

Commit

Permalink
Add ra_log config for the checkpoint interval
Browse files Browse the repository at this point in the history
Initially I have this set at 4x the snapshot interval since you might
spam the `checkpoint` effect more than you would a `release_cursor`
effect.
  • Loading branch information
the-mikedavis committed Jan 26, 2024
1 parent 213bec1 commit 07c9b61
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ra_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

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

-type ra_meta_key() :: atom().
Expand Down Expand Up @@ -84,6 +85,7 @@
log_id :: unicode:chardata(),
directory :: file:filename(),
snapshot_interval = ?SNAPSHOT_INTERVAL :: non_neg_integer(),
checkpoint_interval = ?CHECKPOINT_INTERVAL :: non_neg_integer(),
snapshot_module :: module(),
resend_window_seconds = ?DEFAULT_RESEND_WINDOW_SEC :: integer(),
wal :: atom(),
Expand Down Expand Up @@ -114,6 +116,7 @@
system_config => ra_system:config(),
log_id => unicode:chardata(),
snapshot_interval => non_neg_integer(),
checkpoint_interval => non_neg_integer(),
resend_window => integer(),
max_open_segments => non_neg_integer(),
snapshot_module => module(),
Expand Down Expand Up @@ -152,6 +155,7 @@ init(#{uid := UId,
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),
CPInterval = maps:get(checkpoint_interval, Conf, ?CHECKPOINT_INTERVAL),
SnapshotsDir = filename:join(Dir, "snapshots"),
CheckpointsDir = filename:join(Dir, "checkpoints"),
Counter = maps:get(counter, Conf, undefined),
Expand Down Expand Up @@ -195,6 +199,7 @@ init(#{uid := UId,
uid = UId,
log_id = LogId,
snapshot_interval = SnapInterval,
checkpoint_interval = CPInterval,
wal = Wal,
segment_writer = SegWriter,
resend_window_seconds = ResendWindow,
Expand Down Expand Up @@ -731,8 +736,7 @@ should_snapshot(snapshot, Idx,
ra_log_reader:segment_refs(Reader)),
CanFreeSegments orelse Idx > SnapLimit;
should_snapshot(checkpoint, Idx,
#?MODULE{cfg = #cfg{snapshot_interval = CheckpointInter},
%% ^ TODO: use new cfg var.
#?MODULE{cfg = #cfg{checkpoint_interval = CheckpointInter},
snapshot_state = SnapState}) ->
CheckpointLimit = case ra_snapshot:latest_checkpoint(SnapState) of
undefined -> CheckpointInter;
Expand Down

0 comments on commit 07c9b61

Please sign in to comment.