add aof-use-rdb-preamble

This commit is contained in:
xing-you-ji
2023-04-08 06:11:02 +08:00
committed by finley
parent 25bbd82da5
commit 1e767b6797
19 changed files with 338 additions and 188 deletions

View File

@@ -2,6 +2,12 @@ package database
import (
"fmt"
"runtime/debug"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/hdt3213/godis/aof"
"github.com/hdt3213/godis/config"
"github.com/hdt3213/godis/interface/database"
@@ -10,11 +16,6 @@ import (
"github.com/hdt3213/godis/lib/utils"
"github.com/hdt3213/godis/pubsub"
"github.com/hdt3213/godis/redis/protocol"
"runtime/debug"
"strconv"
"strings"
"sync/atomic"
"time"
)
var godisVersion = "1.2.8" // do not modify
@@ -49,6 +50,7 @@ func NewStandaloneServer() *Server {
server.dbSet[i] = holder
}
server.hub = pubsub.MakeHub()
// record aof
validAof := false
if config.Properties.AppendOnly {
aofHandler, err := NewPersister(server,
@@ -218,6 +220,7 @@ func (server *Server) execFlushDB(dbIndex int) redis.Reply {
return server.flushDB(dbIndex)
}
// flushDB flushes the selected database
func (server *Server) flushDB(dbIndex int) redis.Reply {
if dbIndex >= len(server.dbSet) || dbIndex < 0 {
return protocol.MakeErrReply("ERR DB index is out of range")
@@ -238,6 +241,7 @@ func (server *Server) loadDB(dbIndex int, newDB *DB) redis.Reply {
return &protocol.OkReply{}
}
// flushAll flushes all databases.
func (server *Server) flushAll() redis.Reply {
for i := range server.dbSet {
server.flushDB(i)
@@ -248,6 +252,7 @@ func (server *Server) flushAll() redis.Reply {
return &protocol.OkReply{}
}
// selectDB returns the database with the given index, or an error if the index is out of range.
func (server *Server) selectDB(dbIndex int) (*DB, *protocol.StandardErrReply) {
if dbIndex >= len(server.dbSet) || dbIndex < 0 {
return nil, protocol.MakeErrReply("ERR DB index is out of range")
@@ -255,6 +260,7 @@ func (server *Server) selectDB(dbIndex int) (*DB, *protocol.StandardErrReply) {
return server.dbSet[dbIndex].Load().(*DB), nil
}
// mustSelectDB is like selectDB, but panics if an error occurs.
func (server *Server) mustSelectDB(dbIndex int) *DB {
selectedDB, err := server.selectDB(dbIndex)
if err != nil {
@@ -325,7 +331,7 @@ func SaveRDB(db *Server, args [][]byte) redis.Reply {
if rdbFilename == "" {
rdbFilename = "dump.rdb"
}
err := db.persister.Rewrite2RDB(rdbFilename)
err := db.persister.GenerateRDB(rdbFilename)
if err != nil {
return protocol.MakeErrReply(err.Error())
}
@@ -347,7 +353,7 @@ func BGSaveRDB(db *Server, args [][]byte) redis.Reply {
if rdbFilename == "" {
rdbFilename = "dump.rdb"
}
err := db.persister.Rewrite2RDB(rdbFilename)
err := db.persister.GenerateRDB(rdbFilename)
if err != nil {
logger.Error(err)
}