transfer

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package transfer implements streaming copy/move operations for cloud object storage.

Index

Constants

View Source
const (
	// CopyStageSourceRead covers GetObject plus full body materialization into
	// the retry buffer (memory or temp file) for the single-part path.
	CopyStageSourceRead = "source_read"
	// CopyStageDestWrite covers the destination Put (or multipart upload from
	// an already-materialized body).
	CopyStageDestWrite = "dest_write"
	// CopyStageCoupled covers paths that keep source and dest open together
	// (streaming multipart from a live Get body). The global token still spans
	// the whole operation for those paths.
	CopyStageCoupled = "coupled_copy"
)

CopyStage names a sequential phase of CopyObject for concurrency gating and sterile stage attribution. Source-read fully buffers small objects before dest-write begins, so the phases do not need a shared concurrency token.

View Source
const (
	DefaultMultipartPartSizeBytes  int64 = 8 << 20  // 8 MiB
	DefaultMultipartThresholdBytes int64 = 64 << 20 // 64 MiB
	MultipartDisabledThreshold     int64 = 1<<63 - 1
	MaxMultipartParts                    = 10000
)
View Source
const (
	// DefaultRetryBufferMaxMemoryBytes controls how large an object we buffer in memory
	// to make PUT retries seekable. Larger objects are spooled to a temp file.
	DefaultRetryBufferMaxMemoryBytes int64 = 16 << 20 // 16 MiB
)

Variables

View Source
var ErrUploadSessionClosed = errors.New("transfer upload session is closed")

Functions

func CopyObject

func CopyObject(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64) (int64, error)

CopyObject streams a single object from srcKey to dstKey. expectedSize, when positive, is compared to the source read metadata.

func CopyObjectConditional

func CopyObjectConditional(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, precond provider.PutPrecondition) (int64, provider.PutResult, error)

CopyObjectConditional streams an object with an atomic write precondition.

func CopyObjectConditionalWithGate

func CopyObjectConditionalWithGate(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, precond provider.PutPrecondition, opts provider.PutOptions, gate CopyGate) (int64, provider.PutResult, error)

CopyObjectConditionalWithGate applies phase budgets to a conditional copy.

func CopyObjectConditionalWithOptions

func CopyObjectConditionalWithOptions(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, precond provider.PutPrecondition, opts provider.PutOptions) (int64, provider.PutResult, error)

CopyObjectConditionalWithOptions preserves atomic destination predicates.

func CopyObjectRevisionConditionalWithGate

func CopyObjectRevisionConditionalWithGate(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, precond provider.PutPrecondition, opts provider.PutOptions, revision provider.SourceRevision, gate CopyGate) (int64, provider.PutResult, error)

CopyObjectRevisionConditionalWithGate preserves revision and phase admission.

func CopyObjectRevisionConditionalWithOptions

func CopyObjectRevisionConditionalWithOptions(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, precond provider.PutPrecondition, opts provider.PutOptions, revision provider.SourceRevision) (int64, provider.PutResult, error)

CopyObjectRevisionConditionalWithOptions pins the admitted source revision.

func CopyObjectRevisionWithGate

func CopyObjectRevisionWithGate(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, opts provider.PutOptions, revision provider.SourceRevision, gate CopyGate) (int64, error)

CopyObjectRevisionWithGate streams an admitted revision under phase budgets.

func CopyObjectRevisionWithOptions

func CopyObjectRevisionWithOptions(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, opts provider.PutOptions, revision provider.SourceRevision) (int64, error)

CopyObjectRevisionWithOptions streams exactly the admitted source revision.

func CopyObjectWithGate

func CopyObjectWithGate(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, opts provider.PutOptions, gate CopyGate) (int64, error)

CopyObjectWithGate independently gates the source and destination phases when the source can be buffered before the destination write.

func CopyObjectWithOptions

func CopyObjectWithOptions(ctx context.Context, src provider.Provider, dst provider.Provider, srcKey, dstKey string, expectedSize int64, retryBufferMaxMemoryBytes int64, opts provider.PutOptions) (int64, error)

CopyObjectWithOptions streams an object with destination metadata options.

func DrainReader

func DrainReader(r io.Reader)

DrainReader ensures io.Reader is fully consumed when needed.

func IsTransientNetworkError

func IsTransientNetworkError(err error) bool

IsTransientNetworkError reports transport failures that callers can usually retry at the object/chunk level without treating the engine as internally broken.

Types

type Config

type Config struct {
	Concurrency  int
	OnExists     string // skip | overwrite | fail
	Dedup        DedupConfig
	Mode         string // copy | move
	PathTemplate string

	// RetryBufferMaxMemoryBytes controls how large an object we buffer in memory to
	// make the PUT request body seekable for SDK retries.
	// Larger objects are spooled to a temp file.
	RetryBufferMaxMemoryBytes int64

	Sharding ShardingConfig
}

func DefaultConfig

func DefaultConfig() Config

type CopyGate

type CopyGate interface {
	// Do runs fn under the gate for the named stage. Implementations must call
	// fn exactly once on the success path and propagate its error.
	Do(ctx context.Context, stage string, fn func(context.Context) error) error
}

CopyGate wraps sequential copy phases so callers can acquire and release concurrency permits per phase. A nil gate runs each phase directly (callers that hold an outer token, or ungated library use).

Library-first (ADR-0006): both the pkg/reflow engine and the CLI pool pass the same gate type so stage boundaries stay identical.

type CopyReceipt

type CopyReceipt struct {
	UploadResult
	SourceLastModified time.Time
}

CopyReceipt describes an acknowledged streamed write, not independent destination read-back verification. Unknown provider handles remain empty.

func CopyObjectWithReceipt

func CopyObjectWithReceipt(ctx context.Context, src, dst provider.Provider, srcKey, dstKey string, expectedSize int64, opts CopyReceiptOptions) (CopyReceipt, error)

CopyObjectWithReceipt streams an object using the same bounded upload and phase-gate paths as CopyObject. It never issues a HEAD to fill receipt fields.

type CopyReceiptOptions

type CopyReceiptOptions struct {
	Upload   UploadOptions
	Revision *provider.SourceRevision
	Gate     CopyGate
}

CopyReceiptOptions preserves revision admission, write preconditions and phase budgets while requesting the write's payload receipt.

type DedupConfig

type DedupConfig struct {
	Enabled  bool
	Strategy string // etag | key | none
}

type PathTemplate

type PathTemplate struct {
	// contains filtered or unexported fields
}

PathTemplate is a minimal key mapping template.

Supported placeholders: - `{filename}`: final path segment - `{dir[n]}`: nth directory component (0-based) - `{key}`: full source key

This intentionally stays simple for v0.1.x.

func CompilePathTemplate

func CompilePathTemplate(template string) (*PathTemplate, error)

CompilePathTemplate parses a template string into a PathTemplate.

func (*PathTemplate) Apply

func (t *PathTemplate) Apply(sourceKey string) (string, error)

type ReflowCapture

type ReflowCapture struct {
	// contains filtered or unexported fields
}

ReflowCapture applies a rewrite-from template to a source key and returns the captured variables without rendering a destination template.

func CompileReflowCapture

func CompileReflowCapture(fromTemplate string) (*ReflowCapture, error)

func (*ReflowCapture) Apply

func (r *ReflowCapture) Apply(sourceKey string) (map[string]string, error)

func (*ReflowCapture) CaptureNames

func (r *ReflowCapture) CaptureNames() []string

type ReflowRewrite

type ReflowRewrite struct {
	// contains filtered or unexported fields
}

ReflowRewrite maps a source key to a destination relative key.

The rewrite is a simple segment matcher/renderer: - Templates are split on '/'. - In the from template, literal segments must match exactly. - Placeholders in the from template capture one segment or one segment substring: {var}, prefix-{var}-suffix - The special placeholder {_} captures and ignores a segment. - In the to template, {var} renders the captured value, optionally with a literal prefix/suffix in the same segment.

Each segment may contain at most one placeholder.

func CompileReflowRewrite

func CompileReflowRewrite(fromTemplate, toTemplate string) (*ReflowRewrite, error)

func (*ReflowRewrite) Apply

func (r *ReflowRewrite) Apply(sourceKey string) (destRelKey string, vars map[string]string, err error)

func (*ReflowRewrite) ApplyWithVars

func (r *ReflowRewrite) ApplyWithVars(sourceKey string, extraVars map[string]string) (destRelKey string, vars map[string]string, err error)

ApplyWithVars applies the rewrite and allows callers to provide additional variables.

extraVars override captured variables when a key is present in both maps.

type ShardingConfig

type ShardingConfig struct {
	Enabled         bool
	Depth           int
	MaxShards       int
	ListConcurrency int
	Delimiter       string
}

type SizeMismatchError

type SizeMismatchError struct {
	Key      string
	Expected int64
	Got      int64
}

SizeMismatchError indicates the object size changed between enumeration (list/index) and content retrieval.

This is best-effort validation (validate=size) intended to fail early before deeper pipeline work (buffering/spooling/retries).

It does not eliminate TOCTOU races.

func (*SizeMismatchError) Error

func (e *SizeMismatchError) Error() string

type Summary

type Summary struct {
	ObjectsListed      int64
	ObjectsMatched     int64
	ObjectsTransferred int64
	BytesTransferred   int64
	Errors             int64
	Duration           time.Duration
}

type Transfer

type Transfer struct {
	// contains filtered or unexported fields
}

func New

func New(src provider.Provider, dst provider.Provider, matcher *match.Matcher, writer output.Writer, jobID string, cfg Config) *Transfer

func (*Transfer) Run

func (t *Transfer) Run(ctx context.Context) (*Summary, error)

type UploadOptions

type UploadOptions struct {
	PartSizeBytes         int64
	MultipartThreshold    int64
	MultipartThresholdSet bool
	RetryBufferBytes      int64
	TempDir               string
	Precondition          provider.PutPrecondition
	PutOptions            provider.PutOptions
	Progress              func(context.Context, UploadProgress) error
}

type UploadProgress

type UploadProgress struct {
	Key        string
	UploadID   string
	PartNumber int32
	PartBytes  int64
	Bytes      int64
	Status     string
}

type UploadResult

type UploadResult struct {
	Bytes   int64
	SHA256  string
	ETag    string
	Version string
	Mode    string
}

func UploadFile

func UploadFile(ctx context.Context, putter provider.ObjectPutter, key string, path string, opts UploadOptions) (UploadResult, error)

func UploadReader

func UploadReader(ctx context.Context, putter provider.ObjectPutter, key string, r io.Reader, opts UploadOptions) (UploadResult, error)

func UploadReaderWithSize

func UploadReaderWithSize(ctx context.Context, putter provider.ObjectPutter, key string, r io.Reader, size int64, opts UploadOptions) (UploadResult, error)

type UploadSession

type UploadSession struct {
	// contains filtered or unexported fields
}

func NewUploadSession

func NewUploadSession(ctx context.Context, putter provider.ObjectPutter, key string, opts UploadOptions) (*UploadSession, error)

func (*UploadSession) Abort

func (s *UploadSession) Abort(ctx context.Context) error

func (*UploadSession) Close

func (s *UploadSession) Close(ctx context.Context) (UploadResult, error)

func (*UploadSession) Write

func (s *UploadSession) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL