seaweedfs/unmaintained/repeated_vacuum/repeated_vacuum.go

74 lines
1.8 KiB
Go
Raw Normal View History

2018-11-04 13:32:36 +08:00
package main
import (
"flag"
"fmt"
"log"
"math/rand"
2020-03-14 05:25:56 +08:00
"time"
2018-11-04 13:32:36 +08:00
2020-03-10 11:45:28 +08:00
"google.golang.org/grpc"
2018-11-04 13:32:36 +08:00
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/security"
2018-11-04 13:32:36 +08:00
"github.com/chrislusf/seaweedfs/weed/util"
)
var (
2020-03-10 11:45:28 +08:00
master = flag.String("master", "127.0.0.1:9333", "the master server")
repeat = flag.Int("n", 5, "repeat how many times")
garbageThreshold = flag.Float64("garbageThreshold", 0.3, "garbageThreshold")
2020-03-14 05:25:56 +08:00
replication = flag.String("replication", "", "replication 000, 001, 002, etc")
2018-11-04 13:32:36 +08:00
)
func main() {
flag.Parse()
util.LoadConfiguration("security", false)
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
2019-02-19 04:11:52 +08:00
2020-03-10 11:45:28 +08:00
genFile(grpcDialOption, 0)
2020-03-14 05:25:56 +08:00
go func() {
for {
println("vacuum threshold", *garbageThreshold)
_, err := util.Get(fmt.Sprintf("http://%s/vol/vacuum?garbageThreshold=%f", *master, *garbageThreshold))
if err != nil {
log.Fatalf("vacuum: %v", err)
}
time.Sleep(time.Second)
}
}()
2018-11-04 13:32:36 +08:00
for i := 0; i < *repeat; i++ {
2020-03-10 11:45:28 +08:00
// create 2 files, and delete one of them
2018-11-04 13:32:36 +08:00
2020-03-10 11:45:28 +08:00
assignResult, targetUrl := genFile(grpcDialOption, i)
2018-11-04 13:32:36 +08:00
2020-03-10 11:45:28 +08:00
util.Delete(targetUrl, string(assignResult.Auth))
2018-11-04 13:32:36 +08:00
2020-03-10 11:45:28 +08:00
}
2018-11-04 14:14:05 +08:00
2020-03-10 11:45:28 +08:00
}
2018-11-04 13:32:36 +08:00
2020-03-10 11:45:28 +08:00
func genFile(grpcDialOption grpc.DialOption, i int) (*operation.AssignResult, string) {
2020-03-14 05:25:56 +08:00
assignResult, err := operation.Assign(*master, grpcDialOption, &operation.VolumeAssignRequest{
Count: 1,
Replication: *replication,
})
2020-03-10 11:45:28 +08:00
if err != nil {
log.Fatalf("assign: %v", err)
2018-11-04 13:32:36 +08:00
}
2020-03-10 11:45:28 +08:00
data := make([]byte, 1024)
rand.Read(data)
targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
_, err = operation.UploadData(targetUrl, fmt.Sprintf("test%d", i), false, data, false, "bench/test", nil, assignResult.Auth)
if err != nil {
log.Fatalf("upload: %v", err)
}
return assignResult, targetUrl
2018-11-04 13:32:36 +08:00
}