diff --git a/cmd/rmr.go b/cmd/rmr.go index 2ad1090e03b6..e79988fb8220 100644 --- a/cmd/rmr.go +++ b/cmd/rmr.go @@ -71,12 +71,15 @@ func openController(dpath string) (*os.File, error) { func rmr(ctx *cli.Context) error { setup(ctx, 1) var flag uint8 - var numThreads uint8 + var numThreads int - numThreads = uint8(ctx.Int("threads")) + numThreads = 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") @@ -109,8 +112,7 @@ func rmr(ctx *cli.Context) error { wb.Put64(inode) wb.Put8(uint8(len(name))) wb.Put([]byte(name)) - wb.Put8(flag) - wb.Put8(numThreads) + wb.Put8(flag + uint8(numThreads << 1)) _, err = f.Write(wb.Bytes()) if err != nil { logger.Fatalf("write message: %s", err) diff --git a/pkg/meta/utils.go b/pkg/meta/utils.go index 49f8d33d2e23..84734a0b836d 100644 --- a/pkg/meta/utils.go +++ b/pkg/meta/utils.go @@ -351,12 +351,16 @@ func (m *baseMeta) RemoveEx(ctx Context, parent Ino, name string, skipTrash bool return m.Unlink(ctx, parent, name) } if numThreads <= 0 { + logger.Infof("Invalid threads number %d , auto adjust to 50 .", numThreads) numThreads = 50 } else if numThreads < 2 { + logger.Infof("Invalid threads number %d , auto adjust to 2 .", numThreads) numThreads = 2 - } else if numThreads > 255 { - numThreads = 255 + } else if numThreads > 127 { + logger.Infof("Invalid threads number %d , auto adjust to 127 .", numThreads) + numThreads = 127 } + logger.Infof("Start emptyEntry with %d concurrent threads .", numThreads) concurrent := make(chan int, numThreads) return m.emptyEntry(ctx, parent, name, inode, skipTrash, count, concurrent) } diff --git a/pkg/vfs/internal.go b/pkg/vfs/internal.go index 87e86b791bcf..b591dc043a6a 100644 --- a/pkg/vfs/internal.go +++ b/pkg/vfs/internal.go @@ -300,10 +300,9 @@ func (v *VFS) handleInternalMsg(ctx meta.Context, cmd uint32, r *utils.Buffer, o var skipTrash bool var numThreads uint8 = 50 if r.HasMore() { - skipTrash = r.Get8()&1 != 0 - if r.HasMore() { - numThreads = r.Get8() - } + numThreads = r.Get8() + skipTrash = numThreads&1 != 0 + numThreads = (numThreads >> 1) } var count uint64 var st syscall.Errno