2018-11-04 05:32:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
2018-11-04 05:32:36 +00:00
|
|
|
"log"
|
|
|
|
"math/rand"
|
2020-03-13 21:25:56 +00:00
|
|
|
"time"
|
2018-11-04 05:32:36 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2018-11-04 05:32:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-03-10 03:45:28 +00: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-13 21:25:56 +00:00
|
|
|
replication = flag.String("replication", "", "replication 000, 001, 002, etc")
|
2018-11-04 05:32:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
util.LoadConfiguration("security", false)
|
2020-01-29 17:09:55 +00:00
|
|
|
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
|
2019-02-18 20:11:52 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
genFile(grpcDialOption, 0)
|
|
|
|
|
2020-03-13 21:25:56 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
println("vacuum threshold", *garbageThreshold)
|
2021-09-13 05:47:52 +00:00
|
|
|
_, _, err := util.Get(fmt.Sprintf("http://%s/vol/vacuum?garbageThreshold=%f", pb.ServerAddress(*master).ToHttpAddress(), *garbageThreshold))
|
2020-03-13 21:25:56 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("vacuum: %v", err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-11-04 05:32:36 +00:00
|
|
|
for i := 0; i < *repeat; i++ {
|
2020-03-10 03:45:28 +00:00
|
|
|
// create 2 files, and delete one of them
|
2018-11-04 05:32:36 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
assignResult, targetUrl := genFile(grpcDialOption, i)
|
2018-11-04 05:32:36 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
util.Delete(targetUrl, string(assignResult.Auth))
|
2018-11-04 05:32:36 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
}
|
2018-11-04 06:14:05 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
}
|
2018-11-04 05:32:36 +00:00
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
func genFile(grpcDialOption grpc.DialOption, i int) (*operation.AssignResult, string) {
|
2021-09-13 05:47:52 +00:00
|
|
|
assignResult, err := operation.Assign(func() pb.ServerAddress { return pb.ServerAddress(*master) }, grpcDialOption, &operation.VolumeAssignRequest{
|
2020-03-13 21:25:56 +00:00
|
|
|
Count: 1,
|
|
|
|
Replication: *replication,
|
|
|
|
})
|
2020-03-10 03:45:28 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("assign: %v", err)
|
2018-11-04 05:32:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 03:45:28 +00:00
|
|
|
data := make([]byte, 1024)
|
|
|
|
rand.Read(data)
|
|
|
|
|
|
|
|
targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
|
|
|
|
|
2021-09-06 23:20:49 +00:00
|
|
|
uploadOption := &operation.UploadOption{
|
|
|
|
UploadUrl: targetUrl,
|
|
|
|
Filename: fmt.Sprintf("test%d", i),
|
|
|
|
Cipher: false,
|
|
|
|
IsInputCompressed: true,
|
|
|
|
MimeType: "bench/test",
|
|
|
|
PairMap: nil,
|
|
|
|
Jwt: assignResult.Auth,
|
|
|
|
}
|
|
|
|
_, err = operation.UploadData(data, uploadOption)
|
2020-03-10 03:45:28 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("upload: %v", err)
|
|
|
|
}
|
|
|
|
return assignResult, targetUrl
|
2018-11-04 05:32:36 +00:00
|
|
|
}
|