2022-02-07 20:27:56 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
buffPool "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/util/pool"
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-06-27 08:53:53 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
2022-02-07 20:27:56 +00:00
|
|
|
)
|
|
|
|
|
2023-06-27 08:53:53 +00:00
|
|
|
// defaultGRPCPayloadChunkLen default value for maxChunkLen.
|
|
|
|
// See PrmObjectPutInit.SetGRPCPayloadChunkLen for details.
|
|
|
|
const defaultGRPCPayloadChunkLen = 3 << 20
|
|
|
|
|
2022-02-07 20:27:56 +00:00
|
|
|
// PrmObjectPutInit groups parameters of ObjectPutInit operation.
|
2022-07-29 15:42:24 +00:00
|
|
|
type PrmObjectPutInit struct {
|
2023-09-07 08:53:49 +00:00
|
|
|
XHeaders []string
|
|
|
|
|
|
|
|
BearerToken *bearer.Token
|
|
|
|
|
|
|
|
Session *session.Object
|
|
|
|
|
|
|
|
Local bool
|
|
|
|
|
|
|
|
CopiesNumber []uint32
|
|
|
|
|
|
|
|
MaxChunkLength int
|
|
|
|
|
|
|
|
MaxSize uint64
|
|
|
|
|
|
|
|
EpochSource transformer.EpochSource
|
|
|
|
|
|
|
|
WithoutHomomorphHash bool
|
|
|
|
|
|
|
|
Key *ecdsa.PrivateKey
|
2024-03-25 07:35:17 +00:00
|
|
|
|
|
|
|
Pool *buffPool.BufferPool
|
2022-07-29 15:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetCopiesNumber sets number of object copies that is enough to consider put successful.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.CopiesNumber instead.
|
2022-07-29 15:42:24 +00:00
|
|
|
func (x *PrmObjectPutInit) SetCopiesNumber(copiesNumber uint32) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.CopiesNumber = []uint32{copiesNumber}
|
2023-04-07 15:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetCopiesNumberByVectors sets ordered list of minimal required object copies numbers
|
|
|
|
// per placement vector. List's length MUST equal container's placement vector number,
|
|
|
|
// otherwise request will fail.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.CopiesNumber instead.
|
2023-04-07 15:40:54 +00:00
|
|
|
func (x *PrmObjectPutInit) SetCopiesNumberByVectors(copiesNumbers []uint32) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.CopiesNumber = copiesNumbers
|
2022-07-29 15:42:24 +00:00
|
|
|
}
|
2022-02-07 20:27:56 +00:00
|
|
|
|
2023-06-26 15:13:04 +00:00
|
|
|
// SetGRPCPayloadChunkLen sets maximum chunk length value for gRPC Put request.
|
|
|
|
// Maximum chunk length restricts maximum byte length of the chunk
|
|
|
|
// transmitted in a single stream message. It depends on
|
|
|
|
// server settings and other message fields.
|
|
|
|
// If not specified or negative value set, default value of 3MiB will be used.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.MaxChunkLength instead.
|
2023-06-26 15:13:04 +00:00
|
|
|
func (x *PrmObjectPutInit) SetGRPCPayloadChunkLen(v int) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.MaxChunkLength = v
|
2023-06-26 15:13:04 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 20:27:56 +00:00
|
|
|
// ResObjectPut groups the final result values of ObjectPutInit operation.
|
|
|
|
type ResObjectPut struct {
|
|
|
|
statusRes
|
|
|
|
|
2024-07-12 11:35:01 +00:00
|
|
|
obj oid.ID
|
|
|
|
epoch uint64
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
// StoredObjectID returns identifier of the saved object.
|
|
|
|
func (x ResObjectPut) StoredObjectID() oid.ID {
|
|
|
|
return x.obj
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 11:35:01 +00:00
|
|
|
// StoredEpoch returns creation epoch of the saved object.
|
|
|
|
func (x ResObjectPut) StoredEpoch() uint64 {
|
|
|
|
return x.epoch
|
|
|
|
}
|
|
|
|
|
2023-06-27 08:53:53 +00:00
|
|
|
// ObjectWriter is designed to write one object or
|
|
|
|
// multiple parts of one object to FrostFS system.
|
2022-02-07 20:27:56 +00:00
|
|
|
//
|
|
|
|
// Must be initialized using Client.ObjectPutInit, any other
|
|
|
|
// usage is unsafe.
|
2023-06-27 08:53:53 +00:00
|
|
|
type ObjectWriter interface {
|
|
|
|
// WriteHeader writes header of the object. Result means success.
|
|
|
|
// Failure reason can be received via Close.
|
|
|
|
WriteHeader(context.Context, object.Object) bool
|
|
|
|
// WritePayloadChunk writes chunk of the object payload. Result means success.
|
|
|
|
// Failure reason can be received via Close.
|
|
|
|
WritePayloadChunk(context.Context, []byte) bool
|
|
|
|
// Close ends writing the object and returns the result of the operation
|
|
|
|
// along with the final results. Must be called after using the ObjectWriter.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
|
|
|
// Any client's internal or transport errors are returned as Go built-in error.
|
|
|
|
// If Client is tuned to resolve FrostFS API statuses, then FrostFS failures
|
|
|
|
// codes are returned as error.
|
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs);
|
|
|
|
// - *apistatus.ContainerNotFound;
|
|
|
|
// - *apistatus.ObjectAccessDenied;
|
|
|
|
// - *apistatus.ObjectLocked;
|
|
|
|
// - *apistatus.LockNonRegularObject;
|
|
|
|
// - *apistatus.SessionTokenNotFound;
|
|
|
|
// - *apistatus.SessionTokenExpired.
|
|
|
|
Close(context.Context) (*ResObjectPut, error)
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UseKey specifies private key to sign the requests.
|
|
|
|
// If key is not provided, then Client default key is used.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.Key instead.
|
2022-08-25 12:14:18 +00:00
|
|
|
func (x *PrmObjectPutInit) UseKey(key ecdsa.PrivateKey) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.Key = &key
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithBearerToken attaches bearer token to be used for the operation.
|
|
|
|
// Should be called once before any writing steps.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.BearerToken instead.
|
2022-08-25 12:14:18 +00:00
|
|
|
func (x *PrmObjectPutInit) WithBearerToken(t bearer.Token) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.BearerToken = &t
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithinSession specifies session within which object should be stored.
|
|
|
|
// Should be called once before any writing steps.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.Session instead.
|
2022-08-25 12:14:18 +00:00
|
|
|
func (x *PrmObjectPutInit) WithinSession(t session.Object) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.Session = &t
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MarkLocal tells the server to execute the operation locally.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.Local instead.
|
2022-08-25 12:14:18 +00:00
|
|
|
func (x *PrmObjectPutInit) MarkLocal() {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.Local = true
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 11:04:53 +00:00
|
|
|
// WithXHeaders specifies list of extended headers (string key-value pairs)
|
|
|
|
// to be attached to the request. Must have an even length.
|
|
|
|
//
|
|
|
|
// Slice must not be mutated until the operation completes.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.XHeaders instead.
|
2022-08-25 12:14:18 +00:00
|
|
|
func (x *PrmObjectPutInit) WithXHeaders(hs ...string) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.XHeaders = hs
|
2022-03-03 11:04:53 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 08:53:53 +00:00
|
|
|
// WithObjectMaxSize specifies max object size value and use it during object splitting.
|
|
|
|
// When specified, start writing to the stream only after the object is formed.
|
|
|
|
// Continue processing the input only when the previous formed object has been successfully written.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.MaxSize instead.
|
2023-06-27 08:53:53 +00:00
|
|
|
func (x *PrmObjectPutInit) WithObjectMaxSize(maxSize uint64) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.MaxSize = maxSize
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 08:53:53 +00:00
|
|
|
// WithoutHomomorphicHash if set to true do not use Tillich-Zémor hash for payload.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.WithoutHomomorphHash instead.
|
2023-06-27 08:53:53 +00:00
|
|
|
func (x *PrmObjectPutInit) WithoutHomomorphicHash(v bool) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.WithoutHomomorphHash = v
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 08:53:53 +00:00
|
|
|
// WithEpochSource specifies epoch for object when split it on client side.
|
2023-09-07 08:53:49 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmObjectPutInit.EpochSource instead.
|
2023-06-27 08:53:53 +00:00
|
|
|
func (x *PrmObjectPutInit) WithEpochSource(es transformer.EpochSource) {
|
2023-09-07 08:53:49 +00:00
|
|
|
x.EpochSource = es
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ObjectPutInit initiates writing an object through a remote server using FrostFS API protocol.
|
2022-02-07 20:27:56 +00:00
|
|
|
//
|
|
|
|
// The call only opens the transmission channel, explicit recording is done using the ObjectWriter.
|
|
|
|
// Exactly one return value is non-nil. Resulting writer must be finally closed.
|
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly.
|
2022-02-07 20:27:56 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
2023-06-27 08:53:53 +00:00
|
|
|
func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (ObjectWriter, error) {
|
2023-09-07 08:53:49 +00:00
|
|
|
if prm.MaxSize > 0 {
|
2023-06-27 08:53:53 +00:00
|
|
|
return c.objectPutInitTransformer(prm)
|
2022-08-05 07:56:49 +00:00
|
|
|
}
|
2023-06-27 08:53:53 +00:00
|
|
|
return c.objectPutInitRaw(ctx, prm)
|
2022-02-07 20:27:56 +00:00
|
|
|
}
|