command_volume_vacuum.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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]
  19. `
  20. }
  21. func (c *commandVacuum) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. if err = commandEnv.confirmIsLocked(); err != nil {
  23. return
  24. }
  25. volumeVacuumCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  26. garbageThreshold := volumeVacuumCommand.Float64("garbageThreshold", 0.3, "vacuum when garbage is more than this limit")
  27. if err = volumeVacuumCommand.Parse(args); err != nil {
  28. return nil
  29. }
  30. err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
  31. _, err = client.VacuumVolume(context.Background(), &master_pb.VacuumVolumeRequest{
  32. GarbageThreshold: float32(*garbageThreshold),
  33. })
  34. return err
  35. })
  36. if err != nil {
  37. return
  38. }
  39. return nil
  40. }