libs: Call Flush() before rename #2428#2439
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2439 +/- ##
===========================================
+ Coverage 61.28% 61.33% +0.05%
===========================================
Files 198 198
Lines 16383 16397 +14
===========================================
+ Hits 10040 10057 +17
+ Misses 5508 5504 -4
- Partials 835 836 +1
|
melekes
left a comment
There was a problem hiding this comment.
Thank you for your contribution! Awesome work. I've left a few comments (mostly related to tests) which need to be addressed. After those are fixed, we can merge it
consensus/wal_test.go
Outdated
| t.Fatal(err) | ||
| } | ||
|
|
||
| time.Sleep(5 * time.Second) //wait groupCheckDuration, make sure RotateFile run |
There was a problem hiding this comment.
We're trying to avoid long sleep calls in our tests. Do you think we can do something with this call? Maybe make groupCheckDuration a configuration variable
# libs/autofile/group.go
type Config struct {
GroupCheckDuration time.Duration
}
func OpenGroup(headPath string, cfg Config) (g *Group, err error) {
# consensus/wal.go
type Config struct {
GroupConfig
}
func NewWAL(walFile string, cfg Config) (*baseWAL, error) {There was a problem hiding this comment.
Not only the GroupCheckDuration, but HeadSizeLimit also need to config, this config filed seems only need changed by test. I added some member func to Group, left NewWAL concise.
| if err != nil { | ||
| panic(fmt.Errorf("failed to create temp WAL file: %v", err)) | ||
| } | ||
|
|
There was a problem hiding this comment.
defer os.RemoveAll(walDir) ?
consensus/wal_test.go
Outdated
| t.Fatal(err) | ||
| } | ||
|
|
||
| wal.group.SetHeadSizeLimit(4096) //cause fragment |
There was a problem hiding this comment.
again, better to pass as a config option (although this requires some work)
consensus/wal_test.go
Outdated
|
|
||
| time.Sleep(5 * time.Second) //wait groupCheckDuration, make sure RotateFile run | ||
|
|
||
| wal.group.Flush() |
There was a problem hiding this comment.
wal.Group().Flush()
generally you should not access private fields / methods (even though you can) - sign that there's something wrong with your API
CHANGELOG_PENDING.md
Outdated
|
|
||
| BUG FIXES: | ||
| - [node] \#2294 Delay starting node until Genesis time | ||
| - [autofile] \#2428 Group.RotateFile need call Flush() before rename. |
There was a problem hiding this comment.
Could you please add your github username in the end? before rename (@goolAdapter)
libs/autofile/group.go
Outdated
| } | ||
|
|
||
| // SetGroupCheckDuration allows you to overwrite default groupCheckDuration, this must call before Start(). | ||
| func (g *Group) SetGroupCheckDuration(duration time.Duration) { |
There was a problem hiding this comment.
please don't. let's use config for this
consensus/wal_test.go
Outdated
|
|
||
| wal.group.SetHeadSizeLimit(4096) //cause fragment | ||
| //this magic number 4K can truncate the content when RotateFile. defaultHeadSizeLimit(10M) is hard to simulate. | ||
| wal.Group().SetHeadSizeLimit(4096) |
There was a problem hiding this comment.
same here. we shouldn't expose SetXXX methods for something which is not supposed to change during the WAL group lifetime.
There was a problem hiding this comment.
SetHeadSizeLimit is exposed before this PR,and was used in logjack cmd,should first keep consistent , refactor later? or I refactor it at the same time?
There was a problem hiding this comment.
We would appreciate if you refactor this part! Technical debt tends to accumulate over time, so we need to refactor code sometimes to maintain Tendermint in good shape continually.
libs/autofile/cmd/logjack.go
Outdated
|
|
||
| // Open Group | ||
| group, err := auto.OpenGroup(headPath) | ||
| group, err := auto.OpenGroup(headPath, auto.SetHeadSizeLimit(chopSize), auto.SetTotalSizeLimit(limitSize)) |
There was a problem hiding this comment.
if these are options now, they must not have a Set prefix
There was a problem hiding this comment.
yes, Set* -> With* looks better?
There was a problem hiding this comment.
GroupHeadSizeLimit()
GroupTotalSizeLimit()
|
@goolAdapter Could you resolve the conflicts with |
fix Group.RotateFile need call Flush() before rename. #2428