2019-03-16 20:43:16 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-05-30 17:40:22 +00:00
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
"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{}
|
2019-05-30 16:27:23 +00:00
|
|
|
collections := ms.Topo.ListCollections(req.IncludeNormalVolumes, req.IncludeEcVolumes)
|
2019-03-16 20:43:16 +00:00
|
|
|
for _, c := range collections {
|
|
|
|
resp.Collections = append(resp.Collections, &master_pb.Collection{
|
2019-05-30 16:17:58 +00:00
|
|
|
Name: c,
|
2019-03-16 20:43:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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{}
|
|
|
|
|
2019-05-30 17:40:22 +00:00
|
|
|
err := ms.doDeleteNormalCollection(req.Name)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ms.doDeleteEcCollection(req.Name)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MasterServer) doDeleteNormalCollection(collectionName string) error {
|
|
|
|
|
|
|
|
collection, ok := ms.Topo.FindCollection(collectionName)
|
2019-03-16 20:43:16 +00:00
|
|
|
if !ok {
|
2019-05-30 17:40:22 +00:00
|
|
|
return nil
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, server := range collection.ListVolumeServers() {
|
2020-01-26 22:42:11 +00:00
|
|
|
err := operation.WithVolumeServerClient(server.Url(), ms.grpcDialOption, func(ctx context.Context, client volume_server_pb.VolumeServerClient) error {
|
|
|
|
_, deleteErr := client.DeleteCollection(ctx, &volume_server_pb.DeleteCollectionRequest{
|
2019-05-30 17:40:22 +00:00
|
|
|
Collection: collectionName,
|
2019-03-16 20:43:16 +00:00
|
|
|
})
|
|
|
|
return deleteErr
|
|
|
|
})
|
|
|
|
if err != nil {
|
2019-05-30 17:40:22 +00:00
|
|
|
return err
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-30 17:40:22 +00:00
|
|
|
ms.Topo.DeleteCollection(collectionName)
|
2019-03-16 20:43:16 +00:00
|
|
|
|
2019-05-30 17:40:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MasterServer) doDeleteEcCollection(collectionName string) error {
|
|
|
|
|
|
|
|
listOfEcServers := ms.Topo.ListEcServersByCollection(collectionName)
|
|
|
|
|
|
|
|
for _, server := range listOfEcServers {
|
2020-01-26 22:42:11 +00:00
|
|
|
err := operation.WithVolumeServerClient(server, ms.grpcDialOption, func(ctx context.Context, client volume_server_pb.VolumeServerClient) error {
|
|
|
|
_, deleteErr := client.DeleteCollection(ctx, &volume_server_pb.DeleteCollectionRequest{
|
2019-05-30 17:40:22 +00:00
|
|
|
Collection: collectionName,
|
|
|
|
})
|
|
|
|
return deleteErr
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ms.Topo.DeleteEcCollection(collectionName)
|
|
|
|
|
|
|
|
return nil
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|