Documentation
¶
Overview ¶
Package s3 provides a storage backend using AWS S3 or compatible servers.
In order to allow this backend to function properly, the user accessing the bucket must have at least following AWS IAM policy permissions for the bucket and all of its sub resources:
s3:AbortMultipartUpload s3:DeleteObject s3:GetObject s3:ListMultipartUploadParts s3:PutObject
While this package uses the official AWS SDK for Go, Destination is able to work with any S3-compatible service such as MinIO. In order to change the HTTP endpoint used for sending requests to, adjust the `BaseEndpoint` option in the AWS SDK For Go V2 (https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Options).
Implementation ¶
Once a new transfer is initiated, multiple objects in S3 are created:
First of all, a new info object is stored which contains a JSON-encoded blob of general information about the upload including its size and metadata. This kind of object have the suffix ".info" in their key.
In addition, a new multipart upload (http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html) is created.
If metadata is associated with the upload during creation, it will be added to the multipart upload and after finishing it, the metadata will be passed to the final object. However, the metadata which will be attached to the final object can only contain ASCII characters and every non-ASCII character will be replaced by a question mark (for examples, "Menü" will be "Men?"). However, this does not apply for the metadata returned by the GetInfo function since it relies on the info object for reading the metadata. Therefore, HEAD responses will always contain the unchanged metadata, Base64- encoded, even if it contains non-ASCII characters.
Once the upload is finished, the multipart upload is completed, resulting in the entire file being stored in the bucket. The info object, containing metadata is not deleted. It is recommended to copy the finished upload to another bucket to avoid it being deleted by the Termination extension.
If an upload is about to being terminated, the multipart upload is aborted which removes all the uploaded parts from the bucket. In addition, the info object is also deleted. If the upload has been finished already, the finished object containing the entire upload is also removed.
Considerations ¶
In order to support transfer' principle of resumable upload, S3's Multipart-Uploads are internally used.
When receiving a PATCH request, its body will be temporarily stored on disk. This requirement has been made to ensure the minimum size of a single part and to allow the AWS SDK to calculate a checksum. Once the part has been uploaded to S3, the temporary file will be removed immediately. Therefore, please ensure that the server running this storage backend has enough disk space available to hold these caches.
In addition, it must be mentioned that AWS S3 only offers eventual consistency (https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyModel). Therefore, it is required to build additional measurements in order to prevent concurrent access to the same upload resources which may result in data corruption.
Index ¶
- Constants
- type Destination
- func (d *Destination) Close()
- func (d *Destination) CreateFile(ctx context.Context, path string, size int64, modTime time.Time, ...) (err error)
- func (d *Destination) DeleteFile(ctx context.Context, filePath string, protocol protoc.Client) (err error)
- func (d *Destination) FinalizeTransfer(ctx context.Context, filePath string, protocol protoc.Client) (err error)
- func (d *Destination) GetFileInfo(ctx context.Context, filePath string, cli protoc.Client) (info xferfile.Info, err error)
- func (d *Destination) TransferFileChunk(ctx context.Context, filePath string, src io.Reader, offset int64, ...) (n int64, err error)
- type Source
Constants ¶
const TempDirUseMemory = "_memory"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Destination ¶
type Destination struct { // MetadataObjectPrefix is prepended to the name of each .info and .part S3 // object that is created. If it is not set, then ObjectPrefix is used. // // Note: With customization in the Upload server, we should not use this field, as it will be overwritten by // the storage.SetFilePrefix function. MetadataObjectPrefix string // MaxObjectSize is the maximum size an S3 Object can have according to S3 // API specifications. See link above. MaxObjectSize int64 // MinPartSize specifies the minimum size of a single part uploaded to S3 // in bytes. This number needs to match with the underlying S3 backend or else // uploaded parts will be rejected. AWS S3, for examples, uses 5MB for this value. MinPartSize int64 // MaxPartSize specifies the maximum size of a single part uploaded to S3 // in bytes. This value must be bigger than MinPartSize! In order to // choose the correct number, two things have to be kept in mind: // // If this value is too big and uploading the part to S3 is interrupted // expectedly, the entire part is discarded and the end user is required // to resume the upload and re-upload the entire big part. In addition, the // entire part must be written to disk before submitting to S3. // // If this value is too low, a lot of requests to S3 may be made, depending // on how fast data is coming in. This may result in an eventual overhead. MaxPartSize int64 // PreferredPartSize specifies the preferred size of a single part uploaded to // S3. Destination will attempt to slice the incoming data into parts with this // size whenever possible. In some cases, smaller parts are necessary, so // not every part may reach this value. The PreferredPartSize must be inside the // range of MinPartSize to MaxPartSize. PreferredPartSize int64 // MaxMultipartParts is the maximum number of parts an S3 multipart upload is // allowed to have according to AWS S3 API specifications. // See: http://docs.aws.amazon.com/AmazonS3/latest/dev/qfacts.html MaxMultipartParts int64 // MaxBufferedParts is the number of additional parts that can be received from // the client and stored on disk while a part is being uploaded to S3. This // can help improve throughput by not blocking the client while transfer is // communicating with the S3 API, which can have unpredictable latency. MaxBufferedParts int64 // TemporaryDirectory is the path where Destination will create temporary files // on disk during the upload. An empty string ("", the default value) will // cause Destination to use the operating system's default temporary directory. TemporaryDirectory string // DisableContentHashes instructs the Destination to not calculate the MD5 and SHA256 // hashes when uploading data to S3. These hashes are used for file integrity checks // and for authentication. However, these hashes also consume a significant amount of // CPU, so it might be desirable to disable them. // Note that this property is experimental and might be removed in the future! DisableContentHashes bool // contains filtered or unexported fields }
func NewDestination ¶
func NewDestination(logger logr.Logger) (d *Destination)
NewDestination constructs a new storage using the supplied bucket and service object.
func (*Destination) Close ¶
func (d *Destination) Close()
func (*Destination) CreateFile ¶
func (*Destination) DeleteFile ¶
func (*Destination) FinalizeTransfer ¶
func (*Destination) GetFileInfo ¶
type Source ¶
type Source struct {
// contains filtered or unexported fields
}