-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new types of node lock #554
Conversation
79da76e
to
3f0e424
Compare
cluster/calcium/remap.go
Outdated
type remapEntry struct { | ||
ctx context.Context | ||
nodeName string | ||
logger log.Fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个还带个 logger 就很迷
cluster/calcium/remap.go
Outdated
// watch remap queue | ||
func (c *Calcium) watchRemapChan() { | ||
for { | ||
if entry, ok := <-c.remapChan; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实我的问题在于,你这样相当于是单机 remap,多 core 咋办
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我也发现这个问题了,但是还没来得及改…
应该是要新增一种类型的锁,专门给remap用
所以就按照最开始的讨论引入 node operation lock 了事 |
现在把node lock分成了两种,一种node resource lock,一种node operation lock(主要给remap用)。 |
06977aa
to
837bec8
Compare
cluster/calcium/lock.go
Outdated
nf := types.NodeFilter{ | ||
Includes: []string{nodename}, | ||
All: true, | ||
} | ||
return c.withNodesLocked(ctx, nf, func(ctx context.Context, nodes map[string]*types.Node) error { | ||
return c.withNodesResourceLocked(ctx, nf, func(ctx context.Context, nodes map[string]*types.Node) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么多重复的代码,是我的话会抽出一个函数复用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改啦
之前remap要拿一个node的锁,而且remap流程还挺长的,一直拿着锁会卡住其它部署请求。而remap的锁只是为了保证不会有多个请求同时去remap,其实可以用chan来代替锁的功能。
修改之后会有一个goroutine来循环监听remapChan,调用方只需要异步将node name塞进remapChan即可,大大节约了持有锁的时间。
为了尽量防止脏数据的问题,remap里的实现也稍微改了下,每次都要重新获取node的资源信息。