Skip to content
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

Merged
merged 9 commits into from Jan 19, 2023

Conversation

brianolson
Copy link
Contributor

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.

remove stale test interface
@codecov
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #4964 (b7bd2b8) into master (5c17ad6) will decrease coverage by 0.01%.
The diff coverage is 53.84%.

@@            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     
Impacted Files Coverage Δ
ledger/blockqueue.go 82.25% <52.63%> (-2.23%) ⬇️
ledger/ledger.go 70.18% <57.14%> (-0.63%) ⬇️
catchup/peerSelector.go 98.95% <0.00%> (-1.05%) ⬇️
catchup/service.go 69.08% <0.00%> (-0.73%) ⬇️
ledger/acctupdates.go 68.87% <0.00%> (-0.37%) ⬇️
network/wsNetwork.go 64.74% <0.00%> (-0.18%) ⬇️
ledger/testing/randomAccounts.go 56.26% <0.00%> (ø)
ledger/tracker.go 78.05% <0.00%> (+3.79%) ⬆️

📣 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
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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:

  1. bq.closed will be nil
  2. where bq.closed will be created and immediately closed

Comment on lines 67 to 73
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()
}
Copy link
Contributor

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:

Suggested change
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()

algonautshant
algonautshant previously approved these changes Jan 13, 2023
Copy link
Contributor

@algonautshant algonautshant left a 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.

Comment on lines 69 to 72
oldsyncer := bq.closed
bq.mu.Unlock()
<-oldsyncer
bq.mu.Lock()
Copy link
Contributor

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 Show resolved Hide resolved
ledger/ledger.go Outdated Show resolved Hide resolved
ledger/archival_test.go Show resolved Hide resolved
}()
defer bq.mu.Unlock()

if !bq.running {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !bq.running {
if bq.running {
// log a warning, we should not be restarting running block queue
return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants