Browse Source

use our logger in autofile/group

pull/2799/head
Anton Kaliaev 6 years ago
parent
commit
d178ea9eaf
3 changed files with 23 additions and 5 deletions
  1. +6
    -0
      consensus/wal.go
  2. +14
    -1
      libs/autofile/autofile.go
  3. +3
    -4
      libs/autofile/group.go

+ 6
- 0
consensus/wal.go View File

@ -13,6 +13,7 @@ import (
amino "github.com/tendermint/go-amino"
auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -95,6 +96,11 @@ func (wal *baseWAL) Group() *auto.Group {
return wal.group
}
func (wal *baseWAL) SetLogger(l log.Logger) {
wal.BaseService.Logger = l
wal.group.SetLogger(l)
}
func (wal *baseWAL) OnStart() error {
size, err := wal.group.Head.Size()
if err != nil {


+ 14
- 1
libs/autofile/autofile.go View File

@ -83,6 +83,8 @@ func OpenAutoFile(path string) (*AutoFile, error) {
return af, nil
}
// Close shuts down the closing goroutine, SIGHUP handler and closes the
// AutoFile.
func (af *AutoFile) Close() error {
af.closeTicker.Stop()
close(af.closeTickerStopc)
@ -116,6 +118,10 @@ func (af *AutoFile) closeFile() (err error) {
return file.Close()
}
// Write writes len(b) bytes to the AutoFile. It returns the number of bytes
// written and an error, if any. Write returns a non-nil error when n !=
// len(b).
// Opens AutoFile if needed.
func (af *AutoFile) Write(b []byte) (n int, err error) {
af.mtx.Lock()
defer af.mtx.Unlock()
@ -130,6 +136,10 @@ func (af *AutoFile) Write(b []byte) (n int, err error) {
return
}
// Sync commits the current contents of the file to stable storage. Typically,
// this means flushing the file system's in-memory copy of recently written
// data to disk.
// Opens AutoFile if needed.
func (af *AutoFile) Sync() error {
af.mtx.Lock()
defer af.mtx.Unlock()
@ -158,6 +168,9 @@ func (af *AutoFile) openFile() error {
return nil
}
// Size returns the size of the AutoFile. It returns -1 and an error if fails
// get stats or open file.
// Opens AutoFile if needed.
func (af *AutoFile) Size() (int64, error) {
af.mtx.Lock()
defer af.mtx.Unlock()
@ -171,10 +184,10 @@ func (af *AutoFile) Size() (int64, error) {
return -1, err
}
}
stat, err := af.file.Stat()
if err != nil {
return -1, err
}
return stat.Size(), nil
}

+ 3
- 4
libs/autofile/group.go View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path"
"path/filepath"
@ -253,18 +252,18 @@ func (g *Group) checkTotalSizeLimit() {
}
if index == gInfo.MaxIndex {
// Special degenerate case, just do nothing.
log.Println("WARNING: Group's head " + g.Head.Path + "may grow without bound")
g.Logger.Info("Group's head may grow without bound", "head", g.Head.Path)
return
}
pathToRemove := filePathForIndex(g.Head.Path, index, gInfo.MaxIndex)
fileInfo, err := os.Stat(pathToRemove)
if err != nil {
log.Println("WARNING: Failed to fetch info for file @" + pathToRemove)
g.Logger.Error("Failed to fetch info for file", "file", pathToRemove)
continue
}
err = os.Remove(pathToRemove)
if err != nil {
log.Println(err)
g.Logger.Error("Failed to remove path", "path", pathToRemove)
return
}
totalSize -= fileInfo.Size()


Loading…
Cancel
Save