deadlock after finishing post migration fixed (needs test)
This commit is contained in:
parent
7f73716b9a
commit
60a8597b15
8
main.go
8
main.go
@ -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"
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
select {
|
||||||
|
case <-doneChannel:
|
||||||
|
return
|
||||||
|
case postId, ok := <-workInputChannel:
|
||||||
|
if ok {
|
||||||
result := createPost(postId, migration, wpTagData)
|
result := createPost(postId, migration, wpTagData)
|
||||||
workOutputChannel <- result
|
workOutputChannel <- result
|
||||||
wg.Done()
|
} 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)
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-doneChannel:
|
||||||
|
return
|
||||||
|
case postResult, ok := <-workOutputChannel:
|
||||||
|
if ok {
|
||||||
postResults = append(postResults, postResult)
|
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,10 +326,15 @@ 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 {
|
||||||
|
select {
|
||||||
|
case <-doneChannel:
|
||||||
|
return
|
||||||
|
case result := <-postResultWorkInput:
|
||||||
updatePostRelationship(result, migration)
|
updatePostRelationship(result, migration)
|
||||||
wg.Done()
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user