Skip to content
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

sort out context issues #205

Merged
merged 9 commits into from
Jun 4, 2020
Merged

Conversation

jschwinger233
Copy link
Member

@jschwinger233 jschwinger233 commented Jun 3, 2020

  1. 检查所有调用 rpc 层和 store 层对 context 的使用情况, 只有 CreateLock(key string, ttl Duration) 没有 context, 但是研究了一下它是利用了 etcd client 的 context 作为 session context, 也还行吧, 如果 client 中断, 虽然 CreateLock 不受影响, 但是接下来 lock.Lock(ctx) 会中断, defer 里的 Unlock 也会 close session, 应该没啥问题.
  2. 把所有直接使用 context.Background() 都改成 context.WithTimeout(context.Background(), config.GlobalTimeout)
  3. 把两个 realloc 和 replace rpc 调用改成了使用 stream.Context()
    1. realloc 在 VirutalUpdateResource 之前允许 client 打断, 之后不行, 因为没有回滚机制
    2. replace 在 remove 老容器之前的操作都是允许 client 打断, 之后就不行了, 因为删容器不可回滚

@jschwinger233
Copy link
Member Author

测试挂了..

defer func() {
ctx, cancel := context.WithTimeout(context.Background(), c.config.GlobalTimeout)
defer cancel()
c.doRemoveContainerSync(ctx, []string{message.ContainerID})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得这里的 timeout 处理得放到这个 doRemoveContainerSync 里面

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我放到更下层了, 分别在 Container type 的 Stop / Remove / ... 方法里, 和 Mercury 的 Get / Put / ... 方法里,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types.Container 带一个 timeout 参数蛮奇怪的,如果放方法给 Stop/Remove ... 多一个传参呢

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改到上一层 control container 里统一做了

cluster/calcium/realloc.go Outdated Show resolved Hide resolved
rpc/rpc.go Outdated Show resolved Hide resolved
// 不能让 context 作祟
backgroundCtx := context.Background()
createChan, err := c.CreateContainer(backgroundCtx, opts)
log.Info("in creating")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

日志格式

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是我测试的日志 忘了删了...

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
pods, err := cluster.ListPods(ctx)
pods, err := cluster.ListPods(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..这就没必要改了嘛

@@ -16,21 +16,25 @@ func (c *Calcium) doLock(ctx context.Context, name string, timeout time.Duration
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(ctx, c.config.GlobalTimeout)
defer cancel()
if err = lock.Lock(ctx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

顺便改这里啊 return lock, lock.Lock(ctx)

@CMGS
Copy link
Contributor

CMGS commented Jun 4, 2020

LGTM

@CMGS CMGS merged commit bd905b7 into projecteru2:master Jun 4, 2020
atlas-comstock pushed a commit to atlas-comstock/core that referenced this pull request Jun 11, 2020
* all background context have global timeout

* encapsulate transaction

* let reallac and replace use client context

* better transaction encap

* add ctx timeout in Container and Mercury

* make test pass

* add timeout in control container

* engine interface decorator to add timeout

* exempt interactive requests from timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants