mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 23:17:57 +08:00
filer conf: delete location specific configuration
This commit is contained in:
@@ -82,6 +82,18 @@ func (fc *FilerConf) AddLocationConf(locConf *filer_pb.FilerConf_PathConf) (err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fc *FilerConf) DeleteLocationConf(locationPrefix string) {
|
||||||
|
rules := ptrie.New()
|
||||||
|
fc.rules.Walk(func(key []byte, value interface{}) bool {
|
||||||
|
if string(key) == locationPrefix {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
rules.Put(key, value)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
fc.rules = rules
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
EmptyFilerConfPathConf = &filer_pb.FilerConf_PathConf{}
|
EmptyFilerConfPathConf = &filer_pb.FilerConf_PathConf{}
|
||||||
@@ -110,4 +122,4 @@ func (fc *FilerConf) ToProto() *filer_pb.FilerConf {
|
|||||||
|
|
||||||
func (fc *FilerConf) ToText(writer io.Writer) error {
|
func (fc *FilerConf) ToText(writer io.Writer) error {
|
||||||
return proto.MarshalText(writer, fc.ToProto())
|
return proto.MarshalText(writer, fc.ToProto())
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/viant/ptrie"
|
"github.com/viant/ptrie"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -143,5 +144,6 @@ func IsRename(event *SubscribeMetadataResponse) bool {
|
|||||||
var _ = ptrie.KeyProvider(&FilerConf_PathConf{})
|
var _ = ptrie.KeyProvider(&FilerConf_PathConf{})
|
||||||
|
|
||||||
func (fp *FilerConf_PathConf) Key() interface{} {
|
func (fp *FilerConf_PathConf) Key() interface{} {
|
||||||
return fp.LocationPrefix
|
key, _ := proto.Marshal(fp)
|
||||||
|
return string(key)
|
||||||
}
|
}
|
||||||
|
@@ -3,11 +3,14 @@ package shell
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -32,11 +35,12 @@ func (c *commandFsConfigure) Help() string {
|
|||||||
func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
||||||
|
|
||||||
fsConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
fsConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
locationPrefix := fsConfigureCommand.String("locationPrefix", "", "path prefix")
|
locationPrefix := fsConfigureCommand.String("locationPrefix", "", "path prefix, required to update the path-specific configuration")
|
||||||
collection := fsConfigureCommand.String("collection", "", "assign writes to this colletion")
|
collection := fsConfigureCommand.String("collection", "", "assign writes to this colletion")
|
||||||
replication := fsConfigureCommand.String("replication", "", "assign writes with this replication")
|
replication := fsConfigureCommand.String("replication", "", "assign writes with this replication")
|
||||||
ttl := fsConfigureCommand.String("ttl", "", "assign writes with this ttl")
|
ttl := fsConfigureCommand.String("ttl", "", "assign writes with this ttl")
|
||||||
fsync := fsConfigureCommand.Bool("fsync", false, "fsync for the writes")
|
fsync := fsConfigureCommand.Bool("fsync", false, "fsync for the writes")
|
||||||
|
isDelete := fsConfigureCommand.Bool("delete", false, "delete the configuration by locationPrefix")
|
||||||
apply := fsConfigureCommand.Bool("apply", false, "update and apply filer configuration")
|
apply := fsConfigureCommand.Bool("apply", false, "update and apply filer configuration")
|
||||||
if err = fsConfigureCommand.Parse(args); err != nil {
|
if err = fsConfigureCommand.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -73,13 +77,36 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
|
|||||||
Ttl: *ttl,
|
Ttl: *ttl,
|
||||||
Fsync: *fsync,
|
Fsync: *fsync,
|
||||||
}
|
}
|
||||||
fc.AddLocationConf(locConf)
|
if *isDelete {
|
||||||
|
fc.DeleteLocationConf(*locationPrefix)
|
||||||
|
} else {
|
||||||
|
fc.AddLocationConf(locConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fc.ToText(writer)
|
buf.Reset()
|
||||||
|
fc.ToText(&buf)
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, string(buf.Bytes()))
|
||||||
|
|
||||||
if *apply {
|
if *apply {
|
||||||
|
|
||||||
|
target := fmt.Sprintf("http://%s:%d%s/%s", commandEnv.option.FilerHost, commandEnv.option.FilerPort, filer.DirectoryEtc, filer.FilerConfName)
|
||||||
|
|
||||||
|
// set the HTTP method, url, and request body
|
||||||
|
req, err := http.NewRequest(http.MethodPut, target, &buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the request header Content-Type for json
|
||||||
|
req.Header.Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
util.CloseResponse(resp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user