Mempool WAL

This commit is contained in:
Jae Kwon
2016-10-17 16:54:51 -07:00
parent eab4e1cfa1
commit 642a24dc9c
3 changed files with 25 additions and 0 deletions

View File

@@ -84,6 +84,7 @@ func GetConfig(rootDir string) cfg.Config {
mapConfig.SetDefault("mempool_recheck", true)
mapConfig.SetDefault("mempool_recheck_empty", true)
mapConfig.SetDefault("mempool_broadcast", true)
mapConfig.SetDefault("mempool_wal", rootDir+"/data/mempool_wal")
return mapConfig
}

View File

@@ -97,6 +97,7 @@ func ResetConfig(localPath string) cfg.Config {
mapConfig.SetDefault("mempool_recheck", true)
mapConfig.SetDefault("mempool_recheck_empty", true)
mapConfig.SetDefault("mempool_broadcast", true)
mapConfig.SetDefault("mempool_wal", "")
return mapConfig
}

View File

@@ -60,6 +60,9 @@ type Mempool struct {
// Keep a cache of already-seen txs.
// This reduces the pressure on the proxyApp.
cache *txCache
// A log of mempool txs
wal *AutoFile
}
func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
@@ -75,10 +78,22 @@ func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
cache: newTxCache(cacheSize),
}
mempool.initWAL()
proxyAppConn.SetResponseCallback(mempool.resCb)
return mempool
}
func (mem *Mempool) initWAL() {
walFileName := mem.config.GetString("mempool_wal")
if walFileName != "" {
af, err := OpenAutoFile(walFileName)
if err != nil {
PanicSanity(err)
}
mem.wal = af
}
}
// consensus must be able to hold lock to safely update
func (mem *Mempool) Lock() {
mem.proxyMtx.Lock()
@@ -138,6 +153,14 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*tmsp.Response)) (err error) {
mem.cache.Push(tx)
// END CACHE
// WAL
if mem.wal != nil {
// TODO: Notify administrators when WAL fails
mem.wal.Write([]byte(tx))
mem.wal.Write([]byte("\n"))
}
// END WAL
// NOTE: proxyAppConn may error if tx buffer is full
if err = mem.proxyAppConn.Error(); err != nil {
return err