Skip to content

Commit

Permalink
optimize fast summary of leaf dir
Browse files Browse the repository at this point in the history
Signed-off-by: xixi <[email protected]>
  • Loading branch information
Hexilee committed Mar 16, 2023
1 parent d27a0c7 commit 4684594
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions pkg/meta/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ func GetSummary(r Meta, ctx Context, inode Ino, summary *Summary, recursive bool
entries := &entriesList[i]
eg.Go(func() error {
st := r.Readdir(ctx, ino, 1, entries)
if st == 0 || st == syscall.ENOENT {
return nil
if st != 0 && st != syscall.ENOENT {
return st
}
return st
return nil
})
}
if err := eg.Wait(); err != nil {
Expand Down Expand Up @@ -406,6 +406,8 @@ func FastGetSummary(r Meta, ctx Context, inode Ino, summary *Summary, recursive
}
return 0
}
summary.Dirs++

const concurrency = 1000
dirs := []Ino{inode}
for len(dirs) > 0 {
Expand All @@ -418,26 +420,38 @@ func FastGetSummary(r Meta, ctx Context, inode Ino, summary *Summary, recursive
entries := &entriesList[i]
stat := &dirStats[i]
eg.Go(func() error {
st := r.Readdir(ctx, ino, 0, entries)
if st == syscall.ENOENT {
st = 0
}
if st != 0 {
return st
}
s, err := r.GetDirStat(ctx, ino)
if err != nil {
return err
}
*stat = *s
var attr Attr
if st := r.GetAttr(ctx, ino, &attr); st != 0 && st != syscall.ENOENT {
return st
}
if attr.Nlink == 2 {
// leaf dir, no need to read entries
return nil
}
if st := r.Readdir(ctx, ino, 0, entries); st != 0 && st != syscall.ENOENT {
return st
}
return nil
})
}
if err := eg.Wait(); err != nil {
return errno(err)
}
dirs = dirs[:0]
for _, entries := range entriesList {
for i, entries := range entriesList {
stat := dirStats[i]
summary.Size += uint64(stat.space)
summary.Length += uint64(stat.length)
if entries == nil {
// leaf dir
summary.Files += uint64(stat.inodes)
continue
}
for _, e := range entries {
if bytes.Equal(e.Name, []byte(".")) || bytes.Equal(e.Name, []byte("..")) {
continue
Expand All @@ -452,10 +466,6 @@ func FastGetSummary(r Meta, ctx Context, inode Ino, summary *Summary, recursive
}
}
}
for _, stat := range dirStats {
summary.Size += uint64(stat.space)
summary.Length += uint64(stat.length)
}
}
return 0
}

0 comments on commit 4684594

Please sign in to comment.