Skip to content

Commit

Permalink
Avoid concurrency between CloseSession and flushStats (#5280)
Browse files Browse the repository at this point in the history
Signed-off-by: Changxin Miao <[email protected]>
  • Loading branch information
polyrabbit authored Nov 6, 2024
1 parent f7e0959 commit 03f5d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ type baseMeta struct {

dirStatsLock sync.Mutex
dirStats map[Ino]dirStat

fsStatsLock sync.Mutex
*fsStat

parentMu sync.Mutex // protect dirParents
Expand Down Expand Up @@ -577,7 +579,7 @@ func (m *baseMeta) CloseSession() error {
if m.conf.ReadOnly {
return nil
}
m.en.doFlushStats()
m.doFlushStats()
m.doFlushDirStat()
m.doFlushQuotas()
m.sesMu.Lock()
Expand Down
8 changes: 7 additions & 1 deletion pkg/meta/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ func (m *baseMeta) doFlushDirStat() {
func (m *baseMeta) flushStats() {
for {
time.Sleep(time.Second)
m.en.doFlushStats()
m.doFlushStats()
}
}

func (m *baseMeta) doFlushStats() {
m.fsStatsLock.Lock()
m.en.doFlushStats()
m.fsStatsLock.Unlock()
}

func (m *baseMeta) checkQuota(ctx Context, space, inodes int64, parents ...Ino) syscall.Errno {
if space <= 0 && inodes <= 0 {
return 0
Expand Down

0 comments on commit 03f5d30

Please sign in to comment.