Skip to content

libs: Call Flush() before rename #2428#2439

Merged
xla merged 10 commits intotendermint:developfrom
goolAdapter:fix_group_flush
Sep 25, 2018
Merged

libs: Call Flush() before rename #2428#2439
xla merged 10 commits intotendermint:developfrom
goolAdapter:fix_group_flush

Conversation

@goolAdapter
Copy link
Contributor

fix Group.RotateFile need call Flush() before rename. #2428

@codecov-io
Copy link

codecov-io commented Sep 19, 2018

Codecov Report

Merging #2439 into develop will increase coverage by 0.05%.
The diff coverage is 54.34%.

@@             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
Impacted Files Coverage Δ
consensus/state.go 77.27% <100%> (+0.71%) ⬆️
consensus/wal.go 62.79% <100%> (+1.55%) ⬆️
consensus/wal_generator.go 79.43% <46.66%> (-1.15%) ⬇️
libs/autofile/group.go 65.54% <53.57%> (-1.22%) ⬇️
blockchain/pool.go 65.73% <0%> (-0.7%) ⬇️
consensus/reactor.go 73.82% <0%> (+0.8%) ⬆️
libs/autofile/autofile.go 76.05% <0%> (+1.4%) ⬆️

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

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

t.Fatal(err)
}

time.Sleep(5 * time.Second) //wait groupCheckDuration, make sure RotateFile run
Copy link
Contributor

Choose a reason for hiding this comment

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

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) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

defer os.RemoveAll(walDir) ?

t.Fatal(err)
}

wal.group.SetHeadSizeLimit(4096) //cause fragment
Copy link
Contributor

Choose a reason for hiding this comment

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

again, better to pass as a config option (although this requires some work)


time.Sleep(5 * time.Second) //wait groupCheckDuration, make sure RotateFile run

wal.group.Flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

wal.Group().Flush()

generally you should not access private fields / methods (even though you can) - sign that there's something wrong with your API


BUG FIXES:
- [node] \#2294 Delay starting node until Genesis time
- [autofile] \#2428 Group.RotateFile need call Flush() before rename.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add your github username in the end? before rename (@goolAdapter)

}

// SetGroupCheckDuration allows you to overwrite default groupCheckDuration, this must call before Start().
func (g *Group) SetGroupCheckDuration(duration time.Duration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't. let's use config for this


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

Choose a reason for hiding this comment

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

same here. we shouldn't expose SetXXX methods for something which is not supposed to change during the WAL group lifetime.

Copy link
Contributor Author

@goolAdapter goolAdapter Sep 19, 2018

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

@melekes melekes Sep 19, 2018

Choose a reason for hiding this comment

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

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.


// Open Group
group, err := auto.OpenGroup(headPath)
group, err := auto.OpenGroup(headPath, auto.SetHeadSizeLimit(chopSize), auto.SetTotalSizeLimit(limitSize))
Copy link
Contributor

Choose a reason for hiding this comment

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

if these are options now, they must not have a Set prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, Set* -> With* looks better?

Copy link
Contributor

Choose a reason for hiding this comment

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

GroupHeadSizeLimit()
GroupTotalSizeLimit()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

Cool, thanks!

@xla
Copy link
Contributor

xla commented Sep 25, 2018

@goolAdapter Could you resolve the conflicts with develop then this should be good to go.

@xla xla self-assigned this Sep 25, 2018
@xla xla changed the title fix Group.RotateFile need call Flush() before rename. #2428 libs: Call Flush() before rename. #2428 Sep 25, 2018
@xla xla changed the title libs: Call Flush() before rename. #2428 libs: Call Flush() before rename #2428 Sep 25, 2018
@xla xla merged commit 110b07f into tendermint:develop Sep 25, 2018
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.

4 participants