mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
optimize del in cluster
This commit is contained in:
@@ -25,7 +25,6 @@ func execDel(cluster *core.Cluster, c redis.Connection, cmdLine CmdLine) redis.R
|
|||||||
return protocol.MakeArgNumErrReply("del")
|
return protocol.MakeArgNumErrReply("del")
|
||||||
}
|
}
|
||||||
var keys []string
|
var keys []string
|
||||||
keyValues := make(map[string][]byte)
|
|
||||||
for i := 1; i < len(cmdLine); i++ {
|
for i := 1; i < len(cmdLine); i++ {
|
||||||
key := string(cmdLine[i])
|
key := string(cmdLine[i])
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
@@ -44,8 +43,7 @@ func execDel(cluster *core.Cluster, c redis.Connection, cmdLine CmdLine) redis.R
|
|||||||
for node, keys := range routeMap {
|
for node, keys := range routeMap {
|
||||||
nodeCmdLine := utils.ToCmdLine("del")
|
nodeCmdLine := utils.ToCmdLine("del")
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
val := keyValues[key]
|
nodeCmdLine = append(nodeCmdLine, []byte(key))
|
||||||
nodeCmdLine = append(nodeCmdLine, []byte(key), val)
|
|
||||||
}
|
}
|
||||||
cmdLineMap[node] = nodeCmdLine
|
cmdLineMap[node] = nodeCmdLine
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ func execPrepare(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Re
|
|||||||
tx := cluster.transactions.txs[txId]
|
tx := cluster.transactions.txs[txId]
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
cluster.transactions.mu.Unlock()
|
cluster.transactions.mu.Unlock()
|
||||||
return protocol.MakeErrReply("transction existed")
|
return protocol.MakeErrReply("transaction existed")
|
||||||
}
|
}
|
||||||
tx = &TCC{}
|
tx = &TCC{}
|
||||||
cluster.transactions.txs[txId] = tx
|
cluster.transactions.txs[txId] = tx
|
||||||
@@ -92,11 +92,10 @@ func execCommit(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.Rep
|
|||||||
|
|
||||||
cluster.transactions.mu.Lock()
|
cluster.transactions.mu.Lock()
|
||||||
tx := cluster.transactions.txs[txId]
|
tx := cluster.transactions.txs[txId]
|
||||||
if tx == nil {
|
|
||||||
cluster.transactions.mu.Unlock()
|
|
||||||
return protocol.MakeErrReply("transction not found")
|
|
||||||
}
|
|
||||||
cluster.transactions.mu.Unlock()
|
cluster.transactions.mu.Unlock()
|
||||||
|
if tx == nil {
|
||||||
|
return protocol.MakeErrReply("transaction not found")
|
||||||
|
}
|
||||||
|
|
||||||
resp := cluster.db.ExecWithLock(c, tx.realCmdLine)
|
resp := cluster.db.ExecWithLock(c, tx.realCmdLine)
|
||||||
|
|
||||||
@@ -127,11 +126,10 @@ func execRollback(cluster *Cluster, c redis.Connection, cmdLine CmdLine) redis.R
|
|||||||
// get transaction
|
// get transaction
|
||||||
cluster.transactions.mu.Lock()
|
cluster.transactions.mu.Lock()
|
||||||
tx := cluster.transactions.txs[txId]
|
tx := cluster.transactions.txs[txId]
|
||||||
if tx == nil {
|
|
||||||
cluster.transactions.mu.Unlock()
|
|
||||||
return protocol.MakeErrReply("transction not found")
|
|
||||||
}
|
|
||||||
cluster.transactions.mu.Unlock()
|
cluster.transactions.mu.Unlock()
|
||||||
|
if tx == nil {
|
||||||
|
return protocol.MakeErrReply("transaction not found")
|
||||||
|
}
|
||||||
|
|
||||||
// rollback
|
// rollback
|
||||||
if !tx.hasLock {
|
if !tx.hasLock {
|
||||||
|
Reference in New Issue
Block a user