add shell command to list all collections

This commit is contained in:
Chris Lu
2019-03-16 13:43:16 -07:00
parent b92122b885
commit 657dd2e6c9
11 changed files with 589 additions and 114 deletions

View File

@@ -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
}

View File

@@ -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
}