objectstore

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 3 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 DefaultCacheMaxAge = 30 * time.Second

DefaultCacheMaxAge is how long a cached instance is used before it is checked against the bucket again, unless WithCacheRevalidation or WithoutCacheRevalidation says otherwise.

Typically, engine instances that share the same object storage backend will be running in CI environments that get fresh state on every run, for the more unusual case where long-lived engine instances share an object storage backend, deployments for the same instances do not run in parallel, so subsequent runs are usually minutes apart and 30 seconds is enough to reduce subsequent reads throughout a single deployment process.

Variables

This section is empty.

Functions

func ClaimForDeployment

func ClaimForDeployment(
	ctx context.Context,
	svc Service,
	keys statestore.KeyBuilder,
	st *statestore.State,
	clock commoncore.Clock,
	instanceID string,
	expectedVersion int64,
	newStatus core.InstanceStatus,
) (int64, error)

ClaimForDeployment performs an atomic compare-and-swap on a single instance object in the Service. On success the instance's version is bumped, its status is set to newStatus, and the in-memory State is refreshed.

The CAS bypasses statestore.Storage deliberately as statestore.Storage has no ETag awareness, and the conditional write is what makes this safe for concurrent executions such as CI/CD runs sharing a bucket storage backend.

Returns state.InstanceNotFoundError when the instance object does not exist, and state.ErrVersionConflict when the persisted version does not match expectedVersion (either caught cheaply before the write, or via a 412 on IfMatch).

func InitialiseAndClaim

func InitialiseAndClaim(
	ctx context.Context,
	svc Service,
	keys statestore.KeyBuilder,
	st *statestore.State,
	clock commoncore.Clock,
	instanceState state.InstanceState,
	newStatus core.InstanceStatus,
) (int64, error)

InitialiseAndClaim performs an atomic create-if-absent of a new instance object at version 1 with the given status. The conditional Put with IfNoneMatch: "*" is what serialises concurrent first-deploys of the same instance ID sharing a bucket.

When the instance has a name, its name-lookup record is reserved first (see reserveName), so LookupInstanceIDByName can resolve under ModeLazy without enumerating the instances prefix. A name held by another live instance is mapped to state.ErrInstanceAlreadyExists; the caller can distinguish by a subsequent read if needed. If the instance object cannot be written at all, a reservation this call made is given back.

An instance created with resources or links is first written without them, then their ID records, then the whole instance, so no resource or link is ever stored without its record. An earlier instance with this ID whose removal was interrupted reads as not found everywhere else, so its removal is finished first (see finishRemoval) and the ID used again.

Returns state.ErrInstanceAlreadyExists when the instance object already exists (412 on IfNoneMatch).

func NewAuthFailed

func NewAuthFailed(message string) error

NewAuthFailed returns an Error with ReasonCodeAuthFailed.

func NewObjectNotFound

func NewObjectNotFound(message string) error

NewObjectNotFound returns an Error with ReasonCodeObjectNotFound. Exported so provider-specific Service implementations can construct the canonical error shape from their SDK-native not-found signals.

func NewPreconditionFailed

func NewPreconditionFailed(message string) error

NewPreconditionFailed returns an Error with ReasonCodePreconditionFailed. Used by provider Services when IfMatch / IfNoneMatch conditional writes fail.

func NewRateLimited

func NewRateLimited(message string) error

NewRateLimited returns an Error with ReasonCodeRateLimited.

Types

type DeleteOptions added in v0.12.0

type DeleteOptions struct {
	// IfMatch is used to specify that the Delete operation should only succeed
	// if the ETag matches the provided value. A delete that does not match fails
	// with a precondition failed error and leaves the object in place.
	IfMatch string
}

DeleteOptions defines options for the Delete operation in the object storage service.

type Error

type Error struct {
	ReasonCode ErrorReasonCode
	Err        error
}

Error is a custom error type that provides errors specific to the object store implementation of the object store state container.

func (*Error) Error

func (e *Error) Error() string

type ErrorReasonCode

type ErrorReasonCode string

ErrorReasonCode is an enum of possible error reasons that can be returned by the object store implementation.

const (
	// ErrorReasonCodeObjectNotFound is the error code that is used when
	// an object is not found in the object store.
	ErrorReasonCodeObjectNotFound ErrorReasonCode = "object_not_found"

	// ErrorReasonCodePreconditionFailed is the error code that is used when
	// a precondition for an operation is not met, such as an ETag mismatch.
	ErrorReasonCodePreconditionFailed ErrorReasonCode = "precondition_failed"

	// ErrorReasonCodeAuthFailed is the error code that is used when
	// authentication with the object store fails.
	ErrorReasonCodeAuthFailed ErrorReasonCode = "authentication_failed"

	// ErrorReasonCodeRateLimited is the error code that is used when
	// the object store rate limits the client.
	ErrorReasonCodeRateLimited ErrorReasonCode = "rate_limited"
)

type ListerFrom added in v0.11.0

type ListerFrom interface {
	// ListFrom returns the objects under prefix whose keys sort strictly after
	// startAfter, in the same way List returns those under prefix.
	//
	// Exclusive of startAfter itself, matching S3. A caller wanting a key included
	// passes something that sorts just below it: for keys of the form "<prefix><n>-<id>",
	// passing "<prefix><n>" includes every key for n, since a string sorts before any
	// string it prefixes.
	ListFrom(ctx context.Context, prefix string, startAfter string) ([]*ObjectInfo, error)
}

ListerFrom is implemented by a Service whose backing store can begin a listing at a key instead of returning every key under a prefix.

Separate from Service because stores differ. S3 takes a start key (StartAfter) and Google Cloud Storage takes a start offset, while Azure Blob Storage's flat listing offers only an opaque continuation marker and so cannot. A caller type-asserts for it and falls back to List, rather than every store having to pretend to support it.

type ObjectInfo

type ObjectInfo struct {
	// The key (or name) of the object in the storage service.
	Key string
	// The size of the object in bytes.
	Size int64
	// The ETag of the object, which is typically a hash of the object's content.
	ETag string
	// LastModified is when the object was last written, as the storage service reports it.
	// The leftover-record sweep uses it to leave alone anything written too recently to be
	// judged, such as a record whose instance is still being written.
	LastModified time.Time
}

ObjectInfo contains metadata about an object stored in the object storage service.

type Option

type Option func(*StateContainer)

Option is a type for options that can be passed to LoadStateContainer.

func WithCacheRevalidation added in v0.12.0

func WithCacheRevalidation(maxAge time.Duration) Option

WithCacheRevalidation sets how long a cached instance is used before it is checked against the bucket again (a HEAD request), so that a long-running engine sees changes made by other engines sharing the bucket. A changed instance is reloaded and a removed one dropped. Zero checks on every use. Defaults to DefaultCacheMaxAge.

Writes do not depend on it as every instance write is conditional on the version last read, so a write based on a stale instance is rejected and applied again to the current one.

func WithClock

func WithClock(clock commoncore.Clock) Option

WithClock sets the clock used by the events container, and to timestamp instance name reservations and judge whether an old one was abandoned.

func WithMaxEventPartitionSize

func WithMaxEventPartitionSize(maxEventPartitionSize int64) Option

WithMaxEventPartitionSize sets the maximum size of an event partition file in bytes. See statestore.WithMaxEventPartitionSize.

func WithMaxGuideFileSize

func WithMaxGuideFileSize(maxGuideFileSize int64) Option

WithMaxGuideFileSize sets a guide for the maximum size of a state chunk file in bytes. See statestore.WithMaxGuideFileSize.

func WithRecentlyQueuedEventsThreshold

func WithRecentlyQueuedEventsThreshold(thresholdSeconds int64) Option

WithRecentlyQueuedEventsThreshold sets the threshold in seconds for retrieving recently queued events for a stream when a starting event ID is not provided.

func WithoutCacheRevalidation added in v0.12.0

func WithoutCacheRevalidation() Option

WithoutCacheRevalidation turns off checking cached instances against the bucket, for an engine that has the bucket to itself or is short-lived, such as one started for a CI run. It loads instances fresh, its own writes keep its cache current, and it makes no HEAD requests to revalidate.

type PutOptions

type PutOptions struct {
	// IfNoneMatch is used to specify that the Put operation should only succeed if the object does not exist (ETag "*")
	// or if the ETag does not match the provided value.
	IfNoneMatch string
	// IfMatch is used to specify that the Put operation should only succeed
	// if the ETag matches the provided value.
	IfMatch string
}

PutOptions defines options for the Put operation in the object storage service.

type Service

type Service interface {
	// Get retrieves the object data and its ETag for the given key.
	Get(ctx context.Context, key string) (data []byte, etag string, err error)
	// Put stores the object data with the given key and options, returning the new ETag.
	Put(ctx context.Context, key string, data []byte, opts *PutOptions) (etag string, err error)
	// Delete removes the object associated with the given key, subject to the given
	// options. opts may be nil for an unconditional delete.
	Delete(ctx context.Context, key string, opts *DeleteOptions) error
	// Head retrieves the size and ETag of the object for the given key without fetching the data.
	Head(ctx context.Context, key string) (*ObjectInfo, error)
	// List returns a list of ObjectInfo for objects that match the given prefix.
	List(ctx context.Context, prefix string) ([]*ObjectInfo, error)
}

Service is an interface for interacting with object storage services.

type ServiceLoader

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

ServiceLoader reads entities from the objectstore Service on a State cache miss, and lists categories for whole-category queries. This lets objectstore run under statestore.ModeLazy without bulk-loading the bucket at startup.

func NewServiceLoader

func NewServiceLoader(svc Service, keys statestore.KeyBuilder) *ServiceLoader

func (*ServiceLoader) InstanceVersion added in v0.12.0

func (l *ServiceLoader) InstanceVersion(ctx context.Context, instanceID string) (string, bool, error)

func (*ServiceLoader) ListCleanupOperationIDs added in v0.11.0

func (l *ServiceLoader) ListCleanupOperationIDs(ctx context.Context) ([]string, error)

ListCleanupOperationIDs lists the IDs of every cleanup operation in the bucket.

func (*ServiceLoader) ListInstanceIDs added in v0.11.0

func (l *ServiceLoader) ListInstanceIDs(ctx context.Context) ([]string, error)

ListInstanceIDs lists the IDs of every instance object in the bucket.

func (*ServiceLoader) ListReconciliationResultIDs added in v0.11.0

func (l *ServiceLoader) ListReconciliationResultIDs(ctx context.Context) ([]string, error)

ListReconciliationResultIDs lists the IDs of every reconciliation result in the bucket.

func (*ServiceLoader) LoadAuditRecord added in v0.11.0

func (l *ServiceLoader) LoadAuditRecord(
	ctx context.Context,
	id string,
) (*manage.AuditRecord, bool, error)

LoadAuditRecord reads one record by ID.

The key leads with the record's timestamp, which a caller holding only an ID does not have, so the key is found by listing the trail's prefix rather than constructed. That is a listing of keys and a single read, not a read of the trail.

func (*ServiceLoader) LoadChangeset

func (l *ServiceLoader) LoadChangeset(
	ctx context.Context,
	id string,
) (*manage.Changeset, bool, error)

func (*ServiceLoader) LoadCleanupOperation

func (l *ServiceLoader) LoadCleanupOperation(
	ctx context.Context,
	id string,
) (*manage.CleanupOperation, bool, error)

func (*ServiceLoader) LoadEvent

func (l *ServiceLoader) LoadEvent(_ context.Context, _ string) (*manage.Event, bool, error)

LoadEvent returns (nil, false, nil). Events are partition-keyed rather than per-ID; resolving a single event by ID would require reading the relevant partition. Event lookup is not a hot path under ModeLazy; if it becomes one, add an event-ID index.

func (*ServiceLoader) LoadInstance

func (*ServiceLoader) LoadInstanceIDByName

func (l *ServiceLoader) LoadInstanceIDByName(
	ctx context.Context,
	name string,
) (string, bool, error)

func (*ServiceLoader) LoadLinkDrift

func (l *ServiceLoader) LoadLinkDrift(
	ctx context.Context,
	id string,
) (*state.LinkDriftState, bool, error)

func (*ServiceLoader) LoadLinkInstanceID added in v0.11.0

func (l *ServiceLoader) LoadLinkInstanceID(
	ctx context.Context,
	linkID string,
) (string, bool, error)

LoadLinkInstanceID reads a link's ID record, which says which instance to load.

func (*ServiceLoader) LoadReconciliation

func (l *ServiceLoader) LoadReconciliation(
	ctx context.Context,
	id string,
) (*manage.ReconciliationResult, bool, error)

func (*ServiceLoader) LoadResourceDrift

func (l *ServiceLoader) LoadResourceDrift(
	ctx context.Context,
	id string,
) (*state.ResourceDriftState, bool, error)

func (*ServiceLoader) LoadResourceInstanceID added in v0.11.0

func (l *ServiceLoader) LoadResourceInstanceID(
	ctx context.Context,
	resourceID string,
) (string, bool, error)

LoadResourceInstanceID reads a resource's ID record. Resources are persisted inside their instance's object, so the record only says which instance to load.

func (*ServiceLoader) LoadValidation

func (l *ServiceLoader) LoadValidation(
	ctx context.Context,
	id string,
) (*manage.BlueprintValidation, bool, error)

type ServiceStorage

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

ServiceStorage adapts an objectstore.Service to statestore.Storage so the shared persistence engine can back its writes with an object store. It also implements statestore.ConditionalStorage, with object ETags as versions, so engines sharing a bucket do not overwrite each other's instance changes.

func NewServiceStorage

func NewServiceStorage(svc Service) *ServiceStorage

NewServiceStorage returns a statestore.Storage adapter over svc.

func (*ServiceStorage) Delete

func (s *ServiceStorage) Delete(ctx context.Context, key string) error

func (*ServiceStorage) DeleteIfMatch added in v0.12.0

func (s *ServiceStorage) DeleteIfMatch(ctx context.Context, key string, version string) error

func (*ServiceStorage) Exists

func (s *ServiceStorage) Exists(ctx context.Context, key string) (bool, error)

func (*ServiceStorage) List

func (s *ServiceStorage) List(ctx context.Context, prefix string) ([]string, error)

func (*ServiceStorage) Read

func (s *ServiceStorage) Read(ctx context.Context, key string) ([]byte, error)

func (*ServiceStorage) ReadVersion added in v0.12.0

func (s *ServiceStorage) ReadVersion(ctx context.Context, key string) ([]byte, string, error)

func (*ServiceStorage) Write

func (s *ServiceStorage) Write(ctx context.Context, key string, data []byte) error

func (*ServiceStorage) WriteIfMatch added in v0.12.0

func (s *ServiceStorage) WriteIfMatch(
	ctx context.Context,
	key string,
	data []byte,
	version string,
) (string, error)

type StateContainer

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

StateContainer is the object storage backed implementation of the blueprint state.Container interface. It composes the shared statestore engine with a Service-backed Storage adapter; ETag-aware concurrency primitives (ClaimForDeployment, InitialiseAndClaim) go direct to the Service so IfMatch / IfNoneMatch conditional writes serialise concurrent deploys sharing a bucket.

func LoadStateContainer

func LoadStateContainer(
	_ context.Context,
	svc Service,
	prefix string,
	logger core.Logger,
	opts ...Option,
) (*StateContainer, error)

LoadStateContainer constructs an object-storage-backed state container. svc provides the low-level object operations; prefix is prepended to every storage key (e.g. "bluelink-state/"). State runs under ModeLazy — entries materialise on demand from the Service so each process only touches the working subset of the shared bucket rather than eagerly walking it.

func (*StateContainer) Audit added in v0.11.0

func (c *StateContainer) Audit() manage.Audit

func (*StateContainer) Changesets

func (c *StateContainer) Changesets() manage.Changesets

func (*StateContainer) Children

func (c *StateContainer) Children() state.ChildrenContainer

func (*StateContainer) CleanupOperations

func (c *StateContainer) CleanupOperations() manage.CleanupOperations

func (*StateContainer) Events

func (c *StateContainer) Events() manage.Events

func (*StateContainer) Exports

func (c *StateContainer) Exports() state.ExportsContainer

func (*StateContainer) Housekeeping added in v0.13.0

func (c *StateContainer) Housekeeping() manage.Housekeeping

Housekeeping returns the objectstore backend's housekeeping, which deletes records that interrupted writes left in the bucket, such as ID records whose instance was never written and instances whose removal was cut short. Each multi-object write is ordered so that what it leaves behind is never read as valid, so housekeeping only reclaims storage.

func (*StateContainer) Instances

func (c *StateContainer) Instances() state.InstancesContainer
func (c *StateContainer) Links() state.LinksContainer

func (*StateContainer) Metadata

func (c *StateContainer) Metadata() state.MetadataContainer

func (*StateContainer) ReconciliationResults

func (c *StateContainer) ReconciliationResults() manage.ReconciliationResults

func (*StateContainer) Resources

func (c *StateContainer) Resources() state.ResourcesContainer

func (*StateContainer) Validation

func (c *StateContainer) Validation() manage.Validation

Directories

Path Synopsis
internal
stores
gcs
s3

Jump to

Keyboard shortcuts

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