Skip to content

Commit 1b787a4

Browse files
committed
wal: consolidate LogRecycler.[Set]MinRecycleLogNum
These MinRecycleLogNum and SetMinRecycleLogNum methods were only used to ratchet the minimum log num, so this commit consolidates the two under a RatchetMinRecycleLogNum method.
1 parent cd44965 commit 1b787a4

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

wal/failover_manager.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,7 @@ func (wm *failoverManager) init(o Options, initial Logs) error {
526526
}
527527
wm.recycler.Init(o.MaxNumRecyclableLogs)
528528
for _, ll := range initial {
529-
if wm.recycler.MinRecycleLogNum() <= ll.Num {
530-
wm.recycler.SetMinRecycleLogNum(ll.Num + 1)
531-
}
529+
wm.recycler.RatchetMinRecycleLogNum(ll.Num + 1)
532530
var err error
533531
wm.initialObsolete, err = appendDeletableLogs(wm.initialObsolete, ll)
534532
if err != nil {

wal/failover_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestManagerFailover(t *testing.T) {
382382
var b strings.Builder
383383
fmt.Fprintf(&b, "%s\n", errorToStr(err))
384384
if err == nil {
385-
fmt.Fprintf(&b, "recycler min-log-num: %d\n", fm.recycler.MinRecycleLogNum())
385+
fmt.Fprintf(&b, "recycler min-log-num: %d\n", fm.recycler.minRecycleLogNum)
386386
}
387387
return b.String()
388388

wal/log_recycler.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ func (r *LogRecycler) Init(maxNumLogFiles int) {
4040
r.limit = maxNumLogFiles
4141
}
4242

43-
// MinRecycleLogNum returns the current minimum log number that is allowed to
44-
// be recycled.
45-
func (r *LogRecycler) MinRecycleLogNum() NumWAL {
46-
return NumWAL(r.minRecycleLogNum)
47-
}
48-
49-
// SetMinRecycleLogNum sets the minimum log number that is allowed to be
50-
// recycled.
51-
func (r *LogRecycler) SetMinRecycleLogNum(n NumWAL) {
52-
r.minRecycleLogNum = base.DiskFileNum(n)
43+
// RatchetMinRecycleLogNum ratchets the minimum log number that is allowed to be
44+
// recycled to be at least as high as the given log number.
45+
func (r *LogRecycler) RatchetMinRecycleLogNum(n NumWAL) {
46+
if num := base.DiskFileNum(n); num > r.minRecycleLogNum {
47+
r.minRecycleLogNum = num
48+
}
5349
}
5450

5551
// Add attempts to recycle the log file specified by logInfo. Returns true if

wal/standalone_manager.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ func (m *StandaloneManager) init(o Options, initial Logs) error {
6767
return err
6868
}
6969
for _, ll := range initial {
70-
if m.recycler.MinRecycleLogNum() <= ll.Num {
71-
m.recycler.SetMinRecycleLogNum(ll.Num + 1)
72-
}
70+
m.recycler.RatchetMinRecycleLogNum(ll.Num + 1)
7371
m.initialObsolete, err = appendDeletableLogs(m.initialObsolete, ll)
7472
if err != nil {
7573
return closeAndReturnErr(err)

0 commit comments

Comments
 (0)