aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/filer_conf.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer/filer_conf.go')
-rw-r--r--weed/filer/filer_conf.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/weed/filer/filer_conf.go b/weed/filer/filer_conf.go
index b75fb5084..3e3e9f8a9 100644
--- a/weed/filer/filer_conf.go
+++ b/weed/filer/filer_conf.go
@@ -2,6 +2,7 @@ package filer
import (
"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 recoverable
return 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 file