Ekaterina Lebedeva
6d3ecb6528
All checks were successful
DCO action / DCO (pull_request) Successful in 1m52s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m9s
Tests and linters / Tests with -race (pull_request) Successful in 2m12s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m56s
Tests and linters / Lint (pull_request) Successful in 3m16s
* Currently, objects created in preset are never deleted. k6 deletes only objects from registry, if registry file is not provided k6 delete load fails. * Added cli utility to import objects created in preset into registry so k6 can delete them normally. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package importer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"git.frostfs.info/TrueCloudLab/xk6-frostfs/internal/registry"
|
|
)
|
|
|
|
type PreGenObj struct {
|
|
Bucket string `json:"bucket"`
|
|
Object string `json:"object"`
|
|
Container string `json:"container"`
|
|
}
|
|
|
|
type PreGenerateInfo struct {
|
|
Buckets []string `json:"buckets"`
|
|
Containers []string `json:"containers"`
|
|
Objects []PreGenObj `json:"objects"`
|
|
ObjSize string `json:"obj_size"`
|
|
}
|
|
|
|
// ImportJSONPreGen writes objects from pregenerated JSON file
|
|
// to the registry.
|
|
// Note that ImportJSONPreGen does not check if object already
|
|
// exists in the registry so in case of re-entry the registry
|
|
// will have two entities representing the same object.
|
|
func ImportJSONPreGen(o *registry.ObjRegistry, filename string) error {
|
|
f, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var pregenInfo PreGenerateInfo
|
|
err = json.Unmarshal(f, &pregenInfo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// AddObject uses DB.Batch to combine concurrent Batch calls
|
|
// into a single Bolt transaction. DB.Batch is limited by
|
|
// DB.MaxBatchDelay which may affect perfomance.
|
|
for _, obj := range pregenInfo.Objects {
|
|
if obj.Bucket != "" {
|
|
err = o.AddObject("", "", obj.Bucket, obj.Object, "")
|
|
} else {
|
|
err = o.AddObject(obj.Container, obj.Object, "", "", "")
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|