mirror of https://github.com/tidwall/tile38.git
Prewrite optimization flag
This commit is contained in:
parent
74a47309ec
commit
12b47b39ce
|
@ -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 {
|
||||
|
|
|
@ -92,14 +92,15 @@ type Server struct {
|
|||
exlistmu sync.RWMutex
|
||||
exlist []exitem
|
||||
|
||||
mu sync.RWMutex
|
||||
aof *os.File // active aof file
|
||||
aofbuf []byte // prewrite buffer
|
||||
aofsz int // active size of the aof file
|
||||
qdb *buntdb.DB // hook queue log
|
||||
qidx uint64 // hook queue log last idx
|
||||
cols ds.BTree // data collections
|
||||
expires map[string]map[string]time.Time // synced with cols
|
||||
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
|
||||
qidx uint64 // hook queue log last idx
|
||||
cols ds.BTree // data collections
|
||||
expires map[string]map[string]time.Time // synced with cols
|
||||
|
||||
follows map[*bytes.Buffer]bool
|
||||
fcond *sync.Cond
|
||||
|
@ -473,9 +474,12 @@ func (server *Server) evioServe() error {
|
|||
}
|
||||
|
||||
events.PreWrite = func() {
|
||||
server.mu.Lock()
|
||||
defer server.mu.Unlock()
|
||||
server.flushAOF()
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue