store

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackfillAccessGrants

func BackfillAccessGrants(ctx context.Context, dbConn *sql.DB, dialect Dialect) error

BackfillAccessGrants runs the transfer attribution bootstrap against an already-open database. Backend schema bootstraps use this boundary so the migration itself remains owned by Store.

Types

type CredentialCodec

type CredentialCodec interface {
	Prepare(context.Context, *buckets.Credential) (*buckets.Credential, error)
	Parse(context.Context, *buckets.Credential) (*buckets.Credential, error)
	Enabled() (bool, error)
}

CredentialCodec is the persistence boundary for credential field encoding.

type Dialect

type Dialect interface {
	Rebind(string) string
	ListArgs(string, []string) (string, []any)
	LockContentWrite(context.Context, *sql.Tx) error
	LockObjectUsageEventIDs(context.Context, *sql.Tx, []string) error
	Bootstrap(context.Context, *sql.DB) error
}

Dialect contains the SQL and locking behavior that cannot be shared across the SQLite and PostgreSQL implementations.

type Store

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

Store owns the database handle and the shared, dialect-independent SQL operation state. SQLite and PostgreSQL constructors return this concrete implementation directly.

func Open

func Open(ctx context.Context, db *sql.DB, dialect Dialect, cipher CredentialCodec) (*Store, error)

Open bootstraps db through dialect and returns the shared store. A nil codec is accepted for callers that do not use credential persistence.

func OpenPrepared

func OpenPrepared(ctx context.Context, db *sql.DB, dialect Dialect, cipher CredentialCodec) (*Store, error)

OpenPrepared adopts an already validated database handle without running dialect bootstrap. Production PostgreSQL startup uses this path after a read-only schema check. Schema writes stay in the SQL mounted into the cluster DB-init Job; existing plaintext credentials are encrypted here.

func (*Store) AddObjectControlledAccess added in v0.4.3

func (db *Store) AddObjectControlledAccess(ctx context.Context, objectID, resource string) error

AddObjectControlledAccess restores one project association after the object service has verified that its deterministic ID belongs to that project.

func (*Store) BulkDeleteObjects

func (db *Store) BulkDeleteObjects(ctx context.Context, ids []string) error

func (*Store) BulkUpdateAccessMethods

func (db *Store) BulkUpdateAccessMethods(ctx context.Context, updates map[string][]drs.AccessMethod) error

func (*Store) ClaimMultipartAbort

func (db *Store) ClaimMultipartAbort(ctx context.Context, uploadID, token string, now, staleBefore time.Time) (transfers.MultipartSession, bool, error)

func (*Store) ClaimMultipartCompletionWithParts

func (db *Store) ClaimMultipartCompletionWithParts(ctx context.Context, uploadID, token, partsFingerprint string, parts []transfers.CompletedPart, now, staleBefore time.Time) (transfers.MultipartSession, bool, error)

func (*Store) Close

func (s *Store) Close() error

Close closes the database handle owned by the store.

func (*Store) CompactCompletedMultipartSessions

func (db *Store) CompactCompletedMultipartSessions(ctx context.Context, before time.Time, limit int) error

func (*Store) ConsumePendingMetadata

func (db *Store) ConsumePendingMetadata(ctx context.Context, expected transferlfs.PendingMetadata) (bool, error)

ConsumePendingMetadata removes the expected pending entry if it is still the entry that was read by the caller. A missing or replaced entry is an expected no-op: another stage or verification operation owns that metadata.

func (*Store) CreateBucketScope

func (db *Store) CreateBucketScope(ctx context.Context, scope *buckets.Scope) error

func (*Store) CreateObjectAlias

func (db *Store) CreateObjectAlias(ctx context.Context, aliasID, canonicalObjectID string) error

func (*Store) DB

func (s *Store) DB() *sql.DB

DB exposes the owned handle to backend migration tests that must assert schema and transaction behavior directly.

func (*Store) DeleteBucketCredential added in v0.4.3

func (db *Store) DeleteBucketCredential(ctx context.Context, bucket string, authorize buckets.ScopeDeletionPolicy) ([]string, error)

DeleteBucketCredential applies the caller's policy to the current scope set and removes that set with its credential under one content-write lock.

func (*Store) DeleteBucketScopeConfiguration

func (db *Store) DeleteBucketScopeConfiguration(ctx context.Context, scope buckets.Scope) ([]string, error)

DeleteBucketScopeConfiguration atomically removes one scope and its unused credential. Returned aliases are safe to invalidate because commit succeeded.

func (*Store) DeleteObject

func (db *Store) DeleteObject(ctx context.Context, id string) error

func (*Store) DeleteS3Credential

func (db *Store) DeleteS3Credential(ctx context.Context, credentialID string) error

func (*Store) FinishMultipartAbort

func (db *Store) FinishMultipartAbort(ctx context.Context, uploadID, token string, _ time.Time) (bool, error)

func (*Store) FinishMultipartCompletion

func (db *Store) FinishMultipartCompletion(ctx context.Context, uploadID, token, location string, now time.Time) (bool, error)

func (*Store) GetBucketScope

func (db *Store) GetBucketScope(ctx context.Context, organization, projectID string) (*buckets.Scope, error)

func (*Store) GetBulkObjects

func (db *Store) GetBulkObjects(ctx context.Context, ids []string) ([]drs.DrsObject, error)

func (*Store) GetFileUsage

func (db *Store) GetFileUsage(ctx context.Context, objectID string) (*metricsapi.FileUsage, error)

func (*Store) GetFileUsageSummary

func (db *Store) GetFileUsageSummary(ctx context.Context, inactiveSince *time.Time) (metricsapi.FileUsageSummary, error)

func (*Store) GetFileUsageSummaryByResources

func (db *Store) GetFileUsageSummaryByResources(ctx context.Context, resources []string, includeUnscoped bool, inactiveSince *time.Time) (metricsapi.FileUsageSummary, error)

func (*Store) GetFileUsageSummaryByScope

func (db *Store) GetFileUsageSummaryByScope(ctx context.Context, organization, project string, inactiveSince *time.Time) (metricsapi.FileUsageSummary, error)

func (*Store) GetLFSUploadReceipt added in v0.4.3

func (db *Store) GetLFSUploadReceipt(ctx context.Context, oid string) (*transferlfs.UploadReceipt, error)

func (*Store) GetMultipartCompletionReceipt

func (db *Store) GetMultipartCompletionReceipt(ctx context.Context, uploadID string) (transfers.MultipartCompletionReceipt, error)

func (*Store) GetMultipartSession

func (db *Store) GetMultipartSession(ctx context.Context, uploadID string) (transfers.MultipartSession, error)

func (*Store) GetObject

func (db *Store) GetObject(ctx context.Context, id string) (*drs.DrsObject, error)

func (*Store) GetObjectsByChecksums

func (db *Store) GetObjectsByChecksums(ctx context.Context, checksums []string) (map[string][]drs.DrsObject, error)

func (*Store) GetPendingMetadata

func (db *Store) GetPendingMetadata(ctx context.Context, oid string) (*transferlfs.PendingMetadata, error)

func (*Store) GetProjectRecordSummaryByScope

func (db *Store) GetProjectRecordSummaryByScope(ctx context.Context, organization, project string) (metricsapi.FileUsageSummary, error)

func (*Store) GetPublicReadByIDs

func (db *Store) GetPublicReadByIDs(ctx context.Context, ids []string) (map[string]bool, error)

func (*Store) GetS3Credential

func (db *Store) GetS3Credential(ctx context.Context, credentialID string) (*buckets.Credential, error)

func (*Store) ListBucketScopes

func (db *Store) ListBucketScopes(ctx context.Context) ([]buckets.Scope, error)

func (*Store) ListBucketVisibilityRows

func (db *Store) ListBucketVisibilityRows(ctx context.Context, resources []string, includeUnscoped, restrictToResources bool) ([]buckets.VisibilityRow, error)

func (*Store) ListCredentialMetadata added in v0.4.4

func (db *Store) ListCredentialMetadata(ctx context.Context) ([]buckets.CredentialMetadata, error)

ListCredentialMetadata reads only fields needed to assemble bucket visibility.

func (*Store) ListFileUsage

func (db *Store) ListFileUsage(ctx context.Context, limit, offset int, inactiveSince *time.Time) ([]metricsapi.FileUsage, error)

func (*Store) ListFileUsageByObjectIDs

func (db *Store) ListFileUsageByObjectIDs(ctx context.Context, ids []string) ([]metricsapi.FileUsage, error)

func (*Store) ListFileUsagePageByResources

func (db *Store) ListFileUsagePageByResources(ctx context.Context, resources []string, includeUnscoped bool, limit, offset int, inactiveSince *time.Time) ([]metricsapi.FileUsage, error)

func (*Store) ListFileUsagePageByScope

func (db *Store) ListFileUsagePageByScope(ctx context.Context, organization, project string, limit, offset int, inactiveSince *time.Time) ([]metricsapi.FileUsage, error)

func (*Store) ListMultipartSessionsForReconcile

func (db *Store) ListMultipartSessionsForReconcile(ctx context.Context, inactiveBefore, completedBefore time.Time, limit int) ([]transfers.MultipartSession, error)

func (*Store) ListObjectIDsByResources

func (db *Store) ListObjectIDsByResources(ctx context.Context, resources []string, includeUnscoped bool) ([]string, error)

func (*Store) ListObjectIDsByScope

func (db *Store) ListObjectIDsByScope(ctx context.Context, organization, project string) ([]string, error)

func (*Store) ListObjectIDsPage added in v0.4.3

func (db *Store) ListObjectIDsPage(ctx context.Context, query objects.ObjectIDPageQuery) ([]string, error)

func (*Store) ListRepairCandidateObjectIDs added in v0.4.3

func (db *Store) ListRepairCandidateObjectIDs(ctx context.Context, query objects.RepairCandidateQuery) ([]string, error)

ListRepairCandidateObjectIDs pages records stored under one S3 project prefix that do not yet have the requested controlled-access association.

func (*Store) ListS3Credentials

func (db *Store) ListS3Credentials(ctx context.Context) ([]buckets.Credential, error)

func (*Store) ListScopedObjectIDsByChecksums

func (db *Store) ListScopedObjectIDsByChecksums(ctx context.Context, organization, project string, checksums []string) (map[string][]string, error)

func (*Store) QueryTransferBreakdown

func (db *Store) QueryTransferBreakdown(ctx context.Context, filter usage.Filter, groupBy string, resources []string, limit, offset int) ([]metricsapi.TransferAttributionBreakdown, error)

QueryTransferBreakdown returns one stable page of matching groups.

func (*Store) QueryTransferSummary

func (db *Store) QueryTransferSummary(ctx context.Context, filter usage.Filter, resources []string) (metricsapi.TransferAttributionSummary, error)

func (*Store) RecordFileDownload

func (db *Store) RecordFileDownload(ctx context.Context, objectID string) error

func (*Store) RecordFileUpload

func (db *Store) RecordFileUpload(ctx context.Context, objectID string) error

func (*Store) RecordProviderTransferEvents

func (db *Store) RecordProviderTransferEvents(ctx context.Context, events []metricsapi.ProviderTransferEvent) error

func (*Store) RecordTransferAttributionEvents

func (db *Store) RecordTransferAttributionEvents(ctx context.Context, events []usage.Event) error

func (*Store) RegisterObjects

func (db *Store) RegisterObjects(ctx context.Context, objects []drs.DrsObject) error

RegisterObjects is the content identity write boundary. Every SHA-bearing registration is merged while the SQLite writer lock is held, so the parent row, children, aliases, and public policy commit together.

func (*Store) RegisterObjectsIfPending added in v0.4.3

func (db *Store) RegisterObjectsIfPending(ctx context.Context, records []drs.DrsObject, pending objects.PendingRegistration) error

func (*Store) ReleaseMultipartAbort added in v0.4.3

func (db *Store) ReleaseMultipartAbort(ctx context.Context, uploadID, token string, now time.Time) error

func (*Store) ReleaseMultipartCompletion

func (db *Store) ReleaseMultipartCompletion(ctx context.Context, uploadID, token string, now time.Time) error

func (*Store) RemoveObjectControlledAccess

func (db *Store) RemoveObjectControlledAccess(ctx context.Context, objectID, resource string) error

func (*Store) RemoveObjectControlledAccessBulk

func (db *Store) RemoveObjectControlledAccessBulk(ctx context.Context, objectIDs []string, resource string) (int, error)

func (*Store) RepairCanonicalDuplicates

func (db *Store) RepairCanonicalDuplicates(ctx context.Context, repairs []objects.CanonicalRepair) error

RepairCanonicalDuplicates is the transactional repair boundary for legacy physical rows that share one checksum. Duplicate rows are removed before the merged canonical row is registered, because registration rejects an ambiguous checksum family. The whole operation, including alias creation, commits or rolls back together.

func (*Store) ReplaceObject added in v0.4.3

func (db *Store) ReplaceObject(ctx context.Context, objectID, expectedOldSHA string, obj drs.DrsObject) error

ReplaceObject atomically replaces one requested DID after validating the SHA captured by the caller's preflight lookup. Alias DIDs are detached from their old content row before the new row is registered in the same txn.

func (*Store) ReplaceObjects

func (db *Store) ReplaceObjects(ctx context.Context, objects []drs.DrsObject) error

ReplaceObjects is the checked, atomic boundary for whole-object updates. Registration remains additive; replacement is reserved for callers that have update authority over every current grant.

func (*Store) ResolveObjectAlias

func (db *Store) ResolveObjectAlias(ctx context.Context, aliasID string) (string, error)

func (*Store) ResolveObjectAliases added in v0.4.4

func (db *Store) ResolveObjectAliases(ctx context.Context, ids []string) (map[string]string, error)

ResolveObjectAliases returns aliases even when an alias ID also names a physical object. Bulk overwrite must reject that collision.

func (*Store) ResolveObjectIDs added in v0.4.3

func (db *Store) ResolveObjectIDs(ctx context.Context, ids []string) (map[string]string, error)

ResolveObjectIDs maps physical IDs and aliases to canonical physical IDs in one batch, omitting identifiers that do not exist.

func (*Store) SaveBucketConfiguration

func (db *Store) SaveBucketConfiguration(ctx context.Context, configuration buckets.BucketConfiguration) error

SaveBucketConfiguration atomically persists a credential and its scope. A failure in either write leaves both rows unchanged.

func (*Store) SaveLFSUploadReceipt added in v0.4.3

func (db *Store) SaveLFSUploadReceipt(ctx context.Context, receipt transferlfs.UploadReceipt) error

func (*Store) SaveMultipartSession

func (db *Store) SaveMultipartSession(ctx context.Context, session transfers.MultipartSession) error

func (*Store) SavePendingMetadata

func (db *Store) SavePendingMetadata(ctx context.Context, entries []transferlfs.PendingMetadata) error

func (*Store) SaveS3Credential

func (db *Store) SaveS3Credential(ctx context.Context, cred *buckets.Credential) error

func (*Store) TouchMultipartSession

func (db *Store) TouchMultipartSession(ctx context.Context, uploadID string, now time.Time) error

func (*Store) UpdateObjectAccessMethods

func (db *Store) UpdateObjectAccessMethods(ctx context.Context, objectID string, accessMethods []drs.AccessMethod) error

Jump to

Keyboard shortcuts

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