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

fix restore: count dir stats and quota #4095

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func restore(ctx *cli.Context) error {
}

func doRestore(m meta.Meta, hour string, putBack bool, threads int) {
if err := m.NewSession(false); err != nil {
logger.Warningf("running without sessions because fail to new session: %s", err)
} else {
defer func() {
_ = m.CloseSession()
}()
}
logger.Infof("restore files in %s ...", hour)
ctx := meta.Background
var parent meta.Ino
Expand Down
65 changes: 33 additions & 32 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ func (m *baseMeta) CloseSession() error {
return nil
}
m.doFlushDirStat()
m.doFlushQuotas()
m.sesMu.Lock()
m.umounting = true
m.sesMu.Unlock()
Expand Down Expand Up @@ -758,45 +759,45 @@ func (m *baseMeta) updateDirQuota(ctx Context, inode Ino, space, inodes int64) {
}

func (m *baseMeta) flushQuotas() {
quotas := make(map[Ino]*Quota)
var newSpace, newInodes int64
for {
time.Sleep(time.Second * 3)
if !m.getFormat().DirStats {
continue
m.doFlushQuotas()
}
}

func (m *baseMeta) doFlushQuotas() {
if !m.getFormat().DirStats {
return
}
stageMap := make(map[Ino]*Quota)
m.quotaMu.RLock()
for ino, q := range m.dirQuotas {
newSpace := atomic.LoadInt64(&q.newSpace)
newInodes := atomic.LoadInt64(&q.newInodes)
if newSpace != 0 || newInodes != 0 {
stageMap[ino] = &Quota{newSpace: newSpace, newInodes: newInodes}
}
}
m.quotaMu.RUnlock()
if len(stageMap) == 0 {
return
}

if err := m.en.doFlushQuotas(Background, stageMap); err != nil {
logger.Warnf("Flush quotas: %s", err)
} else {
m.quotaMu.RLock()
for ino, q := range m.dirQuotas {
newSpace = atomic.LoadInt64(&q.newSpace)
newInodes = atomic.LoadInt64(&q.newInodes)
if newSpace != 0 || newInodes != 0 {
quotas[ino] = &Quota{newSpace: newSpace, newInodes: newInodes}
for ino, snap := range stageMap {
q := m.dirQuotas[ino]
if q == nil {
continue
}
atomic.AddInt64(&q.newSpace, -snap.newSpace)
atomic.AddInt64(&q.UsedSpace, snap.newSpace)
atomic.AddInt64(&q.newInodes, -snap.newInodes)
atomic.AddInt64(&q.UsedInodes, snap.newInodes)
}
m.quotaMu.RUnlock()
if len(quotas) == 0 {
continue
}

if err := m.en.doFlushQuotas(Background, quotas); err != nil {
logger.Warnf("Flush quotas: %s", err)
} else {
m.quotaMu.RLock()
for ino, snap := range quotas {
q := m.dirQuotas[ino]
if q == nil {
continue
}
atomic.AddInt64(&q.newSpace, -snap.newSpace)
atomic.AddInt64(&q.UsedSpace, snap.newSpace)
atomic.AddInt64(&q.newInodes, -snap.newInodes)
atomic.AddInt64(&q.UsedInodes, snap.newInodes)
}
m.quotaMu.RUnlock()
}
for ino := range quotas {
delete(quotas, ino)
}
}
}

Expand Down