Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

fix a startup race by creating the blockstoremanager process on init #465

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/decision/blockstoremanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ func newBlockstoreManager(bs bstore.Blockstore, workerCount int) *blockstoreMana
bs: bs,
workerCount: workerCount,
jobs: make(chan func()),
px: process.WithTeardown(func() error { return nil }),
}
}

func (bsm *blockstoreManager) start(px process.Process) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can drop this parameter now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to make sure we shutdown the blockstoreManager when we shutdown the parent service (that's what the AddChild call does).

bsm.px = px

px.AddChild(bsm.px)
// Start up workers
for i := 0; i < bsm.workerCount; i++ {
px.Go(func(px process.Process) {
bsm.worker()
bsm.px.Go(func(px process.Process) {
bsm.worker(px)
})
}
}

func (bsm *blockstoreManager) worker() {
func (bsm *blockstoreManager) worker(px process.Process) {
for {
select {
case <-bsm.px.Closing():
case <-px.Closing():
return
case job := <-bsm.jobs:
job()
Expand Down