mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
enforce bucket quota
This commit is contained in:
parent
6e57d8d0de
commit
e47f63d159
|
@ -11,28 +11,28 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Commands = append(Commands, &commandS3BucketQuotaCheck{})
|
Commands = append(Commands, &commandS3BucketQuotaEnforce{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type commandS3BucketQuotaCheck struct {
|
type commandS3BucketQuotaEnforce struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandS3BucketQuotaCheck) Name() string {
|
func (c *commandS3BucketQuotaEnforce) Name() string {
|
||||||
return "s3.bucket.quota.check"
|
return "s3.bucket.quota.enforce"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandS3BucketQuotaCheck) Help() string {
|
func (c *commandS3BucketQuotaEnforce) Help() string {
|
||||||
return `check quota for all buckets, make the bucket read only if over the limit
|
return `check quota for all buckets, make the bucket read only if over the limit
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
s3.bucket.quota.check -force
|
s3.bucket.quota.enforce -apply
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
func (c *commandS3BucketQuotaEnforce) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
||||||
|
|
||||||
bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
enforceQuotaLimit := bucketCommand.Bool("force", false, "actually change the buckets readonly attribute")
|
applyQuotaLimit := bucketCommand.Bool("apply", false, "actually change the buckets readonly attribute")
|
||||||
if err = bucketCommand.Parse(args); err != nil {
|
if err = bucketCommand.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -79,11 +79,14 @@ func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, wr
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply the configuration changes
|
// apply the configuration changes
|
||||||
if hasConfChanges && *enforceQuotaLimit {
|
if hasConfChanges && *applyQuotaLimit {
|
||||||
|
|
||||||
var buf2 bytes.Buffer
|
var buf2 bytes.Buffer
|
||||||
fc.ToText(&buf2)
|
fc.ToText(&buf2)
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, string(buf2.Bytes()))
|
||||||
|
fmt.Fprintln(writer)
|
||||||
|
|
||||||
if err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
if err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
return filer.SaveInsideFiler(client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, buf2.Bytes())
|
return filer.SaveInsideFiler(client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, buf2.Bytes())
|
||||||
}); err != nil && err != filer_pb.ErrNotFound {
|
}); err != nil && err != filer_pb.ErrNotFound {
|
||||||
|
@ -95,16 +98,11 @@ func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, wr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandS3BucketQuotaCheck) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize uint64) (hasConfChanges bool) {
|
func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize uint64) (hasConfChanges bool) {
|
||||||
|
|
||||||
locPrefix := filerBucketsPath + "/" + entry.Name + "/"
|
locPrefix := filerBucketsPath + "/" + entry.Name + "/"
|
||||||
locConf := fc.MatchStorageRule(locPrefix)
|
locConf := fc.MatchStorageRule(locPrefix)
|
||||||
if locConf == nil {
|
locConf.LocationPrefix = locPrefix
|
||||||
locConf = &filer_pb.FilerConf_PathConf{
|
|
||||||
LocationPrefix: locPrefix,
|
|
||||||
Collection: entry.Name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry.Quota > 0 {
|
if entry.Quota > 0 {
|
||||||
if locConf.ReadOnly {
|
if locConf.ReadOnly {
|
||||||
|
|
Loading…
Reference in a new issue