2020-11-16 02:09:35 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"flag"
|
2020-11-16 04:15:47 +00:00
|
|
|
"fmt"
|
2020-11-16 02:09:35 +00:00
|
|
|
"io"
|
2020-11-17 03:57:08 +00:00
|
|
|
"strings"
|
2020-11-16 02:09:35 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2020-11-17 09:00:02 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
2020-11-16 02:09:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Commands = append(Commands, &commandFsConfigure{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type commandFsConfigure struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsConfigure) Name() string {
|
|
|
|
return "fs.configure"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsConfigure) Help() string {
|
|
|
|
return `configure and apply storage options for each location
|
|
|
|
|
2020-11-16 17:54:26 +00:00
|
|
|
# see the current configuration file content
|
2020-11-16 05:31:14 +00:00
|
|
|
fs.configure
|
|
|
|
|
|
|
|
# trying the changes and see the possible configuration file content
|
|
|
|
fs.configure -locationPrfix=/my/folder -collection=abc
|
|
|
|
fs.configure -locationPrfix=/my/folder -collection=abc -ttl=7d
|
|
|
|
|
2020-11-17 09:00:02 +00:00
|
|
|
# example: configure adding only 1 physical volume for each bucket collection
|
|
|
|
fs.configure -locationPrfix=/buckets/ -volumeGrowthCount=1
|
|
|
|
|
2020-11-16 05:31:14 +00:00
|
|
|
# apply the changes
|
|
|
|
fs.configure -locationPrfix=/my/folder -collection=abc -apply
|
|
|
|
|
|
|
|
# delete the changes
|
|
|
|
fs.configure -locationPrfix=/my/folder -delete -apply
|
2020-11-16 02:09:35 +00:00
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
|
|
|
fsConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
2020-11-16 04:15:47 +00:00
|
|
|
locationPrefix := fsConfigureCommand.String("locationPrefix", "", "path prefix, required to update the path-specific configuration")
|
2020-11-16 05:16:28 +00:00
|
|
|
collection := fsConfigureCommand.String("collection", "", "assign writes to this collection")
|
2020-11-16 02:09:35 +00:00
|
|
|
replication := fsConfigureCommand.String("replication", "", "assign writes with this replication")
|
|
|
|
ttl := fsConfigureCommand.String("ttl", "", "assign writes with this ttl")
|
2020-12-13 20:06:21 +00:00
|
|
|
diskType := fsConfigureCommand.String("disk", "", "[hdd|ssd] choose between hard drive or solid state drive")
|
2020-11-16 02:09:35 +00:00
|
|
|
fsync := fsConfigureCommand.Bool("fsync", false, "fsync for the writes")
|
2020-11-17 09:00:02 +00:00
|
|
|
volumeGrowthCount := fsConfigureCommand.Int("volumeGrowthCount", 0, "the number of physical volumes to add if no writable volumes")
|
2020-11-16 04:15:47 +00:00
|
|
|
isDelete := fsConfigureCommand.Bool("delete", false, "delete the configuration by locationPrefix")
|
2020-11-16 02:09:35 +00:00
|
|
|
apply := fsConfigureCommand.Bool("apply", false, "update and apply filer configuration")
|
|
|
|
if err = fsConfigureCommand.Parse(args); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
2020-12-10 19:11:02 +00:00
|
|
|
return filer.ReadEntry(commandEnv.MasterClient, client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, &buf)
|
2020-12-07 03:43:31 +00:00
|
|
|
}); err != nil && err != filer_pb.ErrNotFound {
|
2020-11-16 02:09:35 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fc := filer.NewFilerConf()
|
2020-12-07 03:43:31 +00:00
|
|
|
if buf.Len() > 0 {
|
|
|
|
if err = fc.LoadFromBytes(buf.Bytes()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-16 02:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if *locationPrefix != "" {
|
|
|
|
locConf := &filer_pb.FilerConf_PathConf{
|
2020-11-17 09:00:02 +00:00
|
|
|
LocationPrefix: *locationPrefix,
|
|
|
|
Collection: *collection,
|
|
|
|
Replication: *replication,
|
|
|
|
Ttl: *ttl,
|
|
|
|
Fsync: *fsync,
|
2020-12-13 19:59:32 +00:00
|
|
|
DiskType: *diskType,
|
2020-11-17 09:00:02 +00:00
|
|
|
VolumeGrowthCount: uint32(*volumeGrowthCount),
|
2020-11-16 02:09:35 +00:00
|
|
|
}
|
2020-11-17 09:00:02 +00:00
|
|
|
|
|
|
|
// check collection
|
2020-11-17 03:57:08 +00:00
|
|
|
if *collection != "" && strings.HasPrefix(*locationPrefix, "/buckets/") {
|
2020-12-23 01:43:13 +00:00
|
|
|
return fmt.Errorf("one s3 bucket goes to one collection and not customizable")
|
2020-11-17 03:57:08 +00:00
|
|
|
}
|
2020-11-17 09:00:02 +00:00
|
|
|
|
|
|
|
// check replication
|
|
|
|
if *replication != "" {
|
|
|
|
rp, err := super_block.NewReplicaPlacementFromString(*replication)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("parse replication %s: %v", *replication, err)
|
|
|
|
}
|
2020-11-26 19:22:30 +00:00
|
|
|
if *volumeGrowthCount%rp.GetCopyCount() != 0 {
|
2020-11-17 09:00:02 +00:00
|
|
|
return fmt.Errorf("volumeGrowthCount %d should be devided by replication copy count %d", *volumeGrowthCount, rp.GetCopyCount())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save it
|
2020-11-16 04:15:47 +00:00
|
|
|
if *isDelete {
|
|
|
|
fc.DeleteLocationConf(*locationPrefix)
|
|
|
|
} else {
|
|
|
|
fc.AddLocationConf(locConf)
|
|
|
|
}
|
2020-11-16 02:09:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 04:15:47 +00:00
|
|
|
buf.Reset()
|
|
|
|
fc.ToText(&buf)
|
|
|
|
|
|
|
|
fmt.Fprintf(writer, string(buf.Bytes()))
|
2020-11-16 05:48:17 +00:00
|
|
|
fmt.Fprintln(writer)
|
2020-11-16 02:09:35 +00:00
|
|
|
|
|
|
|
if *apply {
|
|
|
|
|
2020-12-10 19:11:02 +00:00
|
|
|
if err := filer.SaveAs(commandEnv.option.FilerHost, int(commandEnv.option.FilerPort), filer.DirectoryEtcSeaweedFS, filer.FilerConfName, "text/plain; charset=utf-8", &buf); err != nil {
|
2020-11-16 04:15:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-16 02:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|