cs: update wal comments (#3334)

* cs: update wal comments

Follow-up to https://github.com/tendermint/tendermint/pull/3300

* Update consensus/wal.go

Co-Authored-By: melekes <anton.kalyaev@gmail.com>
This commit is contained in:
Anton Kaliaev
2019-02-21 18:28:02 +04:00
committed by GitHub
parent 4f83eec782
commit ed1de13548

View File

@ -67,9 +67,10 @@ type WAL interface {
} }
// Write ahead logger writes msgs to disk before they are processed. // Write ahead logger writes msgs to disk before they are processed.
// Can be used for crash-recovery and deterministic replay // Can be used for crash-recovery and deterministic replay.
// TODO: currently the wal is overwritten during replay catchup // TODO: currently the wal is overwritten during replay catchup, give it a mode
// give it a mode so it's either reading or appending - must read to end to start appending again // so it's either reading or appending - must read to end to start appending
// again.
type baseWAL struct { type baseWAL struct {
cmn.BaseService cmn.BaseService
@ -81,9 +82,8 @@ type baseWAL struct {
flushInterval time.Duration flushInterval time.Duration
} }
// NewWAL attempts to create a new write-ahead logger based on `baseWAL`, which // NewWAL returns a new write-ahead logger based on `baseWAL`, which implements
// implements all of the required WAL functionality. This base WAL also flushes // WAL. It's flushed and synced to disk every 2s and once when stopped.
// data to disk every 2s.
func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) { func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) {
err := cmn.EnsureDir(filepath.Dir(walFile), 0700) err := cmn.EnsureDir(filepath.Dir(walFile), 0700)
if err != nil { if err != nil {
@ -130,13 +130,11 @@ func (wal *baseWAL) OnStart() error {
return err return err
} }
// processFlushTicks allows us to periodically attempt to sync the WAL to disk.
func (wal *baseWAL) processFlushTicks() { func (wal *baseWAL) processFlushTicks() {
for { for {
select { select {
case <-wal.flushTicker.C: case <-wal.flushTicker.C:
err := wal.Flush() if err := wal.Flush(); err != nil {
if err != nil {
wal.Logger.Error("Periodic WAL flush failed", "err", err) wal.Logger.Error("Periodic WAL flush failed", "err", err)
} }
case <-wal.Quit(): case <-wal.Quit():
@ -145,7 +143,7 @@ func (wal *baseWAL) processFlushTicks() {
} }
} }
// Flush will attempt to flush the underlying group's data to disk. // Flush will attempt to flush and fsync the underlying group's data to disk.
func (wal *baseWAL) Flush() error { func (wal *baseWAL) Flush() error {
return wal.group.Flush() return wal.group.Flush()
} }