Skip to content

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.

add shell command to list all collections

Chris Lu657dd2e6c93c
diff --git a/weed/command/shell.go b/weed/command/shell.go
index 19c5049c50..1c3ce5f106 100644
--- a/weed/command/shell.go
+++ b/weed/command/shell.go
@@ -1,21 +1,25 @@
package command
import (
- "bufio"
- "fmt"
- "os"
+ "github.com/chrislusf/seaweedfs/weed/security"
+ "github.com/chrislusf/seaweedfs/weed/server"
+ "github.com/chrislusf/seaweedfs/weed/shell"
+ "github.com/spf13/viper"
+)
- "github.com/chrislusf/seaweedfs/weed/glog"
+var (
+ shellOptions shell.ShellOptions
)
func init() {
cmdShell.Run = runShell // break init cycle
+ shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
}
var cmdShell = &Command{
UsageLine: "shell",
- Short: "run interactive commands, now just echo",
- Long: `run interactive commands.
+ Short: "run interactive administrative commands",
+ Long: `run interactive administrative commands.
`,
}
@@ -23,39 +27,12 @@ var cmdShell = &Command{
var ()
func runShell(command *Command, args []string) bool {
- r := bufio.NewReader(os.Stdin)
- o := bufio.NewWriter(os.Stdout)
- e := bufio.NewWriter(os.Stderr)
- prompt := func() {
- var err error
- if _, err = o.WriteString("> "); err != nil {
- glog.V(0).Infoln("error writing to stdout:", err)
- }
- if err = o.Flush(); err != nil {
- glog.V(0).Infoln("error flushing stdout:", err)
- }
- }
- readLine := func() string {
- ret, err := r.ReadString('\n')
- if err != nil {
- fmt.Fprint(e, err)
- os.Exit(1)
- }
- return ret
- }
- execCmd := func(cmd string) int {
- if cmd != "" {
- if _, err := o.WriteString(cmd); err != nil {
- glog.V(0).Infoln("error writing to stdout:", err)
- }
- }
- return 0
- }
-
- cmd := ""
- for {
- prompt()
- cmd = readLine()
- execCmd(cmd)
- }
+
+ weed_server.LoadConfiguration("security", false)
+ shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
+
+ shell.RunShell(shellOptions)
+
+ return true
+
}
diff --git a/weed/pb/master.proto b/weed/pb/master.proto
index f03d1e3de0..d4b02cdc50 100644
--- a/weed/pb/master.proto
+++ b/weed/pb/master.proto
@@ -15,6 +15,10 @@ service Seaweed {
}
rpc Statistics (StatisticsRequest) returns (StatisticsResponse) {
}
+ rpc CollectionList (CollectionListRequest) returns (CollectionListResponse) {
+ }
+ rpc CollectionDelete (CollectionDeleteRequest) returns (CollectionDeleteResponse) {
+ }
}
//////////////////////////////////////////////////
@@ -124,3 +128,26 @@ message StatisticsResponse {
uint64 used_size = 5;
uint64 file_count = 6;
}
+
+//
+// collection related
+//
+
+message StorageType {
+ string replication = 1;
+ string ttl = 2;
+}
+message Collection {
+ string name = 1;
+}
+message CollectionListRequest {
+}
+message CollectionListResponse {
+ repeated Collection collections = 1;
+}
+
+message CollectionDeleteRequest {
+ string name = 1;
+}
+message CollectionDeleteResponse {
+}
diff --git a/weed/pb/master_pb/master.pb.go b/weed/pb/master_pb/master.pb.go
index 0c73ff2c89..a046a887b7 100644
--- a/weed/pb/master_pb/master.pb.go
+++ b/weed/pb/master_pb/master.pb.go
@@ -23,6 +23,11 @@ It has these top-level messages:
AssignResponse
StatisticsRequest
StatisticsResponse
+ Collection
+ CollectionListRequest
+ CollectionListResponse
+ CollectionDeleteRequest
+ CollectionDeleteResponse
*/
package master_pb
@@ -675,6 +680,102 @@ func (m *StatisticsResponse) GetFileCount() uint64 {
return 0
}
+type Collection struct {
+ Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
+ Replication string `protobuf:"bytes,2,opt,name=replication" json:"replication,omitempty"`
+ Ttl string `protobuf:"bytes,3,opt,name=ttl" json:"ttl,omitempty"`
+}
+
+func (m *Collection) Reset() { *m = Collection{} }
+func (m *Collection) String() string { return proto.CompactTextString(m) }
+func (*Collection) ProtoMessage() {}
+func (*Collection) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} }
+
+func (m *Collection) GetName() string {
+ if m != nil {
+ return m.Name
+ }
+ return ""
+}
+
+func (m *Collection) GetReplication() string {
+ if m != nil {
+ return m.Replication
+ }
+ return ""
+}
+
+func (m *Collection) GetTtl() string {
+ if m != nil {
+ return m.Ttl
+ }
+ return ""
+}
+
+type CollectionListRequest struct {
+ Replication string `protobuf:"bytes,1,opt,name=replication" json:"replication,omitempty"`
+ Ttl string `protobuf:"bytes,2,opt,name=ttl" json:"ttl,omitempty"`
+}
+
+func (m *CollectionListRequest) Reset() { *m = CollectionListRequest{} }
+func (m *CollectionListRequest) String() string { return proto.CompactTextString(m) }
+func (*CollectionListRequest) ProtoMessage() {}
+func (*CollectionListRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} }
+
+func (m *CollectionListRequest) GetReplication() string {
+ if m != nil {
+ return m.Replication
+ }
+ return ""
+}
+
+func (m *CollectionListRequest) GetTtl() string {
+ if m != nil {
+ return m.Ttl
+ }
+ return ""
+}
+
+type CollectionListResponse struct {
+ Collections []*Collection `protobuf:"bytes,1,rep,name=collections" json:"collections,omitempty"`
+}
+
+func (m *CollectionListResponse) Reset() { *m = CollectionListResponse{} }
+func (m *CollectionListResponse) String() string { return proto.CompactTextString(m) }
+func (*CollectionListResponse) ProtoMessage() {}
+func (*CollectionListResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} }
+
+func (m *CollectionListResponse) GetCollections() []*Collection {
+ if m != nil {
+ return m.Collections
+ }
+ return nil
+}
+
+type CollectionDeleteRequest struct {
+ Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
+}
+
+func (m *CollectionDeleteRequest) Reset() { *m = CollectionDeleteRequest{} }
+func (m *CollectionDeleteRequest) String() string { return proto.CompactTextString(m) }
+func (*CollectionDeleteRequest) ProtoMessage() {}
+func (*CollectionDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} }
+
+func (m *CollectionDeleteRequest) GetName() string {
+ if m != nil {
+ return m.Name
+ }
+ return ""
+}
+
+type CollectionDeleteResponse struct {
+}
+
+func (m *CollectionDeleteResponse) Reset() { *m = CollectionDeleteResponse{} }
+func (m *CollectionDeleteResponse) String() string { return proto.CompactTextString(m) }
+func (*CollectionDeleteResponse) ProtoMessage() {}
+func (*CollectionDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18} }
+
func init() {
proto.RegisterType((*Heartbeat)(nil), "master_pb.Heartbeat")
proto.RegisterType((*HeartbeatResponse)(nil), "master_pb.HeartbeatResponse")
@@ -692,6 +793,11 @@ func init() {
proto.RegisterType((*AssignResponse)(nil), "master_pb.AssignResponse")
proto.RegisterType((*StatisticsRequest)(nil), "master_pb.StatisticsRequest")
proto.RegisterType((*StatisticsResponse)(nil), "master_pb.StatisticsResponse")
+ proto.RegisterType((*Collection)(nil), "master_pb.Collection")
+ proto.RegisterType((*CollectionListRequest)(nil), "master_pb.CollectionListRequest")
+ proto.RegisterType((*CollectionListResponse)(nil), "master_pb.CollectionListResponse")
+ proto.RegisterType((*CollectionDeleteRequest)(nil), "master_pb.CollectionDeleteRequest")
+ proto.RegisterType((*CollectionDeleteResponse)(nil), "master_pb.CollectionDeleteResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -710,6 +816,8 @@ type SeaweedClient interface {
LookupVolume(ctx context.Context, in *LookupVolumeRequest, opts ...grpc.CallOption) (*LookupVolumeResponse, error)
Assign(ctx context.Context, in *AssignRequest, opts ...grpc.CallOption) (*AssignResponse, error)
Statistics(ctx context.Context, in *StatisticsRequest, opts ...grpc.CallOption) (*StatisticsResponse, error)
+ CollectionList(ctx context.Context, in *CollectionListRequest, opts ...grpc.CallOption) (*CollectionListResponse, error)
+ CollectionDelete(ctx context.Context, in *CollectionDeleteRequest, opts ...grpc.CallOption) (*CollectionDeleteResponse, error)
}
type seaweedClient struct {
@@ -809,6 +917,24 @@ func (c *seaweedClient) Statistics(ctx context.Context, in *StatisticsRequest, o
return out, nil
}
+func (c *seaweedClient) CollectionList(ctx context.Context, in *CollectionListRequest, opts ...grpc.CallOption) (*CollectionListResponse, error) {
+ out := new(CollectionListResponse)
+ err := grpc.Invoke(ctx, "/master_pb.Seaweed/CollectionList", in, out, c.cc, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *seaweedClient) CollectionDelete(ctx context.Context, in *CollectionDeleteRequest, opts ...grpc.CallOption) (*CollectionDeleteResponse, error) {
+ out := new(CollectionDeleteResponse)
+ err := grpc.Invoke(ctx, "/master_pb.Seaweed/CollectionDelete", in, out, c.cc, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
// Server API for Seaweed service
type SeaweedServer interface {
@@ -817,6 +943,8 @@ type SeaweedServer interface {
LookupVolume(context.Context, *LookupVolumeRequest) (*LookupVolumeResponse, error)
Assign(context.Context, *AssignRequest) (*AssignResponse, error)
Statistics(context.Context, *StatisticsRequest) (*StatisticsResponse, error)
+ CollectionList(context.Context, *CollectionListRequest) (*CollectionListResponse, error)
+ CollectionDelete(context.Context, *CollectionDeleteRequest) (*CollectionDeleteResponse, error)
}
func RegisterSeaweedServer(s *grpc.Server, srv SeaweedServer) {
@@ -929,6 +1057,42 @@ func _Seaweed_Statistics_Handler(srv interface{}, ctx context.Context, dec func(
return interceptor(ctx, in, info, handler)
}
+func _Seaweed_CollectionList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(CollectionListRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(SeaweedServer).CollectionList(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/master_pb.Seaweed/CollectionList",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(SeaweedServer).CollectionList(ctx, req.(*CollectionListRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+func _Seaweed_CollectionDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(CollectionDeleteRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(SeaweedServer).CollectionDelete(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/master_pb.Seaweed/CollectionDelete",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(SeaweedServer).CollectionDelete(ctx, req.(*CollectionDeleteRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
var _Seaweed_serviceDesc = grpc.ServiceDesc{
ServiceName: "master_pb.Seaweed",
HandlerType: (*SeaweedServer)(nil),
@@ -945,6 +1109,14 @@ var _Seaweed_serviceDesc = grpc.ServiceDesc{
MethodName: "Statistics",
Handler: _Seaweed_Statistics_Handler,
},
+ {
+ MethodName: "CollectionList",
+ Handler: _Seaweed_CollectionList_Handler,
+ },
+ {
+ MethodName: "CollectionDelete",
+ Handler: _Seaweed_CollectionDelete_Handler,
+ },
},
Streams: []grpc.StreamDesc{
{
@@ -966,71 +1138,78 @@ var _Seaweed_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("master.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
- // 1056 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xe4, 0x44,
- 0x10, 0x8e, 0x3d, 0xbf, 0xae, 0xc9, 0x64, 0x27, 0x9d, 0x08, 0x79, 0x67, 0xd9, 0xdd, 0xc1, 0x5c,
- 0x06, 0x81, 0xa2, 0x25, 0x1c, 0x11, 0x42, 0x6c, 0x14, 0x44, 0x94, 0xc0, 0x06, 0x87, 0xdd, 0x03,
- 0x17, 0xd3, 0xb1, 0x2b, 0xa1, 0x15, 0xff, 0xe1, 0x6e, 0x27, 0x33, 0x7b, 0xe1, 0xc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x00,
}
diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.go
index 4234af5f5d..13c66543b9 100644
--- a/weed/server/filer_grpc_server.go
+++ b/weed/server/filer_grpc_server.go
@@ -14,7 +14,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
- "github.com/chrislusf/seaweedfs/weed/util"
)
func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
@@ -239,9 +238,7 @@ func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVol
func (fs *FilerServer) DeleteCollection(ctx context.Context, req *filer_pb.DeleteCollectionRequest) (resp *filer_pb.DeleteCollectionResponse, err error) {
- for _, master := range fs.option.Masters {
- _, err = util.Get(fmt.Sprintf("http://%s/col/delete?collection=%s", master, req.Collection))
- }
+ err = fs.filer.MasterClient.CollectionDelete(ctx, req.GetCollection())
return &filer_pb.DeleteCollectionResponse{}, err
}
diff --git a/weed/server/master_grpc_server_collection.go b/weed/server/master_grpc_server_collection.go
new file mode 100644
index 0000000000..23188d8565
--- /dev/null
+++ b/weed/server/master_grpc_server_collection.go
@@ -0,0 +1,56 @@
+package weed_server
+
+import (
+ "context"
+ "fmt"
+ "github.com/chrislusf/raft"
+ "github.com/chrislusf/seaweedfs/weed/operation"
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
+)
+
+func (ms *MasterServer) CollectionList(ctx context.Context, req *master_pb.CollectionListRequest) (*master_pb.CollectionListResponse, error) {
+
+ if !ms.Topo.IsLeader() {
+ return nil, raft.NotLeaderError
+ }
+
+ resp := &master_pb.CollectionListResponse{}
+ collections := ms.Topo.ListCollections()
+ for _, c := range collections {
+ resp.Collections = append(resp.Collections, &master_pb.Collection{
+ Name: c.Name,
+ })
+ }
+
+ return resp, nil
+}
+
+func (ms *MasterServer) CollectionDelete(ctx context.Context, req *master_pb.CollectionDeleteRequest) (*master_pb.CollectionDeleteResponse, error) {
+
+ if !ms.Topo.IsLeader() {
+ return nil, raft.NotLeaderError
+ }
+
+ resp := &master_pb.CollectionDeleteResponse{}
+
+ collection, ok := ms.Topo.FindCollection(req.GetName())
+ if !ok {
+ return resp, fmt.Errorf("collection not found: %v", req.GetName())
+ }
+
+ for _, server := range collection.ListVolumeServers() {
+ err := operation.WithVolumeServerClient(server.Url(), ms.grpcDialOpiton, func(client volume_server_pb.VolumeServerClient) error {
+ _, deleteErr := client.DeleteCollection(context.Background(), &volume_server_pb.DeleteCollectionRequest{
+ Collection: collection.Name,
+ })
+ return deleteErr
+ })
+ if err != nil {
+ return nil, err
+ }
+ }
+ ms.Topo.DeleteCollection(req.GetName())
+
+ return resp, nil
+}
diff --git a/weed/shell/command_collection_list.go b/weed/shell/command_collection_list.go
new file mode 100644
index 0000000000..aab347d09e
--- /dev/null
+++ b/weed/shell/command_collection_list.go
@@ -0,0 +1,39 @@
+package shell
+
+import (
+ "context"
+ "fmt"
+ "io"
+)
+
+func init() {
+ commands = append(commands, &commandCollectionList{})
+}
+
+type commandCollectionList struct {
+}
+
+func (c *commandCollectionList) Name() string {
+ return "collection.list"
+}
+
+func (c *commandCollectionList) Help() string {
+ return "\t\t # list all collections"
+}
+
+func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error {
+
+ resp, err := commandEnv.masterClient.CollectionList(context.Background())
+
+ if err != nil {
+ return err
+ }
+
+ for _, c := range resp.Collections {
+ fmt.Fprintf(writer, "collection:\"%s\"\n", c.GetName())
+ }
+
+ fmt.Fprintf(writer, "Total %d collections.\n", len(resp.Collections))
+
+ return nil
+}
diff --git a/weed/shell/commands.go b/weed/shell/commands.go
new file mode 100644
index 0000000000..4df70ff555
--- /dev/null
+++ b/weed/shell/commands.go
@@ -0,0 +1,27 @@
+package shell
+
+import (
+ "github.com/chrislusf/seaweedfs/weed/wdclient"
+ "google.golang.org/grpc"
+ "io"
+)
+
+type ShellOptions struct {
+ Masters *string
+ GrpcDialOption grpc.DialOption
+}
+
+type commandEnv struct {
+ env map[string]string
+ masterClient *wdclient.MasterClient
+}
+
+type command interface {
+ Name() string
+ Help() string
+ Do([]string, *commandEnv, io.Writer) error
+}
+
+var (
+ commands = []command{}
+)
diff --git a/weed/shell/shell_liner.go b/weed/shell/shell_liner.go
new file mode 100644
index 0000000000..e862201340
--- /dev/null
+++ b/weed/shell/shell_liner.go
@@ -0,0 +1,143 @@
+package shell
+
+import (
+ "context"
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/wdclient"
+ "os"
+ "regexp"
+ "strings"
+
+ "github.com/peterh/liner"
+ "sort"
+)
+
+var (
+ line *liner.State
+ historyPath = "/tmp/weed-shell"
+)
+
+func RunShell(options ShellOptions) {
+
+ line = liner.NewLiner()
+ defer line.Close()
+
+ line.SetCtrlCAborts(true)
+
+ setCompletionHandler()
+ loadHisotry()
+
+ defer saveHisotry()
+
+ reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`)
+
+ commandEnv := &commandEnv{
+ env: make(map[string]string),
+ masterClient: wdclient.NewMasterClient(context.Background(),
+ options.GrpcDialOption, "shell", strings.Split(*options.Masters, ",")),
+ }
+
+ go commandEnv.masterClient.KeepConnectedToMaster()
+ commandEnv.masterClient.WaitUntilConnected()
+
+ for {
+ cmd, err := line.Prompt("> ")
+ if err != nil {
+ fmt.Printf("%v\n", err)
+ return
+ }
+
+ cmds := reg.FindAllString(cmd, -1)
+ if len(cmds) == 0 {
+ continue
+ } else {
+ line.AppendHistory(cmd)
+
+ args := make([]string, len(cmds[1:]))
+
+ for i := range args {
+ args[i] = strings.Trim(string(cmds[1+i]), "\"'")
+ }
+
+ cmd := strings.ToLower(cmds[0])
+ if cmd == "help" || cmd == "?" {
+ printHelp(cmds)
+ } else if cmd == "exit" || cmd == "quit" {
+ return
+ } else {
+ for _, c := range commands {
+ if c.Name() == cmd {
+ if err := c.Do(args, commandEnv, os.Stderr); err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
+ }
+ }
+ }
+ }
+
+ }
+ }
+}
+
+func printGenericHelp() {
+ msg :=
+ `Type: "help <command>" for help on <command>
+`
+ fmt.Print(msg)
+
+ sort.Slice(commands, func(i, j int) bool {
+ return strings.Compare(commands[i].Name(), commands[j].Name()) < 0
+ })
+ for _, c := range commands {
+ fmt.Printf("\t%s %s \n", c.Name(), c.Help())
+ }
+}
+
+func printHelp(cmds []string) {
+ args := cmds[1:]
+ if len(args) == 0 {
+ printGenericHelp()
+ } else if len(args) > 1 {
+ fmt.Println()
+ } else {
+ cmd := strings.ToLower(args[0])
+
+ sort.Slice(commands, func(i, j int) bool {
+ return strings.Compare(commands[i].Name(), commands[j].Name()) < 0
+ })
+
+ for _, c := range commands {
+ if c.Name() == cmd {
+ fmt.Println()
+ fmt.Printf("\t%s %s \n", c.Name(), c.Help())
+ fmt.Println()
+ }
+ }
+ }
+}
+
+func setCompletionHandler() {
+ line.SetCompleter(func(line string) (c []string) {
+ for _, i := range commands {
+ if strings.HasPrefix(i.Name(), strings.ToLower(line)) {
+ c = append(c, i.Name())
+ }
+ }
+ return
+ })
+}
+
+func loadHisotry() {
+ if f, err := os.Open(historyPath); err == nil {
+ line.ReadHistory(f)
+ f.Close()
+ }
+}
+
+func saveHisotry() {
+ if f, err := os.Create(historyPath); err != nil {
+ fmt.Printf("Error writing history file: %v\n", err)
+ } else {
+ line.WriteHistory(f)
+ f.Close()
+ }
+}
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index 77716605a1..208c9b5b73 100644
--- a/weed/topology/topology.go
+++ b/weed/topology/topology.go
@@ -117,6 +117,13 @@ func (t *Topology) GetVolumeLayout(collectionName string, rp *storage.ReplicaPla
}).(*Collection).GetOrCreateVolumeLayout(rp, ttl)
}
+func (t *Topology) ListCollections() (ret []*Collection) {
+ for _, c := range t.collectionMap.Items() {
+ ret = append(ret, c.(*Collection))
+ }
+ return ret
+}
+
func (t *Topology) FindCollection(collectionName string) (*Collection, bool) {
c, hasCollection := t.collectionMap.Find(collectionName)
if !hasCollection {
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 1686ad5ffb..b3b277c740 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -43,7 +43,7 @@ func (mc *MasterClient) WaitUntilConnected() {
}
func (mc *MasterClient) KeepConnectedToMaster() {
- glog.V(0).Infof("%s bootstraps with masters %v", mc.name, mc.masters)
+ glog.V(1).Infof("%s bootstraps with masters %v", mc.name, mc.masters)
for {
mc.tryAllMasters()
time.Sleep(time.Second)
@@ -52,7 +52,7 @@ func (mc *MasterClient) KeepConnectedToMaster() {
func (mc *MasterClient) tryAllMasters() {
for _, master := range mc.masters {
- glog.V(0).Infof("Connecting to master %v", master)
+ glog.V(1).Infof("Connecting to master %v", master)
gprcErr := withMasterClient(context.Background(), master, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error {
stream, err := client.KeepConnected(ctx)
@@ -67,7 +67,7 @@ func (mc *MasterClient) tryAllMasters() {
}
if mc.currentMaster == "" {
- glog.V(0).Infof("Connected to %v", master)
+ glog.V(1).Infof("Connected to %v", master)
mc.currentMaster = master
}
diff --git a/weed/wdclient/masterclient_collection.go b/weed/wdclient/masterclient_collection.go
new file mode 100644
index 0000000000..bdf791da01
--- /dev/null
+++ b/weed/wdclient/masterclient_collection.go
@@ -0,0 +1,23 @@
+package wdclient
+
+import (
+ "context"
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+)
+
+func (mc *MasterClient) CollectionDelete(ctx context.Context, collection string) error {
+ return withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error {
+ _, err := client.CollectionDelete(ctx, &master_pb.CollectionDeleteRequest{
+ Name: collection,
+ })
+ return err
+ })
+}
+
+func (mc *MasterClient) CollectionList(ctx context.Context) (resp *master_pb.CollectionListResponse, err error) {
+ err = withMasterClient(ctx, mc.currentMaster, mc.grpcDialOption, func(ctx context.Context, client master_pb.SeaweedClient) error {
+ resp, err = client.CollectionList(ctx, &master_pb.CollectionListRequest{})
+ return err
+ })
+ return
+}