Prewrite optimization flag

This commit is contained in:
tidwall 2018-11-10 16:16:04 -07:00
parent 74a47309ec
commit 12b47b39ce
2 changed files with 17 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/tidwall/buntdb"
@ -152,6 +153,7 @@ func (server *Server) writeAOF(args []string, d *commandDetailsT) error {
}
if server.aof != nil {
atomic.StoreInt32(&server.aofdirty, 1) // prewrite optimization flag
n := len(server.aofbuf)
server.aofbuf = redcon.AppendArray(server.aofbuf, len(args))
for _, arg := range args {

View File

@ -94,6 +94,7 @@ type Server struct {
mu sync.RWMutex
aof *os.File // active aof file
aofdirty int32 // mark the aofbuf as having data
aofbuf []byte // prewrite buffer
aofsz int // active size of the aof file
qdb *buntdb.DB // hook queue log
@ -473,9 +474,12 @@ func (server *Server) evioServe() error {
}
events.PreWrite = func() {
if atomic.LoadInt32(&server.aofdirty) != 0 {
server.mu.Lock()
defer server.mu.Unlock()
server.flushAOF()
atomic.StoreInt32(&server.aofdirty, 1)
}
}
return evio.Serve(events, fmt.Sprintf("%s:%d", server.host, server.port))