mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-21 06:57:51 +08:00
2e78a522ab
* remove old raft servers if they don't answer to pings for too long add ping durations as options rename ping fields fix some todos get masters through masterclient raft remove server from leader use raft servers to ping them CheckMastersAlive for hashicorp raft only * prepare blocking ping * pass waitForReady as param * pass waitForReady through all functions * waitForReady works * refactor * remove unneeded params * rollback unneeded changes * fix
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandCollectionDelete{})
|
|
}
|
|
|
|
type commandCollectionDelete struct {
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Name() string {
|
|
return "collection.delete"
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Help() string {
|
|
return `delete specified collection
|
|
|
|
collection.delete -collection <collection_name> -force
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
colDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
collectionName := colDeleteCommand.String("collection", "", "collection to delete. Use '_default_' for the empty-named collection.")
|
|
applyBalancing := colDeleteCommand.Bool("force", false, "apply the collection")
|
|
if err = colDeleteCommand.Parse(args); err != nil {
|
|
return nil
|
|
}
|
|
infoAboutSimulationMode(writer, *applyBalancing, "-force")
|
|
|
|
if err = commandEnv.confirmIsLocked(args); err != nil {
|
|
return
|
|
}
|
|
|
|
if *collectionName == "" {
|
|
return fmt.Errorf("empty collection name is not allowed")
|
|
}
|
|
|
|
if *collectionName == "_default_" {
|
|
*collectionName = ""
|
|
}
|
|
|
|
if !*applyBalancing {
|
|
fmt.Fprintf(writer, "collection '%s' will be deleted. Use -force to apply the change.\n", *collectionName)
|
|
return nil
|
|
}
|
|
|
|
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
|
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
|
Name: *collectionName,
|
|
})
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
fmt.Fprintf(writer, "collection %s is deleted.\n", *collectionName)
|
|
|
|
return nil
|
|
}
|