Skip to content

Commit cde0eb4

Browse files
committed
backup: enforce a minimum compaction window size of 3
Previously, the minimum compaction window size was set to 2. With a compaction window of 2, if a chain is at length `n` prior to a backup that triggers a compaction, the length of the chain after compaction is also `n`. Under these conditions, if compactions fail/are blocked for any reason and the length of the chain exceeds the threshold set by `backup.compaction.threshold`, the chain will never recover and drop below the threshold. This patch enforces that the minimum compaction window size is at least 3. That way, if the length of the chain exceeds the threshold, each successful compaction afterwards will always bring the chain closer to the threshold. This allows compactions to self-correct the chain to be under the threshold. Epic: None Release note: `backup.compaction.window_size` must be at least 3 instead of 2.
1 parent c98cf90 commit cde0eb4

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

pkg/backup/compaction_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252
"the required backup chain length for compaction to be triggered (0 to disable compactions)",
5353
0,
5454
settings.WithVisibility(settings.Reserved),
55-
settings.IntInRangeOrZeroDisable(3, math.MaxInt64),
55+
settings.IntInRangeOrZeroDisable(4, math.MaxInt64),
5656
)
5757
)
5858

pkg/backup/compaction_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ var (
2020
backupCompactionWindow = settings.RegisterIntSetting(
2121
settings.ApplicationLevel,
2222
"backup.compaction.window_size",
23-
"the number of backups to compact per compaction (must be greater than one and less than threshold)",
23+
"the number of backups to compact per compaction (must be greater than two and less than threshold)",
2424
3,
2525
settings.WithVisibility(settings.Reserved),
26-
settings.IntWithMinimum(2),
26+
settings.IntWithMinimum(3),
2727
)
2828
)
2929

pkg/backup/compaction_test.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ func TestScheduledBackupCompaction(t *testing.T) {
458458
// impacted by when the test runs.
459459
th.env.SetTime(time.Date(2025, 3, 27, 1, 0, 0, 0, time.UTC))
460460

461-
th.sqlDB.Exec(t, "SET CLUSTER SETTING backup.compaction.threshold = 3")
462-
th.sqlDB.Exec(t, "SET CLUSTER SETTING backup.compaction.window_size = 2")
461+
th.sqlDB.Exec(t, "SET CLUSTER SETTING backup.compaction.threshold = 4")
462+
th.sqlDB.Exec(t, "SET CLUSTER SETTING backup.compaction.window_size = 3")
463463
schedules, err := th.createBackupSchedule(
464464
t, "CREATE SCHEDULE FOR BACKUP INTO $1 RECURRING '@hourly'", "nodelocal://1/backup",
465465
)
@@ -477,21 +477,15 @@ func TestScheduledBackupCompaction(t *testing.T) {
477477
var backupPath string
478478
th.sqlDB.QueryRow(t, "SHOW BACKUPS IN 'nodelocal://1/backup'").Scan(&backupPath)
479479

480-
inc, err = jobs.ScheduledJobDB(th.internalDB()).
481-
Load(context.Background(), th.env, inc.ScheduleID())
482-
require.NoError(t, err)
483-
484-
th.env.SetTime(inc.NextRun().Add(time.Second))
485-
require.NoError(t, th.executeSchedules())
486-
th.waitForSuccessfulScheduledJob(t, inc.ScheduleID())
487-
488-
inc, err = jobs.ScheduledJobDB(th.internalDB()).
489-
Load(context.Background(), th.env, inc.ScheduleID())
490-
require.NoError(t, err)
480+
for range 3 {
481+
inc, err = jobs.ScheduledJobDB(th.internalDB()).
482+
Load(context.Background(), th.env, inc.ScheduleID())
483+
require.NoError(t, err)
491484

492-
th.env.SetTime(inc.NextRun().Add(time.Second))
493-
require.NoError(t, th.executeSchedules())
494-
th.waitForSuccessfulScheduledJob(t, inc.ScheduleID())
485+
th.env.SetTime(inc.NextRun().Add(time.Second))
486+
require.NoError(t, th.executeSchedules())
487+
th.waitForSuccessfulScheduledJob(t, inc.ScheduleID())
488+
}
495489

496490
if blockCompaction != nil {
497491
t.Log("executing second full backup before compaction job resolves destination")
@@ -535,7 +529,7 @@ func TestScheduledBackupCompaction(t *testing.T) {
535529
fmt.Sprintf("SELECT count(DISTINCT (start_time, end_time)) FROM "+
536530
"[SHOW BACKUP FROM '%s' IN 'nodelocal://1/backup']", backupPath),
537531
).Scan(&numBackups)
538-
require.Equal(t, 4, numBackups)
532+
require.Equal(t, 5, numBackups)
539533
}
540534

541535
func TestBackupCompactionUnsupportedOptions(t *testing.T) {

0 commit comments

Comments
 (0)