From 395bcc005685adf264296619928fa4ba3ba79b63 Mon Sep 17 00:00:00 2001 From: xixi Date: Fri, 13 Jan 2023 23:45:21 +0800 Subject: [PATCH 1/3] warmup metadata when asked Signed-off-by: xixi --- cmd/warmup.go | 23 +++++++++++++++++------ pkg/vfs/fill.go | 7 ++++++- pkg/vfs/fill_test.go | 4 ++-- pkg/vfs/internal.go | 5 +++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cmd/warmup.go b/cmd/warmup.go index 587638d43f2f..d9cbc69dc2f4 100644 --- a/cmd/warmup.go +++ b/cmd/warmup.go @@ -71,6 +71,11 @@ $ juicefs warmup -f /tmp/filelist`, Aliases: []string{"b"}, Usage: "run in background", }, + &cli.BoolFlag{ + Name: "metadata", + Aliases: []string{"m"}, + Usage: "also warm up metadata", + }, }, } } @@ -114,19 +119,24 @@ END: } // send fill-cache command to controller file -func sendCommand(cf *os.File, batch []string, threads uint, background bool, dspin *utils.DoubleSpinner) { +func sendCommand(cf *os.File, batch []string, threads uint, background, metadata bool, dspin *utils.DoubleSpinner) { paths := strings.Join(batch, "\n") - var back uint8 + var back, withMeta uint8 if background { back = 1 } - wb := utils.NewBuffer(8 + 4 + 3 + uint32(len(paths))) + if metadata { + withMeta = 1 + } + + wb := utils.NewBuffer(8 + 4 + 4 + uint32(len(paths))) wb.Put32(meta.FillCache) - wb.Put32(4 + 3 + uint32(len(paths))) + wb.Put32(4 + 4 + uint32(len(paths))) wb.Put32(uint32(len(paths))) wb.Put([]byte(paths)) wb.Put16(uint16(threads)) wb.Put8(back) + wb.Put8(withMeta) if _, err := cf.Write(wb.Bytes()); err != nil { logger.Fatalf("Write message: %s", err) } @@ -201,6 +211,7 @@ func warmup(ctx *cli.Context) error { threads = 1 } background := ctx.Bool("background") + metadata := ctx.Bool("metadata") start := len(mp) batch := make([]string, 0, batchMax) progress := utils.NewProgress(background, true) @@ -220,12 +231,12 @@ func warmup(ctx *cli.Context) error { continue } if len(batch) >= batchMax { - sendCommand(controller, batch, threads, background, dspin) + sendCommand(controller, batch, threads, background, metadata, dspin) batch = batch[0:] } } if len(batch) > 0 { - sendCommand(controller, batch, threads, background, dspin) + sendCommand(controller, batch, threads, background, metadata, dspin) } progress.Done() if !background { diff --git a/pkg/vfs/fill.go b/pkg/vfs/fill.go index 2233e3c5026d..02615ac51704 100644 --- a/pkg/vfs/fill.go +++ b/pkg/vfs/fill.go @@ -34,7 +34,7 @@ type _file struct { size uint64 } -func (v *VFS) fillCache(ctx meta.Context, paths []string, concurrent int, count, bytes *uint64) { +func (v *VFS) fillCache(ctx meta.Context, paths []string, metadata bool, concurrent int, count, bytes *uint64) { logger.Infof("start to warmup %d paths with %d workers", len(paths), concurrent) start := time.Now() todo := make(chan _file, 10240) @@ -50,6 +50,11 @@ func (v *VFS) fillCache(ctx meta.Context, paths []string, concurrent int, count, if err := v.fillInode(ctx, f.ino, f.size, bytes); err != nil { logger.Errorf("Inode %d could be corrupted: %s", f.ino, err) } + if metadata { + if err := v.Meta.Open(ctx, f.ino, syscall.O_RDONLY, &meta.Attr{}); err != 0 { + logger.Errorf("Inode %d could be opened: %s", f.ino, err) + } + } if count != nil { atomic.AddUint64(count, 1) } diff --git a/pkg/vfs/fill_test.go b/pkg/vfs/fill_test.go index 967f5769f9b0..b7aa15ec5e48 100644 --- a/pkg/vfs/fill_test.go +++ b/pkg/vfs/fill_test.go @@ -36,7 +36,7 @@ func TestFill(t *testing.T) { _, _ = v.Symlink(ctx, "testfile", 1, "sym3") // normal cases - v.fillCache(meta.Background, []string{"/test/file", "/test", "/sym", "/"}, 2, nil, nil) + v.fillCache(meta.Background, []string{"/test/file", "/test", "/sym", "/"}, false, 2, nil, nil) // remove chunk var slices []meta.Slice @@ -45,5 +45,5 @@ func TestFill(t *testing.T) { _ = v.Store.Remove(s.Id, int(s.Size)) } // bad cases - v.fillCache(meta.Background, []string{"/test/file", "/sym2", "/sym3", "/.stats", "/not_exists"}, 2, nil, nil) + v.fillCache(meta.Background, []string{"/test/file", "/sym2", "/sym3", "/.stats", "/not_exists"}, false, 2, nil, nil) } diff --git a/pkg/vfs/internal.go b/pkg/vfs/internal.go index 4a274c339d08..0eb0121fc82b 100644 --- a/pkg/vfs/internal.go +++ b/pkg/vfs/internal.go @@ -433,16 +433,17 @@ func (v *VFS) handleInternalMsg(ctx meta.Context, cmd uint32, r *utils.Buffer, o paths := strings.Split(string(r.Get(int(r.Get32()))), "\n") concurrent := r.Get16() background := r.Get8() + metadata := r.Get8() if background == 0 { var count, bytes uint64 done := make(chan struct{}) go func() { - v.fillCache(ctx, paths, int(concurrent), &count, &bytes) + v.fillCache(ctx, paths, metadata > 0, int(concurrent), &count, &bytes) close(done) }() writeProgress(&count, &bytes, out, done) } else { - go v.fillCache(meta.NewContext(ctx.Pid(), ctx.Uid(), ctx.Gids()), paths, int(concurrent), nil, nil) + go v.fillCache(meta.NewContext(ctx.Pid(), ctx.Uid(), ctx.Gids()), paths, metadata > 0, int(concurrent), nil, nil) } _, _ = out.Write([]byte{0}) default: From 260d05934bc3cbb3a7c70c5080ae6b2376b4a483 Mon Sep 17 00:00:00 2001 From: xixi Date: Thu, 9 Feb 2023 00:56:22 +0800 Subject: [PATCH 2/3] revoke open cache override Signed-off-by: xixi --- cmd/warmup.go | 49 +++++++++++++++++--------------------------- pkg/vfs/fill.go | 5 +++-- pkg/vfs/fill_test.go | 4 ++-- pkg/vfs/internal.go | 5 ++--- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/cmd/warmup.go b/cmd/warmup.go index d9cbc69dc2f4..02f24ed0bdf1 100644 --- a/cmd/warmup.go +++ b/cmd/warmup.go @@ -41,19 +41,19 @@ func cmdWarmup() *cli.Command { Usage: "Build cache for target directories/files", ArgsUsage: "[PATH ...]", Description: ` -This command provides a faster way to actively build cache for the target files. It reads all objects -of the files and then write them into local cache directory. - -Examples: -# Warm all files in datadir -$ juicefs warmup /mnt/jfs/datadir - -# Warm only three files in datadir -$ cat /tmp/filelist -/mnt/jfs/datadir/f1 -/mnt/jfs/datadir/f2 -/mnt/jfs/datadir/f3 -$ juicefs warmup -f /tmp/filelist`, + This command provides a faster way to actively build cache for the target files. It reads all objects + of the files and then write them into local cache directory. + + Examples: + # Warm all files in datadir + $ juicefs warmup /mnt/jfs/datadir + + # Warm only three files in datadir + $ cat /tmp/filelist + /mnt/jfs/datadir/f1 + /mnt/jfs/datadir/f2 + /mnt/jfs/datadir/f3 + $ juicefs warmup -f /tmp/filelist`, Flags: []cli.Flag{ &cli.StringFlag{ Name: "file", @@ -71,11 +71,6 @@ $ juicefs warmup -f /tmp/filelist`, Aliases: []string{"b"}, Usage: "run in background", }, - &cli.BoolFlag{ - Name: "metadata", - Aliases: []string{"m"}, - Usage: "also warm up metadata", - }, }, } } @@ -119,24 +114,19 @@ END: } // send fill-cache command to controller file -func sendCommand(cf *os.File, batch []string, threads uint, background, metadata bool, dspin *utils.DoubleSpinner) { +func sendCommand(cf *os.File, batch []string, threads uint, background bool, dspin *utils.DoubleSpinner) { paths := strings.Join(batch, "\n") - var back, withMeta uint8 + var back uint8 if background { back = 1 } - if metadata { - withMeta = 1 - } - - wb := utils.NewBuffer(8 + 4 + 4 + uint32(len(paths))) + wb := utils.NewBuffer(8 + 4 + 3 + uint32(len(paths))) wb.Put32(meta.FillCache) - wb.Put32(4 + 4 + uint32(len(paths))) + wb.Put32(4 + 3 + uint32(len(paths))) wb.Put32(uint32(len(paths))) wb.Put([]byte(paths)) wb.Put16(uint16(threads)) wb.Put8(back) - wb.Put8(withMeta) if _, err := cf.Write(wb.Bytes()); err != nil { logger.Fatalf("Write message: %s", err) } @@ -211,7 +201,6 @@ func warmup(ctx *cli.Context) error { threads = 1 } background := ctx.Bool("background") - metadata := ctx.Bool("metadata") start := len(mp) batch := make([]string, 0, batchMax) progress := utils.NewProgress(background, true) @@ -231,12 +220,12 @@ func warmup(ctx *cli.Context) error { continue } if len(batch) >= batchMax { - sendCommand(controller, batch, threads, background, metadata, dspin) + sendCommand(controller, batch, threads, background, dspin) batch = batch[0:] } } if len(batch) > 0 { - sendCommand(controller, batch, threads, background, metadata, dspin) + sendCommand(controller, batch, threads, background, dspin) } progress.Done() if !background { diff --git a/pkg/vfs/fill.go b/pkg/vfs/fill.go index 02615ac51704..dafb5e7438db 100644 --- a/pkg/vfs/fill.go +++ b/pkg/vfs/fill.go @@ -34,7 +34,7 @@ type _file struct { size uint64 } -func (v *VFS) fillCache(ctx meta.Context, paths []string, metadata bool, concurrent int, count, bytes *uint64) { +func (v *VFS) fillCache(ctx meta.Context, paths []string, concurrent int, count, bytes *uint64) { logger.Infof("start to warmup %d paths with %d workers", len(paths), concurrent) start := time.Now() todo := make(chan _file, 10240) @@ -50,10 +50,11 @@ func (v *VFS) fillCache(ctx meta.Context, paths []string, metadata bool, concurr if err := v.fillInode(ctx, f.ino, f.size, bytes); err != nil { logger.Errorf("Inode %d could be corrupted: %s", f.ino, err) } - if metadata { + if v.Conf.Meta.OpenCache > 0 { if err := v.Meta.Open(ctx, f.ino, syscall.O_RDONLY, &meta.Attr{}); err != 0 { logger.Errorf("Inode %d could be opened: %s", f.ino, err) } + _ = v.Meta.Close(ctx, f.ino) } if count != nil { atomic.AddUint64(count, 1) diff --git a/pkg/vfs/fill_test.go b/pkg/vfs/fill_test.go index b7aa15ec5e48..967f5769f9b0 100644 --- a/pkg/vfs/fill_test.go +++ b/pkg/vfs/fill_test.go @@ -36,7 +36,7 @@ func TestFill(t *testing.T) { _, _ = v.Symlink(ctx, "testfile", 1, "sym3") // normal cases - v.fillCache(meta.Background, []string{"/test/file", "/test", "/sym", "/"}, false, 2, nil, nil) + v.fillCache(meta.Background, []string{"/test/file", "/test", "/sym", "/"}, 2, nil, nil) // remove chunk var slices []meta.Slice @@ -45,5 +45,5 @@ func TestFill(t *testing.T) { _ = v.Store.Remove(s.Id, int(s.Size)) } // bad cases - v.fillCache(meta.Background, []string{"/test/file", "/sym2", "/sym3", "/.stats", "/not_exists"}, false, 2, nil, nil) + v.fillCache(meta.Background, []string{"/test/file", "/sym2", "/sym3", "/.stats", "/not_exists"}, 2, nil, nil) } diff --git a/pkg/vfs/internal.go b/pkg/vfs/internal.go index 0eb0121fc82b..4a274c339d08 100644 --- a/pkg/vfs/internal.go +++ b/pkg/vfs/internal.go @@ -433,17 +433,16 @@ func (v *VFS) handleInternalMsg(ctx meta.Context, cmd uint32, r *utils.Buffer, o paths := strings.Split(string(r.Get(int(r.Get32()))), "\n") concurrent := r.Get16() background := r.Get8() - metadata := r.Get8() if background == 0 { var count, bytes uint64 done := make(chan struct{}) go func() { - v.fillCache(ctx, paths, metadata > 0, int(concurrent), &count, &bytes) + v.fillCache(ctx, paths, int(concurrent), &count, &bytes) close(done) }() writeProgress(&count, &bytes, out, done) } else { - go v.fillCache(meta.NewContext(ctx.Pid(), ctx.Uid(), ctx.Gids()), paths, metadata > 0, int(concurrent), nil, nil) + go v.fillCache(meta.NewContext(ctx.Pid(), ctx.Uid(), ctx.Gids()), paths, int(concurrent), nil, nil) } _, _ = out.Write([]byte{0}) default: From 626117e6b4e42147809990aa912b1696ddef62d9 Mon Sep 17 00:00:00 2001 From: xixi Date: Thu, 9 Feb 2023 00:58:51 +0800 Subject: [PATCH 3/3] revoke comments chages Signed-off-by: xixi --- cmd/warmup.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/warmup.go b/cmd/warmup.go index 02f24ed0bdf1..587638d43f2f 100644 --- a/cmd/warmup.go +++ b/cmd/warmup.go @@ -41,19 +41,19 @@ func cmdWarmup() *cli.Command { Usage: "Build cache for target directories/files", ArgsUsage: "[PATH ...]", Description: ` - This command provides a faster way to actively build cache for the target files. It reads all objects - of the files and then write them into local cache directory. - - Examples: - # Warm all files in datadir - $ juicefs warmup /mnt/jfs/datadir - - # Warm only three files in datadir - $ cat /tmp/filelist - /mnt/jfs/datadir/f1 - /mnt/jfs/datadir/f2 - /mnt/jfs/datadir/f3 - $ juicefs warmup -f /tmp/filelist`, +This command provides a faster way to actively build cache for the target files. It reads all objects +of the files and then write them into local cache directory. + +Examples: +# Warm all files in datadir +$ juicefs warmup /mnt/jfs/datadir + +# Warm only three files in datadir +$ cat /tmp/filelist +/mnt/jfs/datadir/f1 +/mnt/jfs/datadir/f2 +/mnt/jfs/datadir/f3 +$ juicefs warmup -f /tmp/filelist`, Flags: []cli.Flag{ &cli.StringFlag{ Name: "file",