SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fs.configure: read and local add filer configuration
Chris Lu71056dae07d5
diff --git a/weed/filer/filer_conf.go b/weed/filer/filer_conf.goindex b75fb50846..3e3e9f8a96 100644--- a/weed/filer/filer_conf.go+++ b/weed/filer/filer_conf.go@@ -2,6 +2,7 @@ package filerimport ("context"+ "io""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/pb/filer_pb"@@ -47,10 +48,10 @@ func (fc *FilerConf) loadFromChunks(filer *Filer, chunks []*filer_pb.FileChunk)return}- return fc.loadFromBytes(data)+ return fc.LoadFromBytes(data)}-func (fc *FilerConf) loadFromBytes(data []byte) (err error) {+func (fc *FilerConf) LoadFromBytes(data []byte) (err error) {conf := &filer_pb.FilerConf{}err = proto.UnmarshalText(string(data), conf)if err != nil {@@ -64,9 +65,8 @@ func (fc *FilerConf) loadFromBytes(data []byte) (err error) {func (fc *FilerConf) doLoadConf(conf *filer_pb.FilerConf) (err error) {for _, location := range conf.Locations {- err = fc.rules.Put([]byte(location.LocationPrefix), location)+ err = fc.AddLocationConf(location)if err != nil {- glog.Errorf("put location prefix: %v", err)// this is not recoverablereturn nil}@@ -74,6 +74,15 @@ func (fc *FilerConf) doLoadConf(conf *filer_pb.FilerConf) (err error) {return nil}+func (fc *FilerConf) AddLocationConf(locConf *filer_pb.FilerConf_PathConf) (err error) {+ err = fc.rules.Put([]byte(locConf.LocationPrefix), locConf)+ if err != nil {+ glog.Errorf("put location prefix: %v", err)+ }+ return+}++var (EmptyFilerConfPathConf = &filer_pb.FilerConf_PathConf{})@@ -88,3 +97,17 @@ func (fc *FilerConf) MatchStorageRule(path string) (pathConf *filer_pb.FilerConf}return pathConf}++func (fc *FilerConf) ToProto() *filer_pb.FilerConf {+ m := &filer_pb.FilerConf{}+ fc.rules.Walk(func(key []byte, value interface{}) bool {+ pathConf := value.(*filer_pb.FilerConf_PathConf)+ m.Locations = append(m.Locations, pathConf)+ return true+ })+ return m+}++func (fc *FilerConf) ToText(writer io.Writer) error {+ return proto.MarshalText(writer, fc.ToProto())+}\ No newline at end of filediff --git a/weed/shell/command_fs_configure.go b/weed/shell/command_fs_configure.gonew file mode 100644index 0000000000..d8fcda83b7--- /dev/null+++ b/weed/shell/command_fs_configure.go@@ -0,0 +1,87 @@+package shell++import (+ "bytes"+ "flag"+ "io"+ "math"++ "github.com/chrislusf/seaweedfs/weed/filer"+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+)++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++ fs.configure -locationPrfix=/my/folder -++`+}++func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {++ fsConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ locationPrefix := fsConfigureCommand.String("locationPrefix", "", "path prefix")+ collection := fsConfigureCommand.String("collection", "", "assign writes to this colletion")+ replication := fsConfigureCommand.String("replication", "", "assign writes with this replication")+ ttl := fsConfigureCommand.String("ttl", "", "assign writes with this ttl")+ fsync := fsConfigureCommand.Bool("fsync", false, "fsync for the writes")+ 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 {++ request := &filer_pb.LookupDirectoryEntryRequest{+ Directory: filer.DirectoryEtc,+ Name: filer.FilerConfName,+ }+ respLookupEntry, err := filer_pb.LookupEntry(client, request)+ if err != nil {+ return err+ }++ return filer.StreamContent(commandEnv.MasterClient, &buf, respLookupEntry.Entry.Chunks, 0, math.MaxInt64)++ }); err != nil {+ return err+ }++ fc := filer.NewFilerConf()+ if err = fc.LoadFromBytes(buf.Bytes()); err != nil {+ return err+ }++ if *locationPrefix != "" {+ locConf := &filer_pb.FilerConf_PathConf{+ LocationPrefix: *locationPrefix,+ Collection: *collection,+ Replication: *replication,+ Ttl: *ttl,+ Fsync: *fsync,+ }+ fc.AddLocationConf(locConf)+ }++ fc.ToText(writer)++ if *apply {++ }++ return nil++}