Skip to content

Commit

Permalink
revoke open cache override
Browse files Browse the repository at this point in the history
Signed-off-by: xixi <[email protected]>
  • Loading branch information
Hexilee committed Feb 8, 2023
1 parent 395bcc0 commit 260d059
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
49 changes: 19 additions & 30 deletions cmd/warmup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
},
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/vfs/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vfs/fill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
5 changes: 2 additions & 3 deletions pkg/vfs/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 260d059

Please sign in to comment.