service

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 39 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ParamsType  = "params"
	FormsType   = "forms"
	HeadersType = "headers"
	QueryType   = "query"
)

Variables

View Source
var (
	// ErrArchiveDisabled means no AWS credentials were configured. This is a
	// normal state, not a failure: the project is deployed by people who run it
	// on MinIO alone, and for them the archive simply does not exist. Callers
	// must treat it as "skip", never as an error to report.
	ErrArchiveDisabled = errors.New("archive: not configured")

	// ErrArchiveNotFound means the object has no archived copy. For the retention
	// job this is the signal to keep the MinIO copy rather than delete it.
	ErrArchiveNotFound = errors.New("archive: object not found")

	// ErrArchiveNotInScope means the deployment archives some buckets but not
	// this one. Like ErrArchiveDisabled it describes a configuration, not a
	// fault, and callers must treat it as "skip" rather than report it.
	ErrArchiveNotInScope = errors.New("archive: bucket is not in the archive scope")

	// ErrArchiveDestinationPerBucket means there is no single destination to
	// check: under bucket-name parity each local bucket maps to its own S3
	// bucket, and which ones exist is not knowable before they are used.
	ErrArchiveDestinationPerBucket = errors.New("archive: destination is per bucket, checked on first use")
)
View Source
var (
	ErrNoToken           = errors.New("no token provided")
	ErrInvalidAuthFormat = errors.New("invalid authorization format")
	ErrInvalidToken      = errors.New("invalid token")
)

Auth failures are deliberately coarse: the caller learns that the credential was not accepted and nothing about which part of it failed.

View Source
var ErrCacheMiss = errors.New("cache: key not found")

ErrCacheMiss reports that a key simply is not in the cache. It is the single most common outcome on this service (the rate limiter looks up a key per client IP, and the first request from any IP misses by definition), so callers need to be able to tell it apart from Redis actually being broken. Match it with errors.Is.

Functions

func ApplyImagickResourceLimits added in v1.7.0

func ApplyImagickResourceLimits()

ApplyImagickResourceLimits sets process-wide ImageMagick resource limits so a decompression bomb or an oversized resize target cannot exhaust host memory, disk or CPU. MagickSetResourceLimit is global despite hanging off a wand. Must be called once after imagick.Initialize(). Defaults are generous enough that no legitimate stored image starts failing; when a limit is exceeded the resize paths already fall back to serving the original bytes.

Unit note: the C API takes bytes for MEMORY/MAP/DISK, pixels for AREA and seconds for TIME. We log the effective values so they can be eyeballed on the first boot.

The thread limit is the one that decides whether this process stays inside its memory budget at all. ImageMagick defaults to one OpenMP thread per core, and its pixel buffers come from malloc rather than the Go heap: glibc opens a per-thread arena and effectively never returns that memory to the OS, so RSS ratchets upward burst after burst until the host OOM-kills the process. A production deployment on 8 cores held 2.5-2.9 GB per replica at idle with the default; capping threads at 2 brought that to ~200 MB. See also MALLOC_ARENA_MAX in the dockerfile, which bounds the same growth from the allocator side, and the MAGICK_THREAD_LIMIT export in cmd/main.go, which has to happen before genesis because that is when the OpenMP pool is built.

func BearerToken added in v1.8.0

func BearerToken(r *http.Request) (string, error)

BearerToken extracts the raw bearer credential from the Authorization header.

func ByteToStream

func ByteToStream(data []byte) io.Reader

func CheckToken

func CheckToken(r *http.Request) error

CheckToken authenticates a request against the general TOKEN only. A bucket-scoped token is rejected here, which is what gates the operator routes (/aws, /minio, /monitor, /metrics): those act on any bucket or expose service-wide data, so a credential limited to a single bucket must not reach them. Bucket-aware routes use ResolvePrincipal instead.

func CreateFile

func CreateFile(file []byte) (*os.File, error)

func DownloadFile

func DownloadFile(filepath string, url string) error

func GetWidthAndHeight

func GetWidthAndHeight(r *http.Request, requestType string) (bool, uint, uint)

func HasUnsafeObjectKey added in v1.7.0

func HasUnsafeObjectKey(key string) bool

HasUnsafeObjectKey reports whether an object key is empty or contains a ".." path segment. Object stores treat keys opaquely, but rejecting traversal-like segments keeps read/delete keys aligned with the sanitized keys upload writes and avoids surprises if a key is ever mapped onto a filesystem path.

func ImageToByte

func ImageToByte(img string) []byte

func ImagickThreadLimit added in v1.10.0

func ImagickThreadLimit() int

ImagickThreadLimit reports the configured OpenMP thread cap. It lives here rather than being read twice because two places need the same number: the MAGICK_THREAD_LIMIT export that has to run before genesis, and the resource limit applied after it. A value below 1 would leave ImageMagick to pick its own default, which is the behaviour this exists to prevent.

func IsImageFile

func IsImageFile(filename string) bool

func IsInt

func IsInt(one, two string) bool

func MinioClient

func MinioClient() *minio.Client

func RandomName

func RandomName(length int) string

func RatioWidthHeight

func RatioWidthHeight(width, height, targetWidth, targetHeight uint) (uint, uint)

func ReadEnvAndSet added in v1.2.2

func ReadEnvAndSet() error

func Response

func Response(w http.ResponseWriter, code int, success bool, message string, data any) error

Response writes the envelope every JSON endpoint answers with. It returns nil so handlers can end with `return service.Response(...)`.

func SanitizeObjectName added in v1.6.4

func SanitizeObjectName(objectName string) string

SanitizeObjectName removes or replaces unsupported characters for MinIO object names

func SetWidthToHeight

func SetWidthToHeight(width, height string) (string, string)

func StreamToByte

func StreamToByte(stream io.Reader) []byte

func TokenValid added in v1.7.0

func TokenValid(clientToken string) bool

TokenValid reports whether clientToken matches the configured server TOKEN using a constant-time comparison. An empty token on either side is never valid (an empty server token must not authenticate an empty client token). Use this where the token arrives outside the Authorization header, e.g. a WebSocket query parameter that browsers cannot set as a header.

func WithPrincipal added in v1.13.0

func WithPrincipal(r *http.Request, p Principal) *http.Request

WithPrincipal returns r carrying p for downstream handlers.

Types

type Archive added in v1.10.0

type Archive interface {
	// Enabled reports whether archiving is configured. Everything else on this
	// interface returns ErrArchiveDisabled when it is false.
	Enabled() bool

	// Put writes an object to the archive tier.
	Put(ctx context.Context, bucket, object string, body io.Reader) error

	// Open returns the archived object's contents and size. The caller owns the
	// reader and must close it.
	Open(ctx context.Context, bucket, object string) (io.ReadCloser, int64, error)

	// Stat returns the archived object's size without transferring it. This is
	// the proof the retention job requires before deleting the MinIO copy.
	Stat(ctx context.Context, bucket, object string) (int64, error)

	// Reachable reports whether objects from this local bucket have somewhere to
	// go: it resolves the destination and checks it exists and is writable.
	//
	// Callers use it to fail once instead of per object. Nothing creates the
	// destination automatically, so without this a misconfigured deployment
	// discovers the problem one failed upload at a time, several million times.
	Reachable(ctx context.Context, bucket string) error

	// InScope reports whether this bucket is archived at all. Callers use it to
	// skip work rather than to handle a rejection: a bucket left out of the scope
	// is not an error anywhere.
	InScope(bucket string) bool

	// VerifyDestination makes one real call to the archive to find out whether
	// the credentials work and the destination exists. It answers the question a
	// list of known placeholder strings cannot: "are these credentials wrong",
	// as opposed to "were they never filled in".
	//
	// Returns ErrArchiveDisabled when there is nothing to check, and
	// ErrArchiveDestinationPerBucket when the layout has no single destination to
	// test up front.
	VerifyDestination(ctx context.Context) error

	// Walk enumerates what the archive holds for a local bucket, translating
	// archive locations back into local object keys so the caller never has to
	// know which layout is in use. Returning an error from fn stops the walk.
	//
	// Not gated by scope, for the same reason reads are not: the case this exists
	// for includes pulling back a bucket that was removed from the scope.
	Walk(ctx context.Context, bucket string, fn func(key string, size int64) error) error
}

Archive is the cold half of the storage story: MinIO holds what is recent, the archive holds everything, and the two are addressed by the same (bucket, object) pair so nothing has to be indexed to find an old file again.

Why this exists as its own interface rather than more methods on AwsService: the handlers do not care that the archive happens to be S3. They care whether archiving is on, and how to read or write one object. Keeping that surface to four methods is also what makes it cheap to fake in tests, where AwsService's sixteen methods are not.

func NewArchive added in v1.10.0

func NewArchive(aws AwsService) Archive

NewArchive builds the archive from the environment. The enabled decision is made once, here, rather than per request: whether this deployment has an archive is a property of the deployment, and re-deciding it per upload would let a transient credential problem silently drop objects that the retention job later expects to find.

type AwsService

type AwsService interface {
	GlacierVaultList() *glacier.ListVaultsOutput
	GlacierUploadArchive(vaultName string, fileBuffer []byte) (*glacier.UploadArchiveOutput, error)
	GlacierInitiateRetrieval(vaultName, archiveId string, retrievalType string) (*glacier.InitiateJobOutput, error)
	GlacierListJobs(vaultName string) (*glacier.ListJobsOutput, error)
	GlacierGetJobOutput(vaultName, jobId string) (*glacier.GetJobOutputOutput, error)
	GlacierDescribeJob(vaultName, jobId string) (*glacier.DescribeJobOutput, error)
	GlacierInventoryRetrieval(vaultName string) (*glacier.InitiateJobOutput, error)
	GlacierDownloadToMinio(vaultName, jobId, targetBucket, targetPath string) error
	GlacierDownloadToLocal(vaultName, jobId, localPath string) error
	S3PutObject(ctx context.Context, bucketName string, objectName string, fileBuffer io.Reader) (*manager.UploadOutput, error)
	S3HeadObject(ctx context.Context, bucketName, objectName string) (*s3.HeadObjectOutput, error)
	S3HeadBucket(ctx context.Context, bucketName string) error
	S3ListObjects(ctx context.Context, bucketName, prefix string, fn func(key string, size int64) error) error
	S3GetObject(ctx context.Context, bucketName, objectName string) (*s3.GetObjectOutput, error)
	ListBuckets() ([]s3types.Bucket, error)
	BucketExists(bucketName string) bool
	DeleteObjects(bucketName string, objectKeys []string) error
	IsConnected() bool
}

func NewAwsService

func NewAwsService() AwsService

type CacheService added in v1.5.0

type CacheService interface {
	Get(key string) ([]byte, error)
	Set(key string, value []byte, expiration time.Duration) error
	Delete(key string) error
	GetResizedImage(bucket, path string, width, height uint) ([]byte, error)
	SetResizedImage(bucket, path string, width, height uint, data []byte) error
	FlushAll() error
	Close() error
}

func NewCacheService added in v1.5.0

func NewCacheService() (CacheService, error)

NewCacheService builds the cache client. It returns a usable CacheService even when the connection cannot be established, alongside an error describing why.

The two return values are independent on purpose. A nil service is reserved for configuration that can never work (an unparseable REDIS_URL); a live server that is merely unreachable right now yields a usable service and an error. Callers should log the error and keep the service.

This matters because the client does not dial here. go-redis connects lazily per command from its own pool and reconnects on its own, so a client whose first ping failed still works the moment Redis accepts connections. Discarding it converted a few seconds of RDB loading into a process that ran without a cache until someone restarted it, which is exactly what happened in production on 2026-08-03: two of three replicas came up cacheless and stayed that way.

type ImageService added in v1.5.0

type ImageService struct {
	MinioClient *minio.Client
}

func (*ImageService) GetImage added in v1.5.0

func (s *ImageService) GetImage(bucket, objectName string, width, height int) ([]byte, error)

GetImage gets an image from storage and optionally resizes it

func (*ImageService) GetImageInfo added in v1.5.0

func (s *ImageService) GetImageInfo(data []byte) (width uint, height uint, format string, err error)

GetImageInfo returns width, height and format of an image

func (*ImageService) ImagickFormat added in v1.5.0

func (s *ImageService) ImagickFormat(image []byte) (error, string)

func (*ImageService) ImagickGetWidthHeight added in v1.5.0

func (s *ImageService) ImagickGetWidthHeight(image []byte) (error, uint, uint)

func (*ImageService) ImagickResize added in v1.5.0

func (s *ImageService) ImagickResize(image []byte, targetWidth, targetHeight uint) []byte

func (*ImageService) IsImageFile added in v1.5.0

func (s *ImageService) IsImageFile(data []byte) bool

IsImageFile checks if the file is a valid image by examining its content (magic bytes)

func (*ImageService) IsResizable added in v1.5.0

func (s *ImageService) IsResizable(data []byte) bool

IsResizable checks if the file is a valid image that can be resized

func (*ImageService) OptimizeImage added in v1.7.0

func (s *ImageService) OptimizeImage(data []byte, opts OptimizeOptions) ([]byte, uint, uint, error)

OptimizeImage re-encodes a resizable raster image in a single decode/encode pass: optional downscale (explicit target dims win over MaxDimension), metadata strip, and per-format quality. It returns the encoded bytes and the final dimensions.

Inputs that are not resizable rasters (per IsResizable) and animated-capable GIFs are returned unchanged with a nil error, so callers can treat any success as "safe to store". GIF is passed through because a single-frame resize would flatten animations.

func (*ImageService) ProcessImage added in v1.5.0

func (s *ImageService) ProcessImage(data []byte) ([]byte, error)

ProcessImage processes an image (resize, optimize, etc.). Retained for backward compatibility; it is a thin wrapper over OptimizeImage with the original caps and per-format quality values.

func (*ImageService) ResizeImage added in v1.5.0

func (s *ImageService) ResizeImage(data []byte, width, height int) ([]byte, error)

ResizeImage resizes an image to the specified dimensions

type MinioStore added in v1.10.0

type MinioStore struct {
	*minio.Client
}

MinioStore adapts *minio.Client to ObjectStore. Embedding supplies every method but OpenObject, which narrows the concrete return type to an interface.

func (MinioStore) OpenObject added in v1.10.0

func (m MinioStore) OpenObject(ctx context.Context, bucket, object string) (io.ReadCloser, error)

type ObjectStore added in v1.10.0

type ObjectStore interface {
	ListBuckets(ctx context.Context) ([]minio.BucketInfo, error)
	ListObjects(ctx context.Context, bucket string, opts minio.ListObjectsOptions) <-chan minio.ObjectInfo
	StatObject(ctx context.Context, bucket, object string, opts minio.StatObjectOptions) (minio.ObjectInfo, error)
	RemoveObject(ctx context.Context, bucket, object string, opts minio.RemoveObjectOptions) error
	PutObject(ctx context.Context, bucket, object string, reader io.Reader, size int64, opts minio.PutObjectOptions) (minio.UploadInfo, error)
	MakeBucket(ctx context.Context, bucket string, opts minio.MakeBucketOptions) error
	BucketExists(ctx context.Context, bucket string) (bool, error)

	// OpenObject reads an object's contents. It is deliberately not GetObject:
	// the minio-go signature returns the concrete *minio.Object, which cannot be
	// constructed by a test, and this is the one method a fake has to provide.
	OpenObject(ctx context.Context, bucket, object string) (io.ReadCloser, error)
}

ObjectStore is the slice of MinIO that the tiering and retention paths use. It exists so the code allowed to delete user data can be tested without a running MinIO. MinioStore adapts the real client to it.

type OptimizeOptions added in v1.7.0

type OptimizeOptions struct {
	MaxDimension uint // cap on the longest side; 0 = no cap
	TargetWidth  uint // explicit dimensions; when either is set they override MaxDimension
	TargetHeight uint
	JPEGQuality  uint
	PNGQuality   uint // lossless: ImageMagick maps PNG "quality" to zlib level/filter
	WebPQuality  uint
	Strip        bool // remove metadata (EXIF/ICC/etc.)
}

OptimizeOptions controls a single-pass re-encode used to shrink an uploaded image without visible quality loss.

func DefaultOptimizeOptions added in v1.7.0

func DefaultOptimizeOptions() OptimizeOptions

DefaultOptimizeOptions builds the opt-in upload optimization options from the OPTIMIZE_* environment variables, falling back to visually-lossless defaults.

type Principal added in v1.8.0

type Principal struct {
	// Scoped is true when the caller presented a bucket-scoped token. The general
	// TOKEN yields the zero Principal, which is not restricted to one bucket.
	Scoped bool
	// Bucket is the single bucket a scoped principal may write to. Empty when
	// Scoped is false.
	Bucket string
}

Principal is the identity behind an authenticated request.

func PrincipalFrom added in v1.8.0

func PrincipalFrom(r *http.Request) Principal

PrincipalFrom returns the principal stored by the auth middleware. A missing principal yields the zero value, i.e. the unrestricted general token, so a route wired without the bucket-aware middleware keeps its previous behaviour.

func ResolvePrincipal added in v1.8.0

func ResolvePrincipal(r *http.Request) (Principal, error)

ResolvePrincipal authenticates a request against either the general TOKEN or a bucket-scoped token.

Order matters. The general TOKEN is compared first and as a whole string, because a general token is free to contain a ':' and must never be reinterpreted as a "<bucket>:<secret>" pair. Parsing first would break every existing deployment whose TOKEN happens to contain a colon.

For a bucket-scoped token the bucket prefix is attacker-controlled input and grants nothing on its own: the secret is compared, in constant time, against the entry for that exact bucket and no other.

type Retention added in v1.10.0

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

Retention frees local disk by removing objects that the archive already holds.

The rule the whole design rests on: an object is deleted from MinIO only after the archive has been asked for it by name and has answered with a matching size. Age alone never authorises a delete. That ordering is what makes the window safe to shorten and the job safe to run unattended, and it is why an upload whose archive write failed simply keeps occupying disk instead of disappearing.

The job never deletes from the archive. Removing an object for good is a separate, deliberate act (see DeleteImage), not something a scheduled sweep should ever do.

func NewRetention added in v1.10.0

func NewRetention(store ObjectStore, archive Archive) *Retention

NewRetention reads the schedule from the environment.

Both switches default to the cautious setting: the job is off unless asked for, and the first time it is asked for it only reports. Anything else would mean that pulling a new version of this project could start deleting a stranger's files on a timer.

func (*Retention) Enabled added in v1.10.0

func (r *Retention) Enabled() bool

Enabled reports whether the job will do anything. Retention without an archive is just deletion, so the archive being off disables it regardless of RETENTION_ENABLED.

func (*Retention) RunOnce added in v1.10.0

func (r *Retention) RunOnce(ctx context.Context, now time.Time) (RetentionStats, error)

RunOnce performs a single sweep. now is a parameter rather than a call to time.Now so the age boundary can be tested exactly.

func (*Retention) Start added in v1.10.0

func (r *Retention) Start(ctx context.Context)

Start runs the job on its interval until ctx is cancelled. It deliberately does not sweep immediately on boot: a restart loop would otherwise turn into a delete loop, and the first pass after a deploy is the one most likely to be running with a misconfigured window.

type RetentionStats added in v1.10.0

type RetentionStats struct {
	Scanned      int
	Eligible     int
	Deleted      int
	BytesFreed   int64
	NotArchived  int
	SizeMismatch int
	Errors       int
}

RetentionStats is the outcome of one pass, both for the log line and for tests to assert against.

type StatsService added in v1.5.0

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

func NewStatsService added in v1.5.0

func NewStatsService() *StatsService

func (*StatsService) AddUploadBytes added in v1.5.0

func (s *StatsService) AddUploadBytes(bytes int64)

func (*StatsService) DecrementActiveUploads added in v1.5.0

func (s *StatsService) DecrementActiveUploads()

func (*StatsService) GetActiveUploads added in v1.5.0

func (s *StatsService) GetActiveUploads() int

func (*StatsService) GetCPUUsage added in v1.5.0

func (s *StatsService) GetCPUUsage() float64

func (*StatsService) GetCacheHitRate added in v1.5.0

func (s *StatsService) GetCacheHitRate() float64

func (*StatsService) GetDiskUsage added in v1.5.0

func (s *StatsService) GetDiskUsage() map[string]int64

func (*StatsService) GetMemoryUsage added in v1.5.0

func (s *StatsService) GetMemoryUsage() float64

func (*StatsService) GetRecentErrors added in v1.5.0

func (s *StatsService) GetRecentErrors() []string

func (*StatsService) GetUploadSpeed added in v1.5.0

func (s *StatsService) GetUploadSpeed() float64

func (*StatsService) IncrementActiveUploads added in v1.5.0

func (s *StatsService) IncrementActiveUploads()

func (*StatsService) IncrementCacheHit added in v1.5.0

func (s *StatsService) IncrementCacheHit()

func (*StatsService) IncrementCacheMiss added in v1.5.0

func (s *StatsService) IncrementCacheMiss()

func (*StatsService) LogError added in v1.5.0

func (s *StatsService) LogError(err string)

type TierOutcome added in v1.10.0

type TierOutcome string

TierOutcome is what happened to one object.

const (
	// TierArchived: copied to the archive and removed from MinIO.
	TierArchived TierOutcome = "archived"
	// TierArchivedKept: copied to the archive, local copy deliberately kept.
	TierArchivedKept TierOutcome = "archived_kept"
	// TierAlreadyArchived: the archive already held it at the right size.
	TierAlreadyArchived TierOutcome = "already_archived"
	// TierNotInScope: the deployment archives some buckets, but not this one.
	TierNotInScope TierOutcome = "not_in_scope"
	// TierRestored: copied back from the archive into local storage.
	TierRestored TierOutcome = "restored"
	// TierAlreadyLocal: local storage already had it at the right size.
	TierAlreadyLocal TierOutcome = "already_local"
	// TierNotFound: neither tier has it.
	TierNotFound TierOutcome = "not_found"
	// TierFailed: something went wrong; the local copy was not touched.
	TierFailed TierOutcome = "failed"
)

type TierResult added in v1.10.0

type TierResult struct {
	Key     string
	Outcome TierOutcome
	Size    int64
	Err     error
}

TierResult reports one object's fate.

type Tiering added in v1.10.0

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

Tiering moves objects between the local store and the archive.

It owns the one rule that must not be duplicated anywhere: a local copy is removed only after the archive has been asked for that object by name and has answered with a matching size. Both the scheduled sweep and the on-demand API go through here, so there is a single place where that decision is made and a single place to get it wrong.

func NewTiering added in v1.10.0

func NewTiering(store ObjectStore, archive Archive) *Tiering

func (*Tiering) ArchiveKnownObject added in v1.10.0

func (t *Tiering) ArchiveKnownObject(ctx context.Context, bucket, key string, localSize int64, evict bool) TierResult

ArchiveKnownObject is ArchiveObject for a caller that already knows the object's local size, which lets it skip the StatObject round trip.

This is not a micro-optimisation at the scale it exists for: a backfill walks millions of objects and gets each one's size from the listing it is already paginating through, so re-statting every one of them would double the calls into local storage for information already in hand.

func (*Tiering) ArchiveObject added in v1.10.0

func (t *Tiering) ArchiveObject(ctx context.Context, bucket, key string, evict bool) TierResult

ArchiveObject copies one object to the archive and, when evict is set, removes the local copy once the archive is verified to hold it.

This is what the on-demand endpoint calls. Age never enters into it: only the application that owns the content knows when it stops needing to be local, and on a CDN that objects were migrated into, the stored timestamps describe the migration rather than the content.

Idempotent by construction. Calling it again on an already-evicted object finds nothing locally, confirms the archive still has it, and reports TierAlreadyArchived rather than an error.

func (*Tiering) Enabled added in v1.10.0

func (t *Tiering) Enabled() bool

Enabled reports whether tiering can do anything at all.

func (*Tiering) EnsureBucket added in v1.10.0

func (t *Tiering) EnsureBucket(ctx context.Context, bucket string) error

EnsureBucket creates the local bucket if it is missing, so a restore into a deployment whose buckets were removed still has somewhere to land.

func (*Tiering) InScope added in v1.10.0

func (t *Tiering) InScope(bucket string) bool

InScope reports whether this bucket is archived on this deployment.

func (*Tiering) RestoreObject added in v1.10.0

func (t *Tiering) RestoreObject(ctx context.Context, bucket, key string, archivedSize int64) TierResult

RestoreObject copies an object back out of the archive into local storage.

This is the way out. A deployment that adopted cold storage and later wants to stop using it needs to be able to pull everything home; without that, turning the archive on would be a one-way door, and a one-way door is a bad thing to ask an operator to walk through.

It never deletes from the archive. Emptying S3 is a separate decision, made with the AWS console or CLI once the operator is satisfied that local storage holds everything, and deliberately not automated here: a bug in this direction would destroy the only remaining copy.

Not gated by ARCHIVE_ONLY_BUCKETS, because pulling back a bucket that was removed from the scope is exactly one of the cases this exists for.

func (*Tiering) VerifyArchived added in v1.10.0

func (t *Tiering) VerifyArchived(ctx context.Context, bucket, key string, localSize int64) (bool, VerifyReason, error)

VerifyArchived answers the only question that authorises a delete: is this exact object, at this exact size, already in the archive?

The size comparison is not redundant with existence. An earlier version of the archive upload handed S3 a reader that the MinIO upload had already drained, so the archive filled with zero-byte objects that existed by every other measure. Comparing sizes is what turns "there is something under that key" into "the object is safe to remove locally".

Every failure mode returns false. An archive that cannot be reached is not an archive that is empty, and a transient outage must postpone a delete rather than license it.

func (*Tiering) Walk added in v1.10.0

func (t *Tiering) Walk(ctx context.Context, bucket string, fn func(key string, size int64) error) error

Walk exposes the archive listing to callers that already hold a Tiering.

type VerifyReason added in v1.10.0

type VerifyReason string

VerifyReason explains a verification result in terms the caller can log or return without re-deriving it.

const (
	VerifyOK           VerifyReason = "ok"
	VerifyNotArchived  VerifyReason = "not_archived"
	VerifySizeMismatch VerifyReason = "size_mismatch"
	VerifyError        VerifyReason = "error"
)

Jump to

Keyboard shortcuts

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