Skip to content

Commit 267d209

Browse files
committed
rename LatestCheckpoint to LatestCheckpointV6
1 parent 29929af commit 267d209

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

ledger/complete/compactor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (c *Compactor) run() {
184184
activeSegmentNum = -1
185185
}
186186

187-
lastCheckpointNum, err := c.checkpointer.LatestCheckpoint()
187+
lastCheckpointNum, err := c.checkpointer.LatestCheckpointV6()
188188
if err != nil {
189189
c.logger.Error().Err(err).Msg("compactor failed to get last checkpoint number")
190190
lastCheckpointNum = -1

ledger/complete/wal/checkpointer.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,14 @@ func NewCheckpointer(wal *DiskWAL, keyByteSize int, forestCapacity int) *Checkpo
116116
}
117117
}
118118

119-
// listCheckpoints returns all the numbers (unsorted) of the checkpoint files, and the number of the last checkpoint.
120-
func (c *Checkpointer) listCheckpoints() ([]int, int, error) {
121-
return ListCheckpoints(c.dir)
119+
// listV6Checkpoints returns V6 checkpoint numbers (unsorted) and the last V6 number.
120+
// This Checkpointer writes V6 only, so its scheduling decisions (LatestCheckpointV6,
121+
// NotCheckpointedSegments, the Checkpoint(to) no-op short-circuit) must track V6
122+
// progress to avoid being misled by stray V7 files dropped in the same directory.
123+
// For cross-version inspection, use the package-level ListCheckpoints or
124+
// ListV7Checkpoints functions.
125+
func (c *Checkpointer) listV6Checkpoints() ([]int, int, error) {
126+
return ListV6Checkpoints(c.dir)
122127
}
123128

124129
// ListCheckpoints returns all the numbers of the checkpoint files (both V6 and V7), and the number of the last checkpoint.
@@ -261,17 +266,19 @@ func (c *Checkpointer) CheckpointsV7() ([]int, error) {
261266
return list, nil
262267
}
263268

264-
// LatestCheckpoint returns number of latest checkpoint or -1 if there are no checkpoints
265-
func (c *Checkpointer) LatestCheckpoint() (int, error) {
266-
_, last, err := c.listCheckpoints()
269+
// LatestCheckpointV6 returns the number of the latest V6 checkpoint, or -1 if
270+
// there are no V6 checkpoints. V7 (payloadless) files in the same directory are
271+
// ignored — see [Checkpointer.listV6Checkpoints] for rationale.
272+
func (c *Checkpointer) LatestCheckpointV6() (int, error) {
273+
_, last, err := c.listV6Checkpoints()
267274
return last, err
268275
}
269276

270277
// NotCheckpointedSegments - returns numbers of segments which are not checkpointed yet,
271278
// or -1, -1 if there are no segments
272279
func (c *Checkpointer) NotCheckpointedSegments() (from, to int, err error) {
273280

274-
latestCheckpoint, err := c.LatestCheckpoint()
281+
latestCheckpoint, err := c.LatestCheckpointV6()
275282
if err != nil {
276283
return -1, -1, fmt.Errorf("cannot get last checkpoint: %w", err)
277284
}
@@ -312,7 +319,7 @@ func (c *Checkpointer) Checkpoint(to int) (err error) {
312319
return fmt.Errorf("cannot get not checkpointed segments: %w", err)
313320
}
314321

315-
latestCheckpoint, err := c.LatestCheckpoint()
322+
latestCheckpoint, err := c.LatestCheckpointV6()
316323
if err != nil {
317324
return fmt.Errorf("cannot get latest checkpoint: %w", err)
318325
}

ledger/complete/wal/checkpointer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func Test_Checkpointing(t *testing.T) {
383383
randomlyModifyFile(t, path.Join(dir, "checkpoint.00000010"))
384384

385385
// make sure 10 is latest checkpoint
386-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
386+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
387387
require.NoError(t, err)
388388
require.Equal(t, 10, latestCheckpoint)
389389

ledger/complete/wal/wal_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func RunWithWALCheckpointerWithFiles(t *testing.T, names ...interface{}) {
4242

4343
func Test_emptyDir(t *testing.T) {
4444
RunWithWALCheckpointerWithFiles(t, func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
45-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
45+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
4646
require.NoError(t, err)
4747
require.Equal(t, -1, latestCheckpoint)
4848

@@ -57,7 +57,7 @@ func Test_emptyDir(t *testing.T) {
5757
// Prometheus WAL require files to be 8 characters, otherwise it gets confused
5858
func Test_noCheckpoints(t *testing.T) {
5959
RunWithWALCheckpointerWithFiles(t, "00000000", "00000001", "00000002", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
60-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
60+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
6161
require.NoError(t, err)
6262
require.Equal(t, -1, latestCheckpoint)
6363

@@ -70,7 +70,7 @@ func Test_noCheckpoints(t *testing.T) {
7070

7171
func Test_someCheckpoints(t *testing.T) {
7272
RunWithWALCheckpointerWithFiles(t, "00000000", "00000001", "00000002", "00000003", "00000004", "00000005", "checkpoint.00000002", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
73-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
73+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
7474
require.NoError(t, err)
7575
require.Equal(t, 2, latestCheckpoint)
7676

@@ -83,7 +83,7 @@ func Test_someCheckpoints(t *testing.T) {
8383

8484
func Test_loneCheckpoint(t *testing.T) {
8585
RunWithWALCheckpointerWithFiles(t, "checkpoint.00000005", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
86-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
86+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
8787
require.NoError(t, err)
8888
require.Equal(t, 5, latestCheckpoint)
8989

@@ -96,15 +96,15 @@ func Test_loneCheckpoint(t *testing.T) {
9696

9797
func Test_lastCheckpointIsFoundByNumericValue(t *testing.T) {
9898
RunWithWALCheckpointerWithFiles(t, "checkpoint.00000005", "checkpoint.00000004", "checkpoint.00000006", "checkpoint.00000002", "checkpoint.00000001", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
99-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
99+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
100100
require.NoError(t, err)
101101
require.Equal(t, 6, latestCheckpoint)
102102
})
103103
}
104104

105105
func Test_checkpointWithoutPrecedingSegments(t *testing.T) {
106106
RunWithWALCheckpointerWithFiles(t, "checkpoint.00000005", "00000006", "00000007", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
107-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
107+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
108108
require.NoError(t, err)
109109
require.Equal(t, 5, latestCheckpoint)
110110

@@ -117,7 +117,7 @@ func Test_checkpointWithoutPrecedingSegments(t *testing.T) {
117117

118118
func Test_checkpointWithSameSegment(t *testing.T) {
119119
RunWithWALCheckpointerWithFiles(t, "checkpoint.00000005", "00000005", "00000006", "00000007", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
120-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
120+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
121121
require.NoError(t, err)
122122
require.Equal(t, 5, latestCheckpoint)
123123

@@ -139,7 +139,7 @@ func Test_listingCheckpoints(t *testing.T) {
139139

140140
func Test_NoGapBetweenSegmentsAndLastCheckpoint(t *testing.T) {
141141
RunWithWALCheckpointerWithFiles(t, "checkpoint.00000004", "00000006", "00000007", func(t *testing.T, wal *DiskWAL, checkpointer *Checkpointer) {
142-
latestCheckpoint, err := checkpointer.LatestCheckpoint()
142+
latestCheckpoint, err := checkpointer.LatestCheckpointV6()
143143
require.NoError(t, err)
144144
require.Equal(t, 4, latestCheckpoint)
145145

0 commit comments

Comments
 (0)