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.

46 lines
1.3 KiB

  1. package main
  2. import (
  3. "github.com/chrislusf/seaweedfs/go/glog"
  4. "github.com/chrislusf/seaweedfs/go/storage"
  5. )
  6. func init() {
  7. cmdCompact.Run = runCompact // break init cycle
  8. cmdCompact.IsDebug = cmdCompact.Flag.Bool("debug", false, "enable debug mode")
  9. }
  10. var cmdCompact = &Command{
  11. UsageLine: "compact -dir=/tmp -volumeId=234",
  12. Short: "run weed tool compact on volume file",
  13. Long: `Force an compaction to remove deleted files from volume files.
  14. The compacted .dat file is stored as .cpd file.
  15. The compacted .idx file is stored as .cpx file.
  16. `,
  17. }
  18. var (
  19. compactVolumePath = cmdCompact.Flag.String("dir", "/tmp", "data directory to store files")
  20. compactVolumeCollection = cmdCompact.Flag.String("collection", "", "volume collection name")
  21. compactVolumeId = cmdCompact.Flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir.")
  22. )
  23. func runCompact(cmd *Command, args []string) bool {
  24. if *compactVolumeId == -1 {
  25. return false
  26. }
  27. vid := storage.VolumeId(*compactVolumeId)
  28. v, err := storage.NewVolume(*compactVolumePath, *compactVolumeCollection, vid,
  29. storage.NeedleMapInMemory, nil, nil)
  30. if err != nil {
  31. glog.Fatalf("Load Volume [ERROR] %s\n", err)
  32. }
  33. if err = v.Compact(); err != nil {
  34. glog.Fatalf("Compact Volume [ERROR] %s\n", err)
  35. }
  36. return true
  37. }