Implement teardown for gh-ost library#479
Implement teardown for gh-ost library#479shlomi-noach merged 17 commits intogithub:teardown-contribfrom
Conversation
|
Thank you! just as heads up it'll take me a few days to review this, sorry for the delay. |
|
@shlomi-noach do you think you will get a chance to review this this week? |
|
this is the week! |
shlomi-noach
left a comment
There was a problem hiding this comment.
Overall looks very good -- see finishedMigrating concurrency concern ; this would need to change.
When this is changed, I can send this PR for testing.
Thank you!
| knownDBsMutex.Lock() | ||
| defer func() { | ||
| knownDBsMutex.Unlock() | ||
| }() |
There was a problem hiding this comment.
simpler:
defer knownDBsMutex.Unlock()
There was a problem hiding this comment.
of course, thanks!
go/logic/migrator.go
Outdated
| this.eventsStreamer.Teardown() | ||
| } | ||
|
|
||
| sqlutils.ResetDBCache() |
go/logic/applier.go
Outdated
| db *gosql.DB | ||
| singletonDB *gosql.DB | ||
| migrationContext *base.MigrationContext | ||
| finishedMigrating bool |
There was a problem hiding this comment.
This variable is accesses read/write by different goroutines. You'd need o change it to int64 and use atomic.StoreInt64 and atomic.LoadInt64 ; see various such examples throughout the code.
go/logic/applier.go
Outdated
|
|
||
| heartbeatTick := time.Tick(time.Duration(this.migrationContext.HeartbeatIntervalMilliseconds) * time.Millisecond) | ||
| for range heartbeatTick { | ||
| if this.finishedMigrating { |
There was a problem hiding this comment.
unsafe operation ; concurrency
go/logic/applier.go
Outdated
| log.Debugf("Tearing down...") | ||
| this.db.Close() | ||
| this.singletonDB.Close() | ||
| this.finishedMigrating = true |
There was a problem hiding this comment.
unsafe operation ; concurrency ; use atomic.StoreInt64
go/logic/migrator.go
Outdated
|
|
||
| handledChangelogStates map[string]bool | ||
|
|
||
| finishedMigrating bool |
There was a problem hiding this comment.
see concurrency concerns above
go/logic/migrator.go
Outdated
| this.printStatus(ForcePrintStatusAndHintRule) | ||
| statusTick := time.Tick(1 * time.Second) | ||
| for range statusTick { | ||
| if this.finishedMigrating { |
There was a problem hiding this comment.
unsafe operation ; concurrency
go/logic/migrator.go
Outdated
| go func() { | ||
| ticker := time.Tick(1 * time.Second) | ||
| for range ticker { | ||
| if this.finishedMigrating { |
There was a problem hiding this comment.
unsafe operation ; concurrency
go/logic/migrator.go
Outdated
| return nil | ||
| } | ||
| for { | ||
| if this.finishedMigrating { |
There was a problem hiding this comment.
unsafe operation ; concurrency
go/logic/migrator.go
Outdated
| } | ||
|
|
||
| func (this *Migrator) teardown() { | ||
| this.finishedMigrating = true |
There was a problem hiding this comment.
unsafe operation ; concurrency
|
@shlomi-noach thanks for the notes on the concurrency concerns - those have been fixed! i've been doing some additional testing over the past week and came across an issue with the DB cache in Do you have any objections to attaching the db connections pools that connect to |
92784e7 to
5788ab5
Compare
6822be1 to
84bdfdb
Compare
|
@shlomi-noach, I implemented that proposed changed here 84bdfdb - let me know what you think of the approach! i believe with these changes, each migration will maintain its own connections before cleaning them up at the end - allowing for migrations to run concurrently. Thanks again for your review, and sorry for the delay with the above changes! Will be sure to get to any feedback you have shortly :) |
|
@nikhilmat I'll be in a conference this week so will only take a look next week. But meanwhile, Re: thread pool, please see #491 and #482, work in progress by @zmoazeni to address that. |
|
@shlomi-noach @nikhilmat hey folks. I'm not sure how the thread pool changes affect this PR, but by all means if you need any help just ask. As far as I understand the codebase and my threadpool PR, I don't explicitly create a new connection. It just reuses the existing ones. So I think they will both go hand-in-hand. But if they don't, just let me know. |
Thank you for working on this. One thing I'd like not to change is Also, whatever happened to the |
|
@shlomi-noach great, I believe all the changes on moving the DB connections are covered in this PR - I was able to successfully run concurrent migrations locally. Totally understand about not wanting to change the source code in Sorry for the confusion with the layered changes. The Thanks again! Let me know how you'd like to proceed with the |
|
@shlomi-noach any thoughts on the above with regards to the |
|
@shlomi-noach friendly ping :) anything else i can do to help this along? |
|
@nikhilmat sorry for the delay! I was out for a while and then busy catching up. Will get to it. |
|
@shlomi-noach no problem, thanks! |
|
Again, apologies for the delay. Still on it, just have some serious backlog. |
|
@shlomi-noach thanks for checking in on this. i know there's still a decision to be made on how to apply the changes to the vendor directory:
Feel free to chime in on your preference on this and I can make the change before taking another pass. Otherwise, I can go ahead remove the usage of Thanks! |
|
Apologies for keeping you waiting on such a small issue. What I also see you've done is https://github.com/github/gh-ost/pull/479/files#diff-b9f3c8a49a606c2654d3c9c33727e879R253, which just duplicates the code in Furthermore, I suggest the following:
Thank you! |
|
@shlomi-noach the goal with moving the caching to the Thanks! |
I understand better now, thank you for explaining. To elaborate abit, a futuristic idea is to have the |
|
Ah, cool! Thanks for sharing, that's good to know. I had a separate question about adding a custom, migration-specific logger (we're sending our logs to cloudwatch), and this is really helpful. Will open up an issue to discuss. This is ready for another pass when you get a chance. Incorporated your feedback and updated with the latest master! |
|
👋 @shlomi-noach - do you think you'll get a chance to take another look at this soon? |
|
@nikhilmat apologies yet again for the delays and I appreciate your patience, thank you for pinging. What I'll do is merge this onto a local |
|
wonderful - thank you!!! |
Fixes #465
This PR adds explicit cleanup to gh-ost for when the library is consumed by another application and might be executed multiple times (for example, by a webserver). This stops any infinite goroutines that have started once the migration has finished, closes any DB connections it has opened, and ensures that the migration context that is passed around is not being globally accessed - instead it instantiates a new one for each migration run and passes it around.
Please let me know how this looks to you, and happy to make any changes to improve it!
It also pulls in the change from outbrain-inc/golib#4.