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] Ledger cleanups + make a test async #1073

Merged
merged 7 commits into from
Aug 6, 2021

Conversation

huitseeker
Copy link
Contributor

found while trying to read about / dig into the WAL:

  • removes unneeded byte conversions,
  • removes unused, untested functions either in test utils or for which there's a good alternative,
  • makes Test_Compactor/Compactor_creates_checkpoints_eventually asynchronous but deterministic,
    (introduces a minimalistic Observable interface that I know I'll reuse elsewhere, though not in this PR, see Networking test races #1020 )
  • Simplifies Compactor's start / stop slightly, thanks to @smnzhu 's LifeCycleManager

stopc chan struct{}
wg sync.WaitGroup
lm *lifecycle.LifecycleManager
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

ledger/complete/wal/compactor.go Outdated Show resolved Hide resolved
ledger/complete/wal/compactor_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@synzhu synzhu left a comment

Choose a reason for hiding this comment

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

LGTM

for observer := range c.observers {
observer.OnComplete()
}
c.stopc <- struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

You may be interested in #1077, which will allow you to replace c.stopc as well :)

@@ -289,7 +281,7 @@ func (p *TrieProof) String() string {
interimIndex := 0
for j := 0; j < int(p.Steps); j++ {
// if bit is set
if p.Flags[j/8]&(1<<int(7-j%8)) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

@tarakby is this change okey?

Copy link
Contributor Author

@huitseeker huitseeker Aug 3, 2021

Choose a reason for hiding this comment

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

j is an integer, % has an integer codomain, and j % 8 <= 7 by specification

Copy link
Contributor

Choose a reason for hiding this comment

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

That's correct, but we can replace this by Bit(p.Falgs, j) using this tool function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I remembered Tarak recommended something about this part of the code and I was not remembering the details, that's why I asked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for flagging @ramtinms. You're right I made changes in the past to the Bit function.

ledger/complete/wal/compactor_test.go Outdated Show resolved Hide resolved
@@ -0,0 +1,8 @@
package observable

type Observable interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we maybe should use some established library for this - https://github.com/ReactiveX/RxGo
Now the usecase is simple but it might grow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm familiar with RxGo and very much in favor, but I don't think we have scope for using it fully as a consequence of this PR alone.

The Observable API I put in modules right now is forward-compatible.

ledger/complete/wal/compactor.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tarakby tarakby left a comment

Choose a reason for hiding this comment

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

Thanks for the ledger tools and tests clean up!
Minor suggestions.

Out of curiosity, did you use a linter tool to find out the non-needed type casts or was it by manual review ?

@@ -272,7 +272,7 @@ func DecodeValue(encodedValue []byte) (ledger.Value, error) {
}

func decodeValue(inp []byte) (ledger.Value, error) {
return ledger.Value(inp), nil
return inp, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We could delete the function in this case. It also never errors.

@@ -289,7 +281,7 @@ func (p *TrieProof) String() string {
interimIndex := 0
for j := 0; j < int(p.Steps); j++ {
// if bit is set
if p.Flags[j/8]&(1<<int(7-j%8)) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's correct, but we can replace this by Bit(p.Falgs, j) using this tool function.

@huitseeker
Copy link
Contributor Author

@tarakby I blasted the ones my IDE highlighted, but if we want to put that in CI, golang-ci supports unconvert: https://golangci-lint.run/usage/linters/

Copy link
Contributor

@m4ksio m4ksio left a comment

Choose a reason for hiding this comment

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

Looks good now

@huitseeker huitseeker merged commit 3029e6f into onflow:master Aug 6, 2021
huitseeker added a commit to huitseeker/flow-go that referenced this pull request Aug 18, 2021
This reverts commit 845a00b.

Reasons for reversal:
- provided impetus for clearing out races (onflow#1073, onflow#1095)
- network tests now pass with race detector on!
- but those  timings are preposterous
huitseeker added a commit to huitseeker/flow-go that referenced this pull request Aug 18, 2021
This reverts commit 845a00b.

Reasons for reversal:
- provided impetus for clearing out races (onflow#1073, onflow#1095)
- network tests now pass with race detector on!
- but those  timings are preposterous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants