Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cluster/node/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package node

import (
"context"
"sync"
"time"

"github.com/dobyte/due/v2/cluster"
Expand All @@ -17,6 +18,7 @@ type Proxy struct {
node *Node // 节点服务器
gateLinker *link.GateLinker // 网关链接器
nodeLinker *link.NodeLinker // 节点链接器
boundUsers sync.Map // 跟踪已绑定用户
}

func newProxy(node *Node) *Proxy {
Expand Down Expand Up @@ -174,7 +176,9 @@ func (p *Proxy) BindNode(ctx context.Context, uid int64, nameAndNID ...string) e
}

if nid == p.node.opts.id {
p.node.addWait()
if _, loaded := p.boundUsers.LoadOrStore(uid, struct{}{}); !loaded {
p.node.addWait()
}
}

return nil
Expand All @@ -195,7 +199,9 @@ func (p *Proxy) UnbindNode(ctx context.Context, uid int64, nameAndNID ...string)
}

if nid == p.node.opts.id {
p.node.doneWait()
if _, loaded := p.boundUsers.LoadAndDelete(uid); loaded {
p.node.doneWait()
}
}

return nil
Expand Down
Loading