deadlock after finishing post migration fixed (needs test)

This commit is contained in:
Ross Trottier 2024-06-08 15:48:39 -06:00
parent 7f73716b9a
commit 60a8597b15
2 changed files with 54 additions and 19 deletions

View File

@ -7,15 +7,15 @@ import (
) )
// WP Config // WP Config
const baseUrl = "http://go-api-playground.local/" const baseUrl = "https://slowtwitch.cloud/"
const wordpressKey = "admin" const wordpressKey = "admin@slowtwitch.cloud"
const wordpressSecret = "JXDP 3EgE h1RF jhln b8F5 A1Xk" const wordpressSecret = "hGZ0 GWlR TuUN CVyk SXh6 05uP"
// DB Config // DB Config
const slowtwitchAdminUser = "admin" const slowtwitchAdminUser = "admin"
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv" const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
const slowtwitchDbName = "slowtwitch" const slowtwitchDbName = "slowtwitch"
const migrationDbName = "slowtwitch_transfer_threaded_test" const migrationDbName = "slowtwitch_transfer"
const federatedDbUrl = "slowtwitch.northend.network" const federatedDbUrl = "slowtwitch.northend.network"
const federatedDbPort = "3306" const federatedDbPort = "3306"

View File

@ -41,16 +41,25 @@ func (migration MigratePosts) Execute() []PostResult {
batchSize := 5 batchSize := 5
workInputChannel := make(chan int) workInputChannel := make(chan int)
workOutputChannel := make(chan PostResult) workOutputChannel := make(chan PostResult)
doneChannel := make(chan bool)
defer close(doneChannel)
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1)
wg.Add(len(slowtwitchPostIdsForMigration)) wg.Add(len(slowtwitchPostIdsForMigration))
for i := 0; i < batchSize; i++ { for i := 0; i < batchSize; i++ {
go func() { go func() {
for postId := range workInputChannel { for {
result := createPost(postId, migration, wpTagData) select {
workOutputChannel <- result case <-doneChannel:
wg.Done() return
case postId, ok := <-workInputChannel:
if ok {
result := createPost(postId, migration, wpTagData)
workOutputChannel <- result
} else {
return
}
}
} }
}() }()
} }
@ -59,20 +68,34 @@ func (migration MigratePosts) Execute() []PostResult {
defer close(workInputChannel) defer close(workInputChannel)
for _, postId := range slowtwitchPostIdsForMigration { for _, postId := range slowtwitchPostIdsForMigration {
workInputChannel <- postId select {
case <-doneChannel:
return
case workInputChannel <- postId:
}
} }
wg.Done()
}() }()
go func() { go func() {
for postResult := range workOutputChannel { defer close(workOutputChannel)
postResults = append(postResults, postResult)
for {
select {
case <-doneChannel:
return
case postResult, ok := <-workOutputChannel:
if ok {
postResults = append(postResults, postResult)
wg.Done()
} else {
return
}
}
} }
}() }()
wg.Wait() wg.Wait()
close(workOutputChannel) doneChannel <- true
updatePostRelationships(postResults, migration) updatePostRelationships(postResults, migration)
@ -292,6 +315,8 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
fmt.Println("Updating post relationships") fmt.Println("Updating post relationships")
batchSize := 5 batchSize := 5
postResultWorkInput := make(chan PostResult) postResultWorkInput := make(chan PostResult)
doneChannel := make(chan bool)
defer close(doneChannel)
//Set up a wait group to wait for the input channel to close after execution //Set up a wait group to wait for the input channel to close after execution
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
@ -301,9 +326,14 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
//maxed out at the batch size //maxed out at the batch size
for i := 0; i < batchSize; i++ { for i := 0; i < batchSize; i++ {
go func() { go func() {
for result := range postResultWorkInput { for {
updatePostRelationship(result, migration) select {
wg.Done() case <-doneChannel:
return
case result := <-postResultWorkInput:
updatePostRelationship(result, migration)
wg.Done()
}
} }
}() }()
} }
@ -315,13 +345,18 @@ func updatePostRelationships(postResults []PostResult, migration MigratePosts) {
defer close(postResultWorkInput) defer close(postResultWorkInput)
for _, result := range postResults { for _, result := range postResults {
postResultWorkInput <- result select {
case <-doneChannel:
return
case postResultWorkInput <- result:
}
} }
wg.Done() wg.Done()
}() }()
wg.Wait() wg.Wait()
doneChannel <- true
fmt.Println("Done with post relationships") fmt.Println("Done with post relationships")
} }