Fix minor bug in Consensus WAL; Fix AutoFile dependency
This commit is contained in:
parent
642a24dc9c
commit
830e84adc4
|
@ -2,6 +2,7 @@ package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -80,10 +81,10 @@ func (wal *WAL) Save(clm ConsensusLogMessageInterface) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var clmBytes = wire.JSONBytes(ConsensusLogMessage{time.Now(), clm})
|
||||||
var n int
|
var n int
|
||||||
var err error
|
var err error
|
||||||
wire.WriteJSON(ConsensusLogMessage{time.Now(), clm}, wal.fp, &n, &err)
|
wire.WriteTo(append(clmBytes, byte('\n')), wal.fp, &n, &err) // one message per line
|
||||||
wire.WriteTo([]byte("\n"), wal.fp, &n, &err) // one message per line
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicQ(Fmt("Error writing msg to consensus wal. Error: %v \n\nMessage: %v", err, clm))
|
PanicQ(Fmt("Error writing msg to consensus wal. Error: %v \n\nMessage: %v", err, clm))
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ func (wal *WAL) Wait() {
|
||||||
func (wal *WAL) SeekFromEnd(found func([]byte) bool) (nLines int, err error) {
|
func (wal *WAL) SeekFromEnd(found func([]byte) bool) (nLines int, err error) {
|
||||||
var current int64
|
var current int64
|
||||||
// start at the end
|
// start at the end
|
||||||
current, err = wal.fp.Seek(0, 2)
|
current, err = wal.fp.Seek(0, io.SeekEnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -115,11 +116,11 @@ func (wal *WAL) SeekFromEnd(found func([]byte) bool) (nLines int, err error) {
|
||||||
for {
|
for {
|
||||||
current -= 1
|
current -= 1
|
||||||
if current < 0 {
|
if current < 0 {
|
||||||
wal.fp.Seek(0, 0) // back to beginning
|
wal.fp.Seek(0, io.SeekStart) // back to beginning
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// backup one and read a new byte
|
// backup one and read a new byte
|
||||||
if _, err = wal.fp.Seek(current, 0); err != nil {
|
if _, err = wal.fp.Seek(current, io.SeekStart); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b := make([]byte, 1)
|
b := make([]byte, 1)
|
||||||
|
@ -136,8 +137,8 @@ func (wal *WAL) SeekFromEnd(found func([]byte) bool) (nLines int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if found(lineBytes) {
|
if found(lineBytes) {
|
||||||
wal.fp.Seek(0, 1) // (?)
|
wal.fp.Seek(0, io.SeekCurrent) // (?)
|
||||||
wal.fp.Seek(current, 0)
|
wal.fp.Seek(current, io.SeekStart)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
auto "github.com/tendermint/go-autofile"
|
||||||
"github.com/tendermint/go-clist"
|
"github.com/tendermint/go-clist"
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
cfg "github.com/tendermint/go-config"
|
cfg "github.com/tendermint/go-config"
|
||||||
|
@ -62,7 +63,7 @@ type Mempool struct {
|
||||||
cache *txCache
|
cache *txCache
|
||||||
|
|
||||||
// A log of mempool txs
|
// A log of mempool txs
|
||||||
wal *AutoFile
|
wal *auto.AutoFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
|
func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
|
||||||
|
@ -86,7 +87,7 @@ func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
|
||||||
func (mem *Mempool) initWAL() {
|
func (mem *Mempool) initWAL() {
|
||||||
walFileName := mem.config.GetString("mempool_wal")
|
walFileName := mem.config.GetString("mempool_wal")
|
||||||
if walFileName != "" {
|
if walFileName != "" {
|
||||||
af, err := OpenAutoFile(walFileName)
|
af, err := auto.OpenAutoFile(walFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicSanity(err)
|
PanicSanity(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue