-
Notifications
You must be signed in to change notification settings - Fork 179
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
Extract uncurried functions from storage writes #6803
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6803 +/- ##
==========================================
- Coverage 40.96% 40.96% -0.01%
==========================================
Files 2093 2096 +3
Lines 184478 184516 +38
==========================================
+ Hits 75577 75590 +13
- Misses 102579 102608 +29
+ Partials 6322 6318 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
0516981
to
8fa3022
Compare
// Using these deprecated functions could minimize the changes during refactor and easier to review the changes. | ||
// The simplified implementation of the functions are in the writes.go file, which are encouraged to be used instead. | ||
|
||
func Upsert(key []byte, val interface{}) func(storage.Writer) error { |
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.
Originally these functions are implemented as curried functions in order to follow the same pattern as badger transaction.
However, since we are moving away from badger transaction, it's simpler just removing this additional wrap by using the uncurried functions.
I extracted the uncurried functions and kept the original functions here so that the same logic are reused, as well as the tests.
Useful for refactoring storage modules with UpsertKey instead of Upsert for instance.
utils/merr/closer.go
Outdated
func CloseAndMergeError(closable io.Closer, err error) error { | ||
var merr *multierror.Error | ||
if err != nil { | ||
merr = multierror.Append(merr, err) | ||
} | ||
|
||
closeError := closable.Close() | ||
if closeError != nil { | ||
merr = multierror.Append(merr, closeError) | ||
} | ||
|
||
return merr.ErrorOrNil() | ||
} |
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.
func CloseAndMergeError(closable io.Closer, err error) error { | |
var merr *multierror.Error | |
if err != nil { | |
merr = multierror.Append(merr, err) | |
} | |
closeError := closable.Close() | |
if closeError != nil { | |
merr = multierror.Append(merr, closeError) | |
} | |
return merr.ErrorOrNil() | |
} | |
func CloseAndMergeError(closable io.Closer, original error) error { | |
merr = multierror.Append(merr, closable.Close()) | |
return merr.ErrorOrNil() | |
} |
I'm not 100% but I think this will just work
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.
refactored and added test cases.
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
const ( |
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.
where did these constants come from? Is this a unrelated thing?
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.
They are copied from https://github.com/onflow/flow-go/blob/master/storage/badger/operation/prefix.go
8fa3022
to
a0068e1
Compare
This PR: