-
Notifications
You must be signed in to change notification settings - Fork 493
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
ledger: rearrange blockqueue start/stop #4964
Conversation
remove stale test interface
Codecov Report
@@ Coverage Diff @@
## master #4964 +/- ##
==========================================
- Coverage 53.64% 53.63% -0.01%
==========================================
Files 432 432
Lines 54068 54080 +12
==========================================
+ Hits 29003 29006 +3
- Misses 22814 22820 +6
- Partials 2251 2254 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
bq.mu.Lock() | ||
for { | ||
for bq.running && len(bq.q) == 0 { | ||
bq.cond.Wait() | ||
} | ||
|
||
if !bq.running { | ||
close(bq.closed) | ||
bq.closed = nil |
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.
Is setting this to nil necessary? Keep it closed, and replace it with a new one when restarted.
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.
receiving from nil blocks forever, and creating a chan and immediately closing it feels silly, so I like the nil checking
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.
Based on my suggestion, I expect that none of what you arguing should happen.
I must be missing something, can you please point to me when:
bq.closed
will be nil- where
bq.closed
will be created and immediately closed
ledger/blockqueue.go
Outdated
if bq.closed != nil { | ||
// a previus close() is still waiting on a previous syncer() to finish | ||
oldsyncer := bq.closed | ||
bq.mu.Unlock() | ||
<-oldsyncer | ||
bq.mu.Lock() | ||
} |
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.
If bq.closed
is not set to nil, this can be simplified:
if bq.closed != nil { | |
// a previus close() is still waiting on a previous syncer() to finish | |
oldsyncer := bq.closed | |
bq.mu.Unlock() | |
<-oldsyncer | |
bq.mu.Lock() | |
} | |
// a previus close() is still waiting on a previous syncer() to finish | |
bq.mu.Unlock() | |
<-bq.closed | |
bq.mu.Lock() |
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.
It looks correct.
Some suggestions to simplify and clarify the interfaces.
ledger/blockqueue.go
Outdated
oldsyncer := bq.closed | ||
bq.mu.Unlock() | ||
<-oldsyncer | ||
bq.mu.Lock() |
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.
A test for this?
ledger/blockqueue.go
Outdated
}() | ||
defer bq.mu.Unlock() | ||
|
||
if !bq.running { |
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.
if !bq.running { | |
if bq.running { | |
// log a warning, we should not be restarting running block queue | |
return | |
} |
Summary
Rearrange blockqueue start/stop to be cleaner and never nil inside ledger.go
Bonus: Remove stale test interface
Test Plan
Passes local unit tests.