mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
bug fix: FlushDB command is not recorded by AOF (#142)
* bug fix: FlushDB command is not recorded by AOF * bug fix: Fix an error occurred while rewriting aof rename, windows.ERROR_SHARING_VIOLATION * bug fix: Fix an error occurred while rewriting aof rename, windows.ERROR_SHARING_VIOLATION * change the flushDB procedures * The savecmdline flushdb in the method is incorrectly selected, causing the testof error
This commit is contained in:
@@ -139,10 +139,11 @@ func (persister *Persister) FinishRewrite(ctx *RewriteCtx) {
|
||||
logger.Error("copy aof filed failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tmpFileName := tmpFile.Name()
|
||||
_ = tmpFile.Close()
|
||||
// replace current aof file by tmp file
|
||||
_ = persister.aofFile.Close()
|
||||
_ = os.Rename(tmpFile.Name(), persister.aofFilename)
|
||||
_ = os.Rename(tmpFileName, persister.aofFilename)
|
||||
|
||||
// reopen aof file for further write
|
||||
aofFile, err := os.OpenFile(persister.aofFilename, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600)
|
||||
|
@@ -142,7 +142,7 @@ func (server *Server) Exec(c redis.Connection, cmdLine [][]byte) (result redis.R
|
||||
if c.InMultiState() {
|
||||
return protocol.MakeErrReply("ERR command 'FlushDB' cannot be used in MULTI")
|
||||
}
|
||||
return server.flushDB(c.GetDBIndex())
|
||||
return server.execFlushDB(c.GetDBIndex())
|
||||
} else if cmdName == "save" {
|
||||
return SaveRDB(server, cmdLine[1:])
|
||||
} else if cmdName == "bgsave" {
|
||||
@@ -203,6 +203,13 @@ func execSelect(c redis.Connection, mdb *Server, args [][]byte) redis.Reply {
|
||||
return protocol.MakeOkReply()
|
||||
}
|
||||
|
||||
func (server *Server) execFlushDB(dbIndex int) redis.Reply {
|
||||
if server.persister != nil {
|
||||
server.persister.SaveCmdLine(dbIndex, utils.ToCmdLine("FlushDB"))
|
||||
}
|
||||
return server.flushDB(dbIndex)
|
||||
}
|
||||
|
||||
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")
|
||||
|
Reference in New Issue
Block a user