Skip to content

Commit e2964e1

Browse files
refactor/meta: dir filtering and pointer parameter (#6579)
1 parent 67830cd commit e2964e1

6 files changed

Lines changed: 16 additions & 18 deletions

File tree

pkg/meta/base.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type engine interface {
115115
doLink(ctx Context, inode, parent Ino, name string, attr *Attr) syscall.Errno
116116
doUnlink(ctx Context, parent Ino, name string, attr *Attr, skipCheckTrash ...bool) syscall.Errno
117117
doRmdir(ctx Context, parent Ino, name string, inode *Ino, attr *Attr, skipCheckTrash ...bool) syscall.Errno
118-
doBatchUnlink(ctx Context, parent Ino, entries []Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) (errno syscall.Errno)
118+
doBatchUnlink(ctx Context, parent Ino, entries []*Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) (errno syscall.Errno)
119119
doReadlink(ctx Context, inode Ino, noatime bool) (int64, []byte, error)
120120
doReaddir(ctx Context, inode Ino, plus uint8, entries *[]*Entry, limit int) syscall.Errno
121121
doRename(ctx Context, parentSrc Ino, nameSrc string, parentDst Ino, nameDst string, flags uint32, inode, tinode *Ino, attr, tattr *Attr) syscall.Errno
@@ -1652,7 +1652,10 @@ func (m *baseMeta) Rmdir(ctx Context, parent Ino, name string, skipCheckTrash ..
16521652
return st
16531653
}
16541654

1655-
func (m *baseMeta) BatchUnlink(ctx Context, parent Ino, entries []Entry, count *uint64, skipCheckTrash bool) syscall.Errno {
1655+
func (m *baseMeta) BatchUnlink(ctx Context, parent Ino, entries []*Entry, count *uint64, skipCheckTrash bool) syscall.Errno {
1656+
if len(entries) == 0 {
1657+
return 0
1658+
}
16561659
var length int64
16571660
var space int64
16581661
var inodes int64

pkg/meta/base_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4735,13 +4735,13 @@ func testBatchUnlinkWithUserGroupQuota(t *testing.T, m Meta, ctx Context, parent
47354735
t.Fatalf("User group quota not found before batch unlink")
47364736
}
47374737

4738-
var entries []Entry
4738+
var entries []*Entry
47394739
for i, fileName := range fileNames {
47404740
var attr Attr
47414741
if st := m.GetAttr(ctx, fileInodes[i], &attr); st != 0 {
47424742
t.Fatalf("GetAttr for %s: %s", fileName, st)
47434743
}
4744-
entries = append(entries, Entry{
4744+
entries = append(entries, &Entry{
47454745
Inode: fileInodes[i],
47464746
Name: []byte(fileName),
47474747
Attr: &attr,
@@ -4835,7 +4835,7 @@ func testBatchUnlinkWithUserGroupQuota(t *testing.T, m Meta, ctx Context, parent
48354835
if st := m.GetAttr(ctx, hardlinkInode, &hardlinkEntry); st != 0 {
48364836
t.Fatalf("GetAttr for hardlink: %s", st)
48374837
}
4838-
hardlinkEntries := []Entry{
4838+
hardlinkEntries := []*Entry{
48394839
{
48404840
Inode: hardlinkInode,
48414841
Name: []byte(hardlinkFileName2),

pkg/meta/redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ func (m *redisMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, s
17211721
return errno(err)
17221722
}
17231723

1724-
func (m *redisMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
1724+
func (m *redisMeta) doBatchUnlink(ctx Context, parent Ino, entries []*Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
17251725
if len(entries) == 0 {
17261726
return 0
17271727
}

pkg/meta/sql.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ func recordUserGroupDeletionStats(
26142614
}
26152615
}
26162616

2617-
func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
2617+
func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []*Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
26182618
if len(entries) == 0 {
26192619
return 0
26202620
}
@@ -2672,6 +2672,9 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
26722672
for _, entry := range entries {
26732673
e := &edge{Parent: parent, Name: entry.Name, Inode: entry.Inode}
26742674
if entry.Attr != nil {
2675+
if entry.Attr.Typ == TypeDirectory {
2676+
continue
2677+
}
26752678
e.Type = entry.Attr.Typ
26762679
}
26772680
entryInfos = append(entryInfos, &entryInfo{e: e, trash: trash})
@@ -2715,10 +2718,6 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
27152718
}
27162719

27172720
for _, info := range entryInfos {
2718-
if info.e.Type == TypeDirectory {
2719-
continue
2720-
}
2721-
27222721
if info.trash > 0 && info.n.Nlink > 1 {
27232722
info.trashName = m.trashEntry(parent, info.e.Inode, string(info.e.Name))
27242723
te := edge{
@@ -2771,10 +2770,6 @@ func (m *dbMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length
27712770

27722771
// walk each edge to decide whether to move to trash, decrement nlink or delete inode & xattrs
27732772
for _, info := range entryInfos {
2774-
if info.n.Type == TypeDirectory {
2775-
continue
2776-
}
2777-
27782773
edgesDel = append(edgesDel, edge{Parent: parent, Name: info.e.Name})
27792774
if !visited[info.n.Inode] {
27802775
if info.n.Nlink > 0 {

pkg/meta/tkv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ func (m *kvMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip
14271427
return errno(err)
14281428
}
14291429

1430-
func (m *kvMeta) doBatchUnlink(ctx Context, parent Ino, entries []Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
1430+
func (m *kvMeta) doBatchUnlink(ctx Context, parent Ino, entries []*Entry, length *int64, space *int64, inodes *int64, userGroupQuotas *[]userGroupQuotaDelta, skipCheckTrash ...bool) syscall.Errno {
14311431
return syscall.ENOTSUP
14321432
}
14331433

pkg/meta/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (m *baseMeta) emptyDir(ctx Context, inode Ino, skipCheckTrash bool, count *
301301
}
302302
var wg sync.WaitGroup
303303
var status syscall.Errno
304-
var nonDirEntries []Entry
304+
var nonDirEntries []*Entry
305305
for i, e := range entries {
306306
if e.Attr.Typ == TypeDirectory {
307307
select {
@@ -322,7 +322,7 @@ func (m *baseMeta) emptyDir(ctx Context, inode Ino, skipCheckTrash bool, count *
322322
}
323323
}
324324
} else {
325-
nonDirEntries = append(nonDirEntries, *e)
325+
nonDirEntries = append(nonDirEntries, e)
326326
}
327327
if ctx.Canceled() {
328328
return syscall.EINTR

0 commit comments

Comments
 (0)