2022-05-12 19:37:38 +00:00
|
|
|
package native
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-05-23 11:42:48 +00:00
|
|
|
"context"
|
2022-05-12 19:37:38 +00:00
|
|
|
"crypto/ecdsa"
|
2022-05-23 11:42:48 +00:00
|
|
|
"crypto/sha256"
|
2022-09-02 19:23:33 +00:00
|
|
|
"encoding/hex"
|
2022-05-23 11:42:48 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-06-17 12:50:24 +00:00
|
|
|
"strconv"
|
2022-05-12 19:37:38 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-07 14:53:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
|
|
|
"git.frostfs.info/TrueCloudLab/tzhash/tz"
|
|
|
|
"git.frostfs.info/TrueCloudLab/xk6-frostfs/internal/stats"
|
2022-05-20 11:14:50 +00:00
|
|
|
"github.com/dop251/goja"
|
2022-05-12 19:37:38 +00:00
|
|
|
"go.k6.io/k6/js/modules"
|
|
|
|
"go.k6.io/k6/metrics"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Client struct {
|
2023-07-07 10:16:54 +00:00
|
|
|
vu modules.VU
|
|
|
|
key ecdsa.PrivateKey
|
|
|
|
tok session.Object
|
|
|
|
cli *client.Client
|
|
|
|
prepareLocally bool
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PutResponse struct {
|
|
|
|
Success bool
|
|
|
|
ObjectID string
|
2022-05-20 09:22:11 +00:00
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
DeleteResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-05-20 09:22:11 +00:00
|
|
|
GetResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
VerifyHashResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-06-17 12:50:24 +00:00
|
|
|
PutContainerResponse struct {
|
|
|
|
Success bool
|
|
|
|
ContainerID string
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:42:48 +00:00
|
|
|
PreparedObject struct {
|
2023-07-07 10:16:54 +00:00
|
|
|
vu modules.VU
|
|
|
|
key ecdsa.PrivateKey
|
|
|
|
cli *client.Client
|
|
|
|
hdr object.Object
|
|
|
|
payload []byte
|
|
|
|
prepareLocally bool
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
2022-05-12 19:37:38 +00:00
|
|
|
)
|
|
|
|
|
2022-05-25 08:22:40 +00:00
|
|
|
const defaultBufferSize = 64 * 1024
|
|
|
|
|
2023-07-05 12:35:00 +00:00
|
|
|
func (c *Client) Put(containerID string, headers map[string]string, payload goja.ArrayBuffer, chunkSize int) PutResponse {
|
2022-09-02 19:23:33 +00:00
|
|
|
cliContainerID := parseContainerID(containerID)
|
2022-05-12 19:37:38 +00:00
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectPut)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, c.key.PublicKey)
|
|
|
|
|
|
|
|
attrs := make([]object.Attribute, len(headers))
|
|
|
|
ind := 0
|
|
|
|
for k, v := range headers {
|
|
|
|
attrs[ind].SetKey(k)
|
|
|
|
attrs[ind].SetValue(v)
|
|
|
|
ind++
|
|
|
|
}
|
|
|
|
|
|
|
|
var o object.Object
|
2022-09-02 19:23:33 +00:00
|
|
|
o.SetContainerID(cliContainerID)
|
2022-05-12 19:37:38 +00:00
|
|
|
o.SetOwnerID(&owner)
|
|
|
|
o.SetAttributes(attrs...)
|
|
|
|
|
2023-07-07 10:16:54 +00:00
|
|
|
resp, err := put(c.vu, c.cli, c.prepareLocally, &tok, &o, payload.Bytes(), chunkSize)
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
2022-05-20 09:22:11 +00:00
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
return PutResponse{Success: true, ObjectID: resp.StoredObjectID().String()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
func (c *Client) Delete(containerID string, objectID string) DeleteResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectDelete)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-27 16:01:43 +00:00
|
|
|
err := tok.Sign(c.key)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-11-29 13:08:58 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
var prm client.PrmObjectDelete
|
2023-12-14 08:35:09 +00:00
|
|
|
prm.ObjectID = &cliObjectID
|
|
|
|
prm.ContainerID = &cliContainerID
|
|
|
|
prm.Session = &tok
|
2022-09-27 16:01:43 +00:00
|
|
|
|
|
|
|
_, err = c.cli.ObjectDelete(c.vu.Context(), prm)
|
|
|
|
if err != nil {
|
2022-11-29 13:08:58 +00:00
|
|
|
stats.Report(c.vu, objDeleteFails, 1)
|
2022-09-27 16:01:43 +00:00
|
|
|
return DeleteResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
2022-12-30 10:47:28 +00:00
|
|
|
stats.Report(c.vu, objDeleteTotal, 1)
|
2022-11-29 13:08:58 +00:00
|
|
|
stats.Report(c.vu, objDeleteDuration, metrics.D(time.Since(start)))
|
2022-09-27 16:01:43 +00:00
|
|
|
return DeleteResponse{Success: true}
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
func (c *Client) Get(containerID, objectID string) GetResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
2022-05-12 19:37:38 +00:00
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectGet)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
var prm client.PrmObjectGet
|
2023-12-14 08:35:09 +00:00
|
|
|
prm.ObjectID = &cliObjectID
|
|
|
|
prm.ContainerID = &cliContainerID
|
|
|
|
prm.Session = &tok
|
2022-05-12 19:37:38 +00:00
|
|
|
|
2023-12-14 08:35:09 +00:00
|
|
|
objSize := 0
|
2023-07-05 14:22:34 +00:00
|
|
|
err = get(c.cli, prm, c.vu.Context(), func(data []byte) {
|
2022-09-02 19:23:33 +00:00
|
|
|
objSize += len(data)
|
|
|
|
})
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
stats.Report(c.vu, objGetFails, 1)
|
2022-05-20 09:22:11 +00:00
|
|
|
return GetResponse{Success: false, Error: err.Error()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 10:47:28 +00:00
|
|
|
stats.Report(c.vu, objGetTotal, 1)
|
2022-09-02 19:23:33 +00:00
|
|
|
stats.Report(c.vu, objGetDuration, metrics.D(time.Since(start)))
|
|
|
|
stats.ReportDataReceived(c.vu, float64(objSize))
|
|
|
|
return GetResponse{Success: true}
|
|
|
|
}
|
|
|
|
|
|
|
|
func get(
|
|
|
|
cli *client.Client,
|
|
|
|
prm client.PrmObjectGet,
|
|
|
|
ctx context.Context,
|
|
|
|
onDataChunk func(chunk []byte),
|
|
|
|
) error {
|
2023-12-14 08:35:09 +00:00
|
|
|
buf := make([]byte, defaultBufferSize)
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
objectReader, err := cli.ObjectGetInit(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-12 19:37:38 +00:00
|
|
|
var o object.Object
|
|
|
|
if !objectReader.ReadHeader(&o) {
|
2022-06-17 12:50:24 +00:00
|
|
|
if _, err = objectReader.Close(); err != nil {
|
2022-09-02 19:23:33 +00:00
|
|
|
return err
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
return errors.New("can't read object header")
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n, _ := objectReader.Read(buf)
|
|
|
|
for n > 0 {
|
2022-09-02 19:23:33 +00:00
|
|
|
onDataChunk(buf[:n])
|
2022-05-12 19:37:38 +00:00
|
|
|
n, _ = objectReader.Read(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = objectReader.Close()
|
|
|
|
if err != nil {
|
2022-09-02 19:23:33 +00:00
|
|
|
return err
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) VerifyHash(containerID, objectID, expectedHash string) VerifyHashResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectGet)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var prm client.PrmObjectGet
|
2023-12-14 08:35:09 +00:00
|
|
|
prm.ObjectID = &cliObjectID
|
|
|
|
prm.ContainerID = &cliContainerID
|
|
|
|
prm.Session = &tok
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
hasher := sha256.New()
|
2023-07-05 14:22:34 +00:00
|
|
|
err = get(c.cli, prm, c.vu.Context(), func(data []byte) {
|
2022-09-02 19:23:33 +00:00
|
|
|
hasher.Write(data)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return VerifyHashResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
2022-09-22 16:57:21 +00:00
|
|
|
actualHash := hex.EncodeToString(hasher.Sum(nil))
|
2022-09-02 19:23:33 +00:00
|
|
|
if actualHash != expectedHash {
|
|
|
|
return VerifyHashResponse{Success: true, Error: "hash mismatch"}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VerifyHashResponse{Success: true}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-06-17 12:50:24 +00:00
|
|
|
func (c *Client) putCnrErrorResponse(err error) PutContainerResponse {
|
|
|
|
stats.Report(c.vu, cnrPutFails, 1)
|
|
|
|
return PutContainerResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PutContainer(params map[string]string) PutContainerResponse {
|
|
|
|
stats.Report(c.vu, cnrPutTotal, 1)
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
var cnr container.Container
|
|
|
|
cnr.Init()
|
|
|
|
|
|
|
|
var usr user.ID
|
|
|
|
user.IDFromKey(&usr, c.key.PublicKey)
|
|
|
|
|
|
|
|
container.SetCreationTime(&cnr, time.Now())
|
|
|
|
cnr.SetOwner(usr)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
if basicACLStr, ok := params["acl"]; ok {
|
2022-10-26 19:13:14 +00:00
|
|
|
var basicACL acl.Basic
|
|
|
|
err := basicACL.DecodeString(basicACLStr)
|
2022-06-17 12:50:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
cnr.SetBasicACL(basicACL)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
placementPolicyStr, ok := params["placement_policy"]
|
|
|
|
if ok {
|
2022-10-26 19:13:14 +00:00
|
|
|
var placementPolicy netmap.PlacementPolicy
|
|
|
|
err := placementPolicy.DecodeString(placementPolicyStr)
|
2022-06-17 12:50:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
cnr.SetPlacementPolicy(placementPolicy)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
containerName, hasName := params["name"]
|
|
|
|
if hasName {
|
2022-10-26 19:13:14 +00:00
|
|
|
container.SetName(&cnr, containerName)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var nameScopeGlobal bool
|
|
|
|
if nameScopeGlobalStr, ok := params["name_scope_global"]; ok {
|
|
|
|
if nameScopeGlobal, err = strconv.ParseBool(nameScopeGlobalStr); err != nil {
|
|
|
|
return c.putCnrErrorResponse(fmt.Errorf("invalid name_scope_global param: %w", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if nameScopeGlobal {
|
|
|
|
if !hasName {
|
|
|
|
return c.putCnrErrorResponse(errors.New("you must provide container name if name_scope_global param is set"))
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
var domain container.Domain
|
|
|
|
domain.SetName(containerName)
|
|
|
|
|
|
|
|
container.WriteDomain(&cnr, domain)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
var prm client.PrmContainerPut
|
2022-10-26 19:13:14 +00:00
|
|
|
prm.SetContainer(cnr)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
res, err := c.cli.ContainerPut(c.vu.Context(), prm)
|
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var wp waitParams
|
|
|
|
wp.setDefaults()
|
|
|
|
|
|
|
|
if err = c.waitForContainerPresence(c.vu.Context(), res.ID(), &wp); err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.Report(c.vu, cnrPutDuration, metrics.D(time.Since(start)))
|
|
|
|
return PutContainerResponse{Success: true, ContainerID: res.ID().EncodeToString()}
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
func (c *Client) Onsite(containerID string, payload goja.ArrayBuffer) PreparedObject {
|
2022-05-23 11:42:48 +00:00
|
|
|
maxObjectSize, epoch, hhDisabled, err := parseNetworkInfo(c.vu.Context(), c.cli)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
data := payload.Bytes()
|
|
|
|
ln := len(data)
|
|
|
|
if ln > int(maxObjectSize) {
|
|
|
|
// not sure if load test needs object transformation
|
|
|
|
// with parent-child relation; if needs, then replace
|
|
|
|
// this code with the usage of object transformer from
|
2022-12-29 14:52:55 +00:00
|
|
|
// frostfs-loader or distribution.
|
2022-05-23 11:42:48 +00:00
|
|
|
msg := fmt.Sprintf("payload size %d is bigger than network limit %d", ln, maxObjectSize)
|
|
|
|
panic(msg)
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
cliContainerID := parseContainerID(containerID)
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, c.key.PublicKey)
|
|
|
|
|
|
|
|
apiVersion := version.Current()
|
|
|
|
|
|
|
|
obj := object.New()
|
|
|
|
obj.SetVersion(&apiVersion)
|
|
|
|
obj.SetType(object.TypeRegular)
|
2022-09-02 19:23:33 +00:00
|
|
|
obj.SetContainerID(cliContainerID)
|
2022-05-23 11:42:48 +00:00
|
|
|
obj.SetOwnerID(&owner)
|
|
|
|
obj.SetPayloadSize(uint64(ln))
|
|
|
|
obj.SetCreationEpoch(epoch)
|
|
|
|
|
|
|
|
var sha, hh checksum.Checksum
|
|
|
|
sha.SetSHA256(sha256.Sum256(data))
|
|
|
|
obj.SetPayloadChecksum(sha)
|
|
|
|
if !hhDisabled {
|
|
|
|
hh.SetTillichZemor(tz.Sum(data))
|
|
|
|
obj.SetPayloadHomomorphicHash(hh)
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreparedObject{
|
2023-07-07 10:16:54 +00:00
|
|
|
vu: c.vu,
|
|
|
|
key: c.key,
|
|
|
|
cli: c.cli,
|
|
|
|
hdr: *obj,
|
|
|
|
payload: data,
|
|
|
|
prepareLocally: c.prepareLocally,
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p PreparedObject) Put(headers map[string]string) PutResponse {
|
|
|
|
obj := p.hdr
|
|
|
|
|
|
|
|
attrs := make([]object.Attribute, len(headers))
|
|
|
|
ind := 0
|
|
|
|
for k, v := range headers {
|
|
|
|
attrs[ind].SetKey(k)
|
|
|
|
attrs[ind].SetValue(v)
|
|
|
|
ind++
|
|
|
|
}
|
|
|
|
obj.SetAttributes(attrs...)
|
|
|
|
|
|
|
|
id, err := object.CalculateID(&obj)
|
|
|
|
if err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
obj.SetID(id)
|
|
|
|
|
|
|
|
if err = object.CalculateAndSetSignature(p.key, &obj); err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
2023-07-07 10:16:54 +00:00
|
|
|
_, err = put(p.vu, p.cli, p.prepareLocally, nil, &obj, p.payload, 0)
|
2022-05-23 11:56:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PutResponse{Success: true, ObjectID: id.String()}
|
|
|
|
}
|
|
|
|
|
2023-07-07 10:16:54 +00:00
|
|
|
type epochSource uint64
|
|
|
|
|
|
|
|
func (s epochSource) CurrentEpoch() uint64 {
|
|
|
|
return uint64(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func put(vu modules.VU, cli *client.Client, prepareLocally bool, tok *session.Object,
|
2023-12-14 08:35:09 +00:00
|
|
|
hdr *object.Object, payload []byte, chunkSize int,
|
|
|
|
) (*client.ResObjectPut, error) {
|
2023-07-05 14:22:34 +00:00
|
|
|
bufSize := defaultBufferSize
|
|
|
|
if chunkSize > 0 {
|
|
|
|
bufSize = chunkSize
|
|
|
|
}
|
2022-05-23 11:56:38 +00:00
|
|
|
buf := make([]byte, bufSize)
|
|
|
|
rdr := bytes.NewReader(payload)
|
|
|
|
sz := rdr.Size()
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
// starting upload
|
|
|
|
start := time.Now()
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
var prm client.PrmObjectPutInit
|
|
|
|
if tok != nil {
|
|
|
|
prm.WithinSession(*tok)
|
|
|
|
}
|
2023-07-05 12:35:00 +00:00
|
|
|
if chunkSize > 0 {
|
|
|
|
prm.SetGRPCPayloadChunkLen(chunkSize)
|
|
|
|
}
|
2023-07-07 10:16:54 +00:00
|
|
|
if prepareLocally {
|
|
|
|
res, err := cli.NetworkInfo(vu.Context(), client.PrmNetworkInfo{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
prm.WithObjectMaxSize(res.Info().MaxObjectSize())
|
|
|
|
prm.WithEpochSource(epochSource(res.Info().CurrentEpoch()))
|
|
|
|
prm.WithoutHomomorphicHash(true)
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
objectWriter, err := cli.ObjectPutInit(vu.Context(), prm)
|
2022-05-23 11:42:48 +00:00
|
|
|
if err != nil {
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutFails, 1)
|
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 12:34:06 +00:00
|
|
|
if !objectWriter.WriteHeader(vu.Context(), *hdr) {
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutFails, 1)
|
2023-07-05 12:34:06 +00:00
|
|
|
_, err = objectWriter.Close(vu.Context())
|
2022-05-23 11:56:38 +00:00
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n, _ := rdr.Read(buf)
|
|
|
|
for n > 0 {
|
2023-07-05 12:34:06 +00:00
|
|
|
if !objectWriter.WritePayloadChunk(vu.Context(), buf[:n]) {
|
2022-05-23 11:42:48 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
n, _ = rdr.Read(buf)
|
|
|
|
}
|
|
|
|
|
2023-07-05 12:34:06 +00:00
|
|
|
resp, err := objectWriter.Close(vu.Context())
|
2022-05-23 11:42:48 +00:00
|
|
|
if err != nil {
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutFails, 1)
|
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 10:47:28 +00:00
|
|
|
stats.Report(vu, objPutTotal, 1)
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.ReportDataSent(vu, float64(sz))
|
|
|
|
stats.Report(vu, objPutDuration, metrics.D(time.Since(start)))
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-12-30 10:47:28 +00:00
|
|
|
return resp, nil
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseNetworkInfo(ctx context.Context, cli *client.Client) (maxObjSize, epoch uint64, hhDisabled bool, err error) {
|
|
|
|
ni, err := cli.NetworkInfo(ctx, client.PrmNetworkInfo{})
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, false, err
|
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
ninfo := ni.Info()
|
|
|
|
|
|
|
|
return ninfo.MaxObjectSize(), ninfo.CurrentEpoch(), ninfo.HomomorphicHashingDisabled(), err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
type waitParams struct {
|
|
|
|
timeout time.Duration
|
|
|
|
pollInterval time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *waitParams) setDefaults() {
|
|
|
|
x.timeout = 120 * time.Second
|
|
|
|
x.pollInterval = 5 * time.Second
|
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
func (c *Client) waitForContainerPresence(ctx context.Context, cnrID cid.ID, wp *waitParams) error {
|
2022-06-17 12:50:24 +00:00
|
|
|
return waitFor(ctx, wp, func(ctx context.Context) bool {
|
|
|
|
var prm client.PrmContainerGet
|
2022-10-26 19:13:14 +00:00
|
|
|
prm.SetContainer(cnrID)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
_, err := c.cli.ContainerGet(ctx, prm)
|
|
|
|
return err == nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitFor(ctx context.Context, params *waitParams, condition func(context.Context) bool) error {
|
|
|
|
wctx, cancel := context.WithTimeout(ctx, params.timeout)
|
|
|
|
defer cancel()
|
|
|
|
ticker := time.NewTimer(params.pollInterval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
wdone := wctx.Done()
|
|
|
|
done := ctx.Done()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return ctx.Err()
|
|
|
|
case <-wdone:
|
|
|
|
return wctx.Err()
|
|
|
|
case <-ticker.C:
|
|
|
|
if condition(ctx) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ticker.Reset(params.pollInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
func parseContainerID(strContainerID string) cid.ID {
|
|
|
|
var containerID cid.ID
|
|
|
|
err := containerID.DecodeString(strContainerID)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return containerID
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseObjectID(strObjectID string) oid.ID {
|
|
|
|
var cliObjectID oid.ID
|
|
|
|
err := cliObjectID.DecodeString(strObjectID)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cliObjectID
|
|
|
|
}
|