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.

45 lines
1.2 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. }
  9. var cmdCompact = &Command{
  10. UsageLine: "compact -dir=/tmp -volumeId=234",
  11. Short: "run weed tool compact on volume file",
  12. Long: `Force an compaction to remove deleted files from volume files.
  13. The compacted .dat file is stored as .cpd file.
  14. The compacted .idx file is stored as .cpx file.
  15. `,
  16. }
  17. var (
  18. compactVolumePath = cmdCompact.Flag.String("dir", ".", "data directory to store files")
  19. compactVolumeCollection = cmdCompact.Flag.String("collection", "", "volume collection name")
  20. compactVolumeId = cmdCompact.Flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir.")
  21. )
  22. func runCompact(cmd *Command, args []string) bool {
  23. if *compactVolumeId == -1 {
  24. return false
  25. }
  26. vid := storage.VolumeId(*compactVolumeId)
  27. v, err := storage.NewVolume(*compactVolumePath, *compactVolumeCollection, vid,
  28. storage.NeedleMapInMemory, nil, nil)
  29. if err != nil {
  30. glog.Fatalf("Load Volume [ERROR] %s\n", err)
  31. }
  32. if err = v.Compact(); err != nil {
  33. glog.Fatalf("Compact Volume [ERROR] %s\n", err)
  34. }
  35. return true
  36. }