You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. package weed_server
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/raft"
  6. "github.com/chrislusf/seaweedfs/weed/operation"
  7. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  8. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  9. )
  10. func (ms *MasterServer) CollectionList(ctx context.Context, req *master_pb.CollectionListRequest) (*master_pb.CollectionListResponse, error) {
  11. if !ms.Topo.IsLeader() {
  12. return nil, raft.NotLeaderError
  13. }
  14. resp := &master_pb.CollectionListResponse{}
  15. collections := ms.Topo.ListCollections()
  16. for _, c := range collections {
  17. resp.Collections = append(resp.Collections, &master_pb.Collection{
  18. Name: c.Name,
  19. })
  20. }
  21. return resp, nil
  22. }
  23. func (ms *MasterServer) CollectionDelete(ctx context.Context, req *master_pb.CollectionDeleteRequest) (*master_pb.CollectionDeleteResponse, error) {
  24. if !ms.Topo.IsLeader() {
  25. return nil, raft.NotLeaderError
  26. }
  27. resp := &master_pb.CollectionDeleteResponse{}
  28. collection, ok := ms.Topo.FindCollection(req.GetName())
  29. if !ok {
  30. return resp, fmt.Errorf("collection not found: %v", req.GetName())
  31. }
  32. for _, server := range collection.ListVolumeServers() {
  33. err := operation.WithVolumeServerClient(server.Url(), ms.grpcDialOpiton, func(client volume_server_pb.VolumeServerClient) error {
  34. _, deleteErr := client.DeleteCollection(context.Background(), &volume_server_pb.DeleteCollectionRequest{
  35. Collection: collection.Name,
  36. })
  37. return deleteErr
  38. })
  39. if err != nil {
  40. return nil, err
  41. }
  42. }
  43. ms.Topo.DeleteCollection(req.GetName())
  44. return resp, nil
  45. }