git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/object_put.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"crypto/ecdsa"
     6  
     7  	buffPool "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/pool"
     8  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
     9  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
    10  	oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
    11  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
    12  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
    13  )
    14  
    15  // defaultGRPCPayloadChunkLen default value for maxChunkLen.
    16  // See PrmObjectPutInit.SetGRPCPayloadChunkLen for details.
    17  const defaultGRPCPayloadChunkLen = 3 << 20
    18  
    19  // PrmObjectPutInit groups parameters of ObjectPutInit operation.
    20  type PrmObjectPutInit struct {
    21  	XHeaders []string
    22  
    23  	BearerToken *bearer.Token
    24  
    25  	Session *session.Object
    26  
    27  	Local bool
    28  
    29  	CopiesNumber []uint32
    30  
    31  	MaxChunkLength int
    32  
    33  	MaxSize uint64
    34  
    35  	EpochSource transformer.EpochSource
    36  
    37  	WithoutHomomorphHash bool
    38  
    39  	Key *ecdsa.PrivateKey
    40  
    41  	Pool *buffPool.BufferPool
    42  }
    43  
    44  // SetCopiesNumber sets number of object copies that is enough to consider put successful.
    45  //
    46  // Deprecated: Use PrmObjectPutInit.CopiesNumber instead.
    47  func (x *PrmObjectPutInit) SetCopiesNumber(copiesNumber uint32) {
    48  	x.CopiesNumber = []uint32{copiesNumber}
    49  }
    50  
    51  // SetCopiesNumberByVectors sets ordered list of minimal required object copies numbers
    52  // per placement vector. List's length MUST equal container's placement vector number,
    53  // otherwise request will fail.
    54  //
    55  // Deprecated: Use PrmObjectPutInit.CopiesNumber instead.
    56  func (x *PrmObjectPutInit) SetCopiesNumberByVectors(copiesNumbers []uint32) {
    57  	x.CopiesNumber = copiesNumbers
    58  }
    59  
    60  // SetGRPCPayloadChunkLen sets maximum chunk length value for gRPC Put request.
    61  // Maximum chunk length restricts maximum byte length of the chunk
    62  // transmitted in a single stream message. It depends on
    63  // server settings and other message fields.
    64  // If not specified or negative value set, default value of 3MiB will be used.
    65  //
    66  // Deprecated: Use PrmObjectPutInit.MaxChunkLength instead.
    67  func (x *PrmObjectPutInit) SetGRPCPayloadChunkLen(v int) {
    68  	x.MaxChunkLength = v
    69  }
    70  
    71  // ResObjectPut groups the final result values of ObjectPutInit operation.
    72  type ResObjectPut struct {
    73  	statusRes
    74  
    75  	obj   oid.ID
    76  	epoch uint64
    77  }
    78  
    79  // StoredObjectID returns identifier of the saved object.
    80  func (x ResObjectPut) StoredObjectID() oid.ID {
    81  	return x.obj
    82  }
    83  
    84  // StoredEpoch returns creation epoch of the saved object.
    85  func (x ResObjectPut) StoredEpoch() uint64 {
    86  	return x.epoch
    87  }
    88  
    89  // ObjectWriter is designed to write one object or
    90  // multiple parts of one object to FrostFS system.
    91  //
    92  // Must be initialized using Client.ObjectPutInit, any other
    93  // usage is unsafe.
    94  type ObjectWriter interface {
    95  	// WriteHeader writes header of the object. Result means success.
    96  	// Failure reason can be received via Close.
    97  	WriteHeader(context.Context, object.Object) bool
    98  	// WritePayloadChunk writes chunk of the object payload. Result means success.
    99  	// Failure reason can be received via Close.
   100  	WritePayloadChunk(context.Context, []byte) bool
   101  	// Close ends writing the object and returns the result of the operation
   102  	// along with the final results. Must be called after using the ObjectWriter.
   103  	//
   104  	// Exactly one return value is non-nil. By default, server status is returned in res structure.
   105  	// Any client's internal or transport errors are returned as Go built-in error.
   106  	// If Client is tuned to resolve FrostFS API statuses, then FrostFS failures
   107  	// codes are returned as error.
   108  	//
   109  	// Return statuses:
   110  	//   - global (see Client docs);
   111  	//   - *apistatus.ContainerNotFound;
   112  	//   - *apistatus.ObjectAccessDenied;
   113  	//   - *apistatus.ObjectLocked;
   114  	//   - *apistatus.LockNonRegularObject;
   115  	//   - *apistatus.SessionTokenNotFound;
   116  	//   - *apistatus.SessionTokenExpired.
   117  	Close(context.Context) (*ResObjectPut, error)
   118  }
   119  
   120  // UseKey specifies private key to sign the requests.
   121  // If key is not provided, then Client default key is used.
   122  //
   123  // Deprecated: Use PrmObjectPutInit.Key instead.
   124  func (x *PrmObjectPutInit) UseKey(key ecdsa.PrivateKey) {
   125  	x.Key = &key
   126  }
   127  
   128  // WithBearerToken attaches bearer token to be used for the operation.
   129  // Should be called once before any writing steps.
   130  //
   131  // Deprecated: Use PrmObjectPutInit.BearerToken instead.
   132  func (x *PrmObjectPutInit) WithBearerToken(t bearer.Token) {
   133  	x.BearerToken = &t
   134  }
   135  
   136  // WithinSession specifies session within which object should be stored.
   137  // Should be called once before any writing steps.
   138  //
   139  // Deprecated: Use PrmObjectPutInit.Session instead.
   140  func (x *PrmObjectPutInit) WithinSession(t session.Object) {
   141  	x.Session = &t
   142  }
   143  
   144  // MarkLocal tells the server to execute the operation locally.
   145  //
   146  // Deprecated: Use PrmObjectPutInit.Local instead.
   147  func (x *PrmObjectPutInit) MarkLocal() {
   148  	x.Local = true
   149  }
   150  
   151  // WithXHeaders specifies list of extended headers (string key-value pairs)
   152  // to be attached to the request. Must have an even length.
   153  //
   154  // Slice must not be mutated until the operation completes.
   155  //
   156  // Deprecated: Use PrmObjectPutInit.XHeaders instead.
   157  func (x *PrmObjectPutInit) WithXHeaders(hs ...string) {
   158  	x.XHeaders = hs
   159  }
   160  
   161  // WithObjectMaxSize specifies max object size value and use it during object splitting.
   162  // When specified, start writing to the stream only after the object is formed.
   163  // Continue processing the input only when the previous formed object has been successfully written.
   164  //
   165  // Deprecated: Use PrmObjectPutInit.MaxSize instead.
   166  func (x *PrmObjectPutInit) WithObjectMaxSize(maxSize uint64) {
   167  	x.MaxSize = maxSize
   168  }
   169  
   170  // WithoutHomomorphicHash if set to true do not use Tillich-Zémor hash for payload.
   171  //
   172  // Deprecated: Use PrmObjectPutInit.WithoutHomomorphHash instead.
   173  func (x *PrmObjectPutInit) WithoutHomomorphicHash(v bool) {
   174  	x.WithoutHomomorphHash = v
   175  }
   176  
   177  // WithEpochSource specifies epoch for object when split it on client side.
   178  //
   179  // Deprecated: Use PrmObjectPutInit.EpochSource instead.
   180  func (x *PrmObjectPutInit) WithEpochSource(es transformer.EpochSource) {
   181  	x.EpochSource = es
   182  }
   183  
   184  // ObjectPutInit initiates writing an object through a remote server using FrostFS API protocol.
   185  //
   186  // The call only opens the transmission channel, explicit recording is done using the ObjectWriter.
   187  // Exactly one return value is non-nil. Resulting writer must be finally closed.
   188  //
   189  // Returns an error if parameters are set incorrectly.
   190  // Context is required and must not be nil. It is used for network communication.
   191  func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (ObjectWriter, error) {
   192  	if prm.MaxSize > 0 {
   193  		return c.objectPutInitTransformer(prm)
   194  	}
   195  	return c.objectPutInitRaw(ctx, prm)
   196  }