repeated_vacuum.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "math/rand"
  7. "google.golang.org/grpc"
  8. "github.com/chrislusf/seaweedfs/weed/operation"
  9. "github.com/chrislusf/seaweedfs/weed/security"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. var (
  13. master = flag.String("master", "127.0.0.1:9333", "the master server")
  14. repeat = flag.Int("n", 5, "repeat how many times")
  15. garbageThreshold = flag.Float64("garbageThreshold", 0.3, "garbageThreshold")
  16. )
  17. func main() {
  18. flag.Parse()
  19. util.LoadConfiguration("security", false)
  20. grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
  21. genFile(grpcDialOption, 0)
  22. for i := 0; i < *repeat; i++ {
  23. // create 2 files, and delete one of them
  24. assignResult, targetUrl := genFile(grpcDialOption, i)
  25. util.Delete(targetUrl, string(assignResult.Auth))
  26. println("vacuum", i, "threshold", *garbageThreshold)
  27. util.Get(fmt.Sprintf("http://%s/vol/vacuum?garbageThreshold=%f", *master, *garbageThreshold))
  28. }
  29. }
  30. func genFile(grpcDialOption grpc.DialOption, i int) (*operation.AssignResult, string) {
  31. assignResult, err := operation.Assign(*master, grpcDialOption, &operation.VolumeAssignRequest{Count: 1})
  32. if err != nil {
  33. log.Fatalf("assign: %v", err)
  34. }
  35. data := make([]byte, 1024)
  36. rand.Read(data)
  37. targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
  38. _, err = operation.UploadData(targetUrl, fmt.Sprintf("test%d", i), false, data, false, "bench/test", nil, assignResult.Auth)
  39. if err != nil {
  40. log.Fatalf("upload: %v", err)
  41. }
  42. return assignResult, targetUrl
  43. }