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

reduce unnecessary context.Background() #384

Merged
merged 1 commit into from
Apr 13, 2021
Merged

reduce unnecessary context.Background() #384

merged 1 commit into from
Apr 13, 2021

Conversation

CMGS
Copy link
Contributor

@CMGS CMGS commented Apr 13, 2021

  1. use context.TODO replace context.Background if not sure how to cancel it
  2. not modified wal implementation, @anrs can do
  3. should consider carefully in create/realloc/replace
  4. goroutine pool with ctx outside
  5. removed context in doRemapResourceAndLog
  6. seems redis lock should return wrapped context like etcd lock @tonicbupt

@CMGS CMGS force-pushed the no_more_background branch 3 times, most recently from c306c8a to d305750 Compare April 13, 2021 05:41
lock/redis/lock.go Show resolved Hide resolved
store/etcdv3/meta/ephemeral.go Outdated Show resolved Hide resolved
utils/gopool.go Outdated
// there won't be error once we use background ctx
p.sem.Acquire(context.Background(), 1) // nolint:errcheck
p.sem.Acquire(ctx, 1) // nolint:errcheck
Copy link
Member

Choose a reason for hiding this comment

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

这里用了非 background ctx 就要处理 error 了... 这个函数的类型就开始变得不美好了

Copy link
Member

Choose a reason for hiding this comment

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

当时使用 background 的考虑是, 如果只是考虑这是 sync.WaitGroup 的强化版本的话, wg 本身也没有提供被 ctx 打断的能力, 所以我就偷懒做了一个等价语义.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Acquire acquires the semaphore with a weight of n, blocking until resources are available or ctx is done. On success, returns nil. On failure, returns ctx.Err() and leaves the semaphore unchanged.

If ctx is already done, Acquire may still succeed without blocking.

根据这个描述,其实你不处理 error 也不是不行

Copy link
Member

Choose a reason for hiding this comment

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

笑哭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

所以实际上你看 ctx 导致失败的话,semaphore 不会变化,ctx 错误忽略就行了,还能有啥错误呢对吧……

Copy link
Contributor Author

Choose a reason for hiding this comment

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

哦实际还是不行,得阻断后面的执行……

@CMGS CMGS merged commit f7b4343 into master Apr 13, 2021
@CMGS CMGS deleted the no_more_background branch April 13, 2021 09:21
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.

3 participants