Skip to content

Commit

Permalink
fix use dedicate byte for threads
Browse files Browse the repository at this point in the history
  • Loading branch information
anysql committed Jan 7, 2025
1 parent 62b09b2 commit 6003d10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
12 changes: 5 additions & 7 deletions cmd/rmr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ juicefs rmr /mnt/jfs/foo`,
Name: "threads",
Aliases: []string{"p"},
Value: 50,
Usage: "number of threads for delete jobs (appropriate value)",
Usage: "number of threads for delete jobs (value from 2 to 255)",
},
},
}
Expand All @@ -71,15 +71,12 @@ func openController(dpath string) (*os.File, error) {
func rmr(ctx *cli.Context) error {
setup(ctx, 1)
var flag uint8
var numThreads int
var numThreads uint8

numThreads = ctx.Int("threads")
numThreads = uint8(ctx.Int("threads"))
if numThreads < 2 {
numThreads = 2
}
if numThreads > 127 {
numThreads = 127
}
if ctx.Bool("skip-trash") {
if os.Getuid() != 0 {
logger.Fatalf("Only root can remove files directly")
Expand Down Expand Up @@ -112,7 +109,8 @@ func rmr(ctx *cli.Context) error {
wb.Put64(inode)
wb.Put8(uint8(len(name)))
wb.Put([]byte(name))
wb.Put8(flag + uint8(numThreads * 2))
wb.Put8(flag)
wb.Put8(numThreads)
_, err = f.Write(wb.Bytes())
if err != nil {
logger.Fatalf("write message: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/meta/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ func (m *baseMeta) RemoveEx(ctx Context, parent Ino, name string, skipTrash bool
}
if numThreads <= 0 {
numThreads = 50
} else if numThreads < 2 {
numThreads = 2
} else if numThreads > 255 {
numThreads = 255
}
concurrent := make(chan int, numThreads)
return m.emptyEntry(ctx, parent, name, inode, skipTrash, count, concurrent)
Expand Down
15 changes: 5 additions & 10 deletions pkg/vfs/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,17 @@ func (v *VFS) handleInternalMsg(ctx meta.Context, cmd uint32, r *utils.Buffer, o
inode := Ino(r.Get64())
name := string(r.Get(int(r.Get8())))
var skipTrash bool
var numThreads int = 50
var numThreads uint8 = 50
if r.HasMore() {
numThreads = int(r.Get8())
skipTrash = numThreads&1 != 0
numThreads = numThreads / 2
if numThreads == 0 {
numThreads = 50
}
if numThreads < 2 {
numThreads = 2
skipTrash = r.Get8()&1 != 0
if r.HasMore() {
numThreads = r.Get8()
}
}
var count uint64
var st syscall.Errno
go func() {
st = v.Meta.RemoveEx(ctx, inode, name, skipTrash, numThreads, &count)
st = v.Meta.RemoveEx(ctx, inode, name, skipTrash, int(numThreads), &count)
if st != 0 {
logger.Errorf("remove %d/%s: %s", inode, name, st)
}
Expand Down

0 comments on commit 6003d10

Please sign in to comment.