29 lines
503 B
Go
29 lines
503 B
Go
|
package rep
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func (rep *Replicator) runWALGC() {
|
||
|
defer rep.done.Done()
|
||
|
|
||
|
ticker := time.NewTicker(time.Minute)
|
||
|
defer ticker.Stop()
|
||
|
|
||
|
for {
|
||
|
select {
|
||
|
case <-ticker.C:
|
||
|
state := rep.getState()
|
||
|
before := time.Now().Unix() - rep.conf.WALSegMaxAgeSec
|
||
|
if err := rep.wal.DeleteBefore(before, state.SeqNum); err != nil {
|
||
|
log.Printf("[WAL-GC] failed to delete wal segments: %v", err)
|
||
|
}
|
||
|
// OK
|
||
|
case <-rep.stop:
|
||
|
log.Print("[WAL-GC] Stopped")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|