repeated_vacuum.go 1.8 KB

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