-
Notifications
You must be signed in to change notification settings - Fork 100
*: when cleaning up, use isolated context #559
Changes from all commits
62471dc
9c714ef
cc4497b
51b7898
d83ed80
b12aab7
023064c
fd4c69b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,13 @@ package gluetikv | |
|
|
||
| import ( | ||
| "context" | ||
| "sync/atomic" | ||
|
|
||
| "github.com/pingcap/tidb/config" | ||
| "github.com/pingcap/tidb/domain" | ||
| "github.com/pingcap/tidb/kv" | ||
| "github.com/pingcap/tidb/store/tikv" | ||
| "github.com/prometheus/common/log" | ||
| pd "github.com/tikv/pd/client" | ||
|
|
||
| "github.com/pingcap/br/pkg/glue" | ||
|
|
@@ -48,7 +50,7 @@ func (Glue) OwnsStorage() bool { | |
|
|
||
| // StartProgress implements glue.Glue. | ||
| func (Glue) StartProgress(ctx context.Context, cmdName string, total int64, redirectLog bool) glue.Progress { | ||
| return progress{ch: utils.StartProgress(ctx, cmdName, total, redirectLog)} | ||
| return progress{ch: utils.StartProgress(ctx, cmdName, total, redirectLog), closed: 0} | ||
| } | ||
|
|
||
| // Record implements glue.Glue. | ||
|
|
@@ -57,15 +59,28 @@ func (Glue) Record(name string, val uint64) { | |
| } | ||
|
|
||
| type progress struct { | ||
| ch chan<- struct{} | ||
| ch chan<- struct{} | ||
| closed int32 | ||
| } | ||
|
|
||
| // Inc implements glue.Progress. | ||
| func (p progress) Inc() { | ||
| if atomic.LoadInt32(&p.closed) != 0 { | ||
| log.Warn("proposing a closed progress") | ||
| return | ||
| } | ||
| // there might be buggy if the thread is yielded here. | ||
| // however, there should not be gosched, at most time. | ||
| // so send here probably is safe, even not totally safe. | ||
| // since adding an extra lock should be costly, we just be optimistic. | ||
| // (Maybe a spin lock here would be better?) | ||
| p.ch <- struct{}{} | ||
|
Comment on lines
+62
to
77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is possible to just make this entire progress structure an atomic integer instead of a channel, like https://github.com/pingcap/tidb/blob/c7651f02be36b5faf95a204d20f8859eb9c2080a/executor/brie.go#L49-L73? tbh i don't see any reason why we use a channel in the first place, since we're using a 1-second timer to update the progress bar in any case.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, there would be more change than this pr has done now if we refactor the progress struct here. how about leaving a TODO here and leave it another PR? (The struct that proposing the progress bar is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (But I could have a try in this PR, anyway, if desired) |
||
| } | ||
|
|
||
| // Close implements glue.Progress. | ||
| func (p progress) Close() { | ||
| // set closed to true firstly, | ||
| // so we won't see a state that the channel is closed and the p.closed is false. | ||
| atomic.StoreInt32(&p.closed, 1) | ||
| close(p.ch) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #! /bin/sh | ||
|
|
||
| apt update && apt install default-mysql-client jq --yes | ||
|
|
||
| cd /brie | ||
| TEST_NAME=br_other make integration_test |
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.
What about trying to graceful shutdown at the first time BR receives signal, and os.Exit() when it receives signal twice? So we can avoid hard code 30 seconds timeout.
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.
Good idea!
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.
Done, PTAL~