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"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/buntdb"
|
"github.com/tidwall/buntdb"
|
||||||
|
@ -152,6 +153,7 @@ func (server *Server) writeAOF(args []string, d *commandDetailsT) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.aof != nil {
|
if server.aof != nil {
|
||||||
|
atomic.StoreInt32(&server.aofdirty, 1) // prewrite optimization flag
|
||||||
n := len(server.aofbuf)
|
n := len(server.aofbuf)
|
||||||
server.aofbuf = redcon.AppendArray(server.aofbuf, len(args))
|
server.aofbuf = redcon.AppendArray(server.aofbuf, len(args))
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
|
|
|
@ -92,14 +92,15 @@ type Server struct {
|
||||||
exlistmu sync.RWMutex
|
exlistmu sync.RWMutex
|
||||||
exlist []exitem
|
exlist []exitem
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
aof *os.File // active aof file
|
aof *os.File // active aof file
|
||||||
aofbuf []byte // prewrite buffer
|
aofdirty int32 // mark the aofbuf as having data
|
||||||
aofsz int // active size of the aof file
|
aofbuf []byte // prewrite buffer
|
||||||
qdb *buntdb.DB // hook queue log
|
aofsz int // active size of the aof file
|
||||||
qidx uint64 // hook queue log last idx
|
qdb *buntdb.DB // hook queue log
|
||||||
cols ds.BTree // data collections
|
qidx uint64 // hook queue log last idx
|
||||||
expires map[string]map[string]time.Time // synced with cols
|
cols ds.BTree // data collections
|
||||||
|
expires map[string]map[string]time.Time // synced with cols
|
||||||
|
|
||||||
follows map[*bytes.Buffer]bool
|
follows map[*bytes.Buffer]bool
|
||||||
fcond *sync.Cond
|
fcond *sync.Cond
|
||||||
|
@ -473,9 +474,12 @@ func (server *Server) evioServe() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
events.PreWrite = func() {
|
events.PreWrite = func() {
|
||||||
server.mu.Lock()
|
if atomic.LoadInt32(&server.aofdirty) != 0 {
|
||||||
defer server.mu.Unlock()
|
server.mu.Lock()
|
||||||
server.flushAOF()
|
defer server.mu.Unlock()
|
||||||
|
server.flushAOF()
|
||||||
|
atomic.StoreInt32(&server.aofdirty, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return evio.Serve(events, fmt.Sprintf("%s:%d", server.host, server.port))
|
return evio.Serve(events, fmt.Sprintf("%s:%d", server.host, server.port))
|
||||||
|
|
Loading…
Reference in New Issue