mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
raft cluster
wip: raft does not care about migrating wip: optimize code wip: raft election wip wip: fix raft leader missing log entries wip fix a dead lock batch set slot route wip: raft persist wip refactor cluster suite remove relay rename relay2 refactor: allow customizing client factory test raft refactor re-balance avoid errors caused by inconsistent status on follower nodes during raft commits test raft election
This commit is contained in:
@@ -8,16 +8,16 @@ import (
|
||||
)
|
||||
|
||||
// Rename renames a key, the origin and the destination must within the same node
|
||||
func Rename(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
if len(args) != 3 {
|
||||
func Rename(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply {
|
||||
if len(cmdLine) != 3 {
|
||||
return protocol.MakeErrReply("ERR wrong number of arguments for 'rename' command")
|
||||
}
|
||||
srcKey := string(args[1])
|
||||
destKey := string(args[2])
|
||||
srcNode := cluster.peerPicker.PickNode(srcKey)
|
||||
destNode := cluster.peerPicker.PickNode(destKey)
|
||||
srcKey := string(cmdLine[1])
|
||||
destKey := string(cmdLine[2])
|
||||
srcNode := cluster.pickNodeAddrByKey(srcKey)
|
||||
destNode := cluster.pickNodeAddrByKey(destKey)
|
||||
if srcNode == destNode { // do fast
|
||||
return cluster.relay(srcNode, c, args)
|
||||
return cluster.relay(srcNode, c, modifyCmd(cmdLine, "Rename_"))
|
||||
}
|
||||
groupMap := map[string][]string{
|
||||
srcNode: {srcKey},
|
||||
@@ -26,7 +26,7 @@ func Rename(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
txID := cluster.idGenerator.NextID()
|
||||
txIDStr := strconv.FormatInt(txID, 10)
|
||||
// prepare rename from
|
||||
srcPrepareResp := cluster.relayPrepare(srcNode, c, makeArgs("Prepare", txIDStr, "RenameFrom", srcKey))
|
||||
srcPrepareResp := cluster.relay(srcNode, c, makeArgs("Prepare", txIDStr, "RenameFrom", srcKey))
|
||||
if protocol.IsErrorReply(srcPrepareResp) {
|
||||
// rollback src node
|
||||
requestRollback(cluster, c, txID, map[string][]string{srcNode: {srcKey}})
|
||||
@@ -38,7 +38,7 @@ func Rename(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
return protocol.MakeErrReply("ERR invalid prepare response")
|
||||
}
|
||||
// prepare rename to
|
||||
destPrepareResp := cluster.relayPrepare(destNode, c, utils.ToCmdLine3("Prepare", []byte(txIDStr),
|
||||
destPrepareResp := cluster.relay(destNode, c, utils.ToCmdLine3("Prepare", []byte(txIDStr),
|
||||
[]byte("RenameTo"), []byte(destKey), srcPrepareMBR.Args[0], srcPrepareMBR.Args[1]))
|
||||
if protocol.IsErrorReply(destPrepareResp) {
|
||||
// rollback src node
|
||||
@@ -92,16 +92,16 @@ func init() {
|
||||
|
||||
// RenameNx renames a key, only if the new key does not exist.
|
||||
// The origin and the destination must within the same node
|
||||
func RenameNx(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
if len(args) != 3 {
|
||||
func RenameNx(cluster *Cluster, c redis.Connection, cmdLine [][]byte) redis.Reply {
|
||||
if len(cmdLine) != 3 {
|
||||
return protocol.MakeErrReply("ERR wrong number of arguments for 'renamenx' command")
|
||||
}
|
||||
srcKey := string(args[1])
|
||||
destKey := string(args[2])
|
||||
srcNode := cluster.peerPicker.PickNode(srcKey)
|
||||
destNode := cluster.peerPicker.PickNode(destKey)
|
||||
srcKey := string(cmdLine[1])
|
||||
destKey := string(cmdLine[2])
|
||||
srcNode := cluster.pickNodeAddrByKey(srcKey)
|
||||
destNode := cluster.pickNodeAddrByKey(destKey)
|
||||
if srcNode == destNode {
|
||||
return cluster.relay(srcNode, c, args)
|
||||
return cluster.relay(srcNode, c, modifyCmd(cmdLine, "RenameNX_"))
|
||||
}
|
||||
groupMap := map[string][]string{
|
||||
srcNode: {srcKey},
|
||||
@@ -110,7 +110,7 @@ func RenameNx(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
txID := cluster.idGenerator.NextID()
|
||||
txIDStr := strconv.FormatInt(txID, 10)
|
||||
// prepare rename from
|
||||
srcPrepareResp := cluster.relayPrepare(srcNode, c, makeArgs("Prepare", txIDStr, "RenameFrom", srcKey))
|
||||
srcPrepareResp := cluster.relay(srcNode, c, makeArgs("Prepare", txIDStr, "RenameFrom", srcKey))
|
||||
if protocol.IsErrorReply(srcPrepareResp) {
|
||||
// rollback src node
|
||||
requestRollback(cluster, c, txID, map[string][]string{srcNode: {srcKey}})
|
||||
@@ -122,7 +122,7 @@ func RenameNx(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
|
||||
return protocol.MakeErrReply("ERR invalid prepare response")
|
||||
}
|
||||
// prepare rename to
|
||||
destPrepareResp := cluster.relayPrepare(destNode, c, utils.ToCmdLine3("Prepare", []byte(txIDStr),
|
||||
destPrepareResp := cluster.relay(destNode, c, utils.ToCmdLine3("Prepare", []byte(txIDStr),
|
||||
[]byte("RenameNxTo"), []byte(destKey), srcPrepareMBR.Args[0], srcPrepareMBR.Args[1]))
|
||||
if protocol.IsErrorReply(destPrepareResp) {
|
||||
// rollback src node
|
||||
|
Reference in New Issue
Block a user