-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
domain: Clean up the goroutine after closing a domain #5163
Conversation
/run-all-tests |
domain/domain.go
Outdated
@@ -317,6 +317,7 @@ func (do *Domain) Reload() error { | |||
} | |||
|
|||
func (do *Domain) loadSchemaInLoop(lease time.Duration) { | |||
defer do.wg.Done() | |||
// Lease renewal can run at any frequency. | |||
// Use lease/2 here as recommend by paper. | |||
// TODO: Reset ticker or make interval longer. |
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.
Remove the TODO.
PTAL @siddontang |
domain/domain.go
Outdated
if err == nil { | ||
return nil | ||
} | ||
// If the domain exits, we return this function. |
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.
s/exits/has stopped/
domain/domain.go
Outdated
if err == nil { | ||
return nil | ||
} | ||
// If the domain exits, we return this function. |
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.
s/this function/error immediately/
PTAL @tiancaiamao @coocood |
@@ -474,6 +496,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio | |||
// Only when the store is local that the lease value is 0. | |||
// If the store is local, it doesn't need loadSchemaInLoop. | |||
if ddlLease > 0 { | |||
d.wg.Add(1) |
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.
why need to wait for this rountine exit?
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.
Normally the structure stops, then the gorountine will exit.
@zimulala |
SchemaSyncer belongs to ddl object, how about move it's logic to other place, out of When |
@coocood |
@tiancaiamao |
|
||
for { | ||
childCtx, cancel := goctx.WithTimeout(ctx, timeout) | ||
err := syncer.Restart(childCtx) |
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.
Should we log this error?
domain/domain.go
Outdated
@@ -352,6 +352,28 @@ func (do *Domain) loadSchemaInLoop(lease time.Duration) { | |||
} | |||
} | |||
|
|||
func (do *Domain) mustRestartSyncer() 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.
Please add comments for this method.
PTAL @coocood @winkyao @tiancaiamao |
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.
LGTM
LGTM |
If we close the domain, maybe the channel of
syncer.Done
anddo.exit
are both notified.If it selects the channel of
syncer.Done
and the NewSession function encounters an error likegrpc: the client connection is closing
(the error isn’t thecontext done
error), then the goroutine can't quit. So this domain will leave some dirty data after quitting.