Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd & meta: add support for directory quota #3268

Merged
merged 52 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1b57518
cmd: add `quota` command
SandyXSD Feb 24, 2023
5c7c40a
manage quotas in meta pkg
SandyXSD Feb 26, 2023
e1aa453
add check & update quota for mknod & write
SandyXSD Feb 26, 2023
8f35fc9
fix command
SandyXSD Feb 27, 2023
8091106
add lock for dirParent
SandyXSD Feb 28, 2023
91cfcc1
add lock for dirQuotas
SandyXSD Feb 28, 2023
2e0aa9e
add simple unittest
SandyXSD Feb 28, 2023
abd6020
adjust
SandyXSD Feb 28, 2023
e46c0d4
remove quota when deleting the directory
SandyXSD Feb 28, 2023
ad1b905
Merge branch 'main' into wip-quota
SandyXSD Mar 1, 2023
74196e7
Merge branch 'main' into wip-quota
SandyXSD Mar 2, 2023
a4bd56d
fix updates of quota
SandyXSD Mar 2, 2023
7b9f9df
adjust checkQuota
SandyXSD Mar 2, 2023
b8a44ba
adjust
SandyXSD Mar 3, 2023
df14725
merge from main
Hexilee Mar 14, 2023
c2dccc9
fix lint
Hexilee Mar 14, 2023
858be5c
fix staging merge
Hexilee Mar 14, 2023
ed32b8d
remove parent from quota
Hexilee Mar 14, 2023
e0ee1d8
fix dead loop
Hexilee Mar 15, 2023
8e78942
fix dead lock
Hexilee Mar 15, 2023
fdae90f
remove logs
Hexilee Mar 15, 2023
4456636
rename methods
Hexilee Mar 15, 2023
d4c03ce
dirMu use RWMutex
Hexilee Mar 15, 2023
14e2d81
add dirRecUsedSpaceKey and dirRecUsedInodesKey for redis
Hexilee Mar 17, 2023
599bec9
implement HandleQuota for redis
Hexilee Mar 17, 2023
4005af0
implement redis
Hexilee Mar 17, 2023
74ad4d4
redis pas quota test
Hexilee Mar 20, 2023
d02bde1
fix ineffassign error
Hexilee Mar 20, 2023
ede0e53
implement tkv
Hexilee Mar 20, 2023
fcf082e
tkv quota pass tests
Hexilee Mar 20, 2023
1b9fd44
enable some skipped tests
Hexilee Mar 20, 2023
381158d
skip some mutate test
Hexilee Mar 20, 2023
64af34b
allow redis txn without pessimistic lock
Hexilee Mar 21, 2023
179449e
revoke redis txn without pessimistic lock
Hexilee Mar 21, 2023
92a417b
do not use txn in QuotaSet of redis
Hexilee Mar 21, 2023
286d9ad
address comments
SandyXSD Mar 21, 2023
15f408e
remove deleted quota
SandyXSD Mar 21, 2023
d246920
use different locks for dirParents and dirQuotas
SandyXSD Mar 21, 2023
3c0ee4d
remove loadQuotas in rename
SandyXSD Mar 21, 2023
4b80ac6
fix Rename
SandyXSD Mar 21, 2023
e4da9e7
unify the meta engines
SandyXSD Mar 22, 2023
612542f
remove Inode in Quota
SandyXSD Mar 22, 2023
6f44fd9
get path for each quota
SandyXSD Mar 22, 2023
dc38a7b
Merge branch 'main' into wip-quota
SandyXSD Mar 22, 2023
e8aa6c3
rollback unnecessary change for tests
SandyXSD Mar 22, 2023
4cc8666
fix redis error
SandyXSD Mar 22, 2023
ae9c052
fix Redis get quota
SandyXSD Mar 22, 2023
fbfe2c1
fix redis doRename
SandyXSD Mar 22, 2023
81c2707
Merge branch 'main' into wip-quota
SandyXSD Mar 23, 2023
52b9b0d
fix checkQuota for clone
SandyXSD Mar 23, 2023
406c258
Update pkg/meta/redis.go
SandyXSD Mar 23, 2023
c948d98
adjust comments for Redis
SandyXSD Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Main(args []string) error {
Commands: []*cli.Command{
cmdFormat(),
cmdConfig(),
cmdQuota(),
cmdDestroy(),
cmdGC(),
cmdFsck(),
Expand Down
133 changes: 133 additions & 0 deletions cmd/quota.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* JuiceFS, Copyright 2023 Juicedata, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"fmt"

"github.com/juicedata/juicefs/pkg/meta"

"github.com/urfave/cli/v2"
)

func cmdQuota() *cli.Command {
return &cli.Command{
Name: "quota",
Category: "ADMIN",
Usage: "Manage directory quotas",
ArgsUsage: "META-URL",
HideHelpCommand: true,
Description: `
Examples:
$ juicefs quota set redis://localhost --path /dir1 --capacity 1 --inodes 100
$ juicefs quota get redis://localhost --path /dir1
$ juicefs quota del redis://localhost --path /dir1
$ juicefs quota ls redis://localhost`,
Subcommands: []*cli.Command{
{
Name: "set",
Usage: "Set quota to a directory",
ArgsUsage: "META-URL",
Action: quota,
},
{
Name: "get",
Usage: "Get quota of a directory",
ArgsUsage: "META-URL",
Action: quota,
},
{
Name: "del",
Usage: "Delete quota of a directory",
ArgsUsage: "META-URL",
Action: quota,
},
{
Name: "ls",
Usage: "List all directory quotas",
ArgsUsage: "META-URL",
Action: quota,
},
{
Name: "check",
Usage: "Check quota consistency of a directory",
ArgsUsage: "META-URL",
Action: quota,
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "path",
Usage: "full path of the directory within the volume",
},
&cli.Uint64Flag{
Name: "capacity",
Usage: "hard quota of the directory limiting its usage of space in GiB",
},
&cli.Uint64Flag{
Name: "inodes",
Usage: "hard quota of the directory limiting its number of inodes",
},
},
}
}

func quota(c *cli.Context) error {
setup(c, 1)
var cmd uint8
switch c.Command.Name {
case "set":
cmd = meta.QuotaSet
case "get":
cmd = meta.QuotaGet
case "del":
cmd = meta.QuotaDel
case "ls":
cmd = meta.QuotaList
case "check":
cmd = meta.QuotaCheck
default:
logger.Fatalf("Invalid quota command: %s", c.Command.Name)
}
dpath := c.String("path")
if dpath == "" && cmd != meta.QuotaList {
logger.Fatalf("Please specify the directory with `--path <dir>` option")
}
removePassword(c.Args().Get(0))

m := meta.NewClient(c.Args().Get(0), nil)
qs := make(map[string]*meta.Quota)
if cmd == meta.QuotaSet {
q := &meta.Quota{MaxSpace: -1, MaxInodes: -1} // negative means no change
if c.IsSet("capacity") {
q.MaxSpace = int64(c.Uint64("capacity")) << 30
}
if c.IsSet("inodes") {
q.MaxInodes = int64(c.Uint64("inodes"))
}
qs[dpath] = q
}
if err := m.HandleQuota(meta.Background, cmd, dpath, qs); err != nil {
return err
}

for p, q := range qs {
// FIXME: need a better way to do print
fmt.Printf("%s: %+v\n", p, *q)
}
return nil
}
Loading