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.

57 lines
1.4 KiB

3 years ago
3 years ago
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "io"
  6. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  7. )
  8. func init() {
  9. Commands = append(Commands, &commandVacuum{})
  10. }
  11. type commandVacuum struct {
  12. }
  13. func (c *commandVacuum) Name() string {
  14. return "volume.vacuum"
  15. }
  16. func (c *commandVacuum) Help() string {
  17. return `compact volumes if deleted entries are more than the limit
  18. volume.vacuum [-garbageThreshold=0.3] [-collection=<collection name>] [-volumeId=<volume id>]
  19. `
  20. }
  21. func (c *commandVacuum) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. volumeVacuumCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  23. garbageThreshold := volumeVacuumCommand.Float64("garbageThreshold", 0.3, "vacuum when garbage is more than this limit")
  24. collection := volumeVacuumCommand.String("collection", "", "vacuum this collection")
  25. volumeId := volumeVacuumCommand.Uint("volumeId", 0, "the volume id")
  26. if err = volumeVacuumCommand.Parse(args); err != nil {
  27. return
  28. }
  29. if err = commandEnv.confirmIsLocked(args); err != nil {
  30. return
  31. }
  32. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  33. _, err = client.VacuumVolume(context.Background(), &master_pb.VacuumVolumeRequest{
  34. GarbageThreshold: float32(*garbageThreshold),
  35. VolumeId: uint32(*volumeId),
  36. Collection: *collection,
  37. })
  38. return err
  39. })
  40. if err != nil {
  41. return
  42. }
  43. return nil
  44. }