Skip to content

ledger: rearrange blockqueue start/stop#4964

Merged
algorandskiy merged 9 commits intoalgorand:masterfrom
brianolson:blockq-tweak
Jan 19, 2023
Merged

ledger: rearrange blockqueue start/stop#4964
algorandskiy merged 9 commits intoalgorand:masterfrom
brianolson:blockq-tweak

Conversation

@brianolson
Copy link
Copy Markdown
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
Copy Markdown

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

Comment thread ledger/blockqueue.go

if !bq.running {
close(bq.closed)
bq.closed = nil
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread ledger/blockqueue.go Outdated
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
Copy Markdown
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
Copy Markdown
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 thread ledger/blockqueue.go Outdated
Comment on lines +69 to +72
oldsyncer := bq.closed
bq.mu.Unlock()
<-oldsyncer
bq.mu.Lock()
Copy link
Copy Markdown
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?

Comment thread ledger/blockqueue.go Outdated
Comment thread ledger/ledger.go Outdated
Comment thread ledger/archival_test.go
Comment thread ledger/blockqueue.go Outdated
}()
defer bq.mu.Unlock()

if !bq.running {
Copy link
Copy Markdown
Contributor

@algorandskiy algorandskiy Jan 17, 2023

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.

4 participants