postgres

package
v0.0.0-...-61396ba Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL/CockroachDB implementation of the db.DB interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgres

func NewPostgres(cfg Config) (db.DB, error)

NewPostgres creates a new PostgreSQL-backed database

Types

type Config

type Config struct {
	// DSN is the data source name (e.g., "postgres://user:pass@host:port/database?sslmode=disable")
	DSN string

	// Driver is the specific driver type (postgres or cockroachdb)
	Driver db.Driver

	// Connection pool settings
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

Config holds PostgreSQL connection configuration

func DefaultConfig

func DefaultConfig(dsn string, driver db.Driver) Config

DefaultConfig returns a Config with sensible defaults

type Postgres

type Postgres struct {
	*dbsql.Store // Embedded for shared object operations
	// contains filtered or unexported fields
}

Postgres implements db.DB using PostgreSQL/CockroachDB as the backing store

func (*Postgres) AddChunkReplica

func (p *Postgres) AddChunkReplica(ctx context.Context, chunkID, serverID, backendID string) error

AddChunkReplica records that a chunk exists on a specific file server.

func (*Postgres) Close

func (p *Postgres) Close() error

Close closes the database connection

func (*Postgres) DecrementChunkRefCount

func (p *Postgres) DecrementChunkRefCount(ctx context.Context, chunkID string) error

DecrementChunkRefCount decrements the reference count for a chunk. If ref_count reaches 0, sets zero_ref_since to current time for GC grace period.

func (*Postgres) DecrementChunkRefCountBatch

func (p *Postgres) DecrementChunkRefCountBatch(ctx context.Context, chunkIDs []string) error

DecrementChunkRefCountBatch decrements ref counts for multiple chunks atomically.

func (*Postgres) DeleteBucketLogging

func (p *Postgres) DeleteBucketLogging(ctx context.Context, bucket string) error

DeleteBucketLogging removes the logging configuration for a bucket.

func (*Postgres) DeleteChunkRegistry

func (p *Postgres) DeleteChunkRegistry(ctx context.Context, chunkID string) error

DeleteChunkRegistry removes a chunk from the registry. The chunk_replicas entries are automatically deleted via CASCADE.

func (*Postgres) DeleteFederationConfig

func (p *Postgres) DeleteFederationConfig(ctx context.Context, bucket string) error

DeleteFederationConfig removes the federation config for a bucket.

func (*Postgres) DeleteNotificationConfiguration

func (p *Postgres) DeleteNotificationConfiguration(ctx context.Context, bucket string) error

DeleteNotificationConfiguration removes the notification config for a bucket.

func (*Postgres) DeleteOwnershipControls

func (p *Postgres) DeleteOwnershipControls(ctx context.Context, bucket string) error

func (*Postgres) DeletePublicAccessBlock

func (p *Postgres) DeletePublicAccessBlock(ctx context.Context, bucket string) error

func (*Postgres) GetBucketLogging

func (p *Postgres) GetBucketLogging(ctx context.Context, bucket string) (*db.BucketLoggingConfig, error)

GetBucketLogging retrieves the logging configuration for a bucket.

func (*Postgres) GetBucketsNeedingScan

func (p *Postgres) GetBucketsNeedingScan(ctx context.Context, minAge time.Duration, limit int) ([]string, error)

func (*Postgres) GetChunkRefCount

func (p *Postgres) GetChunkRefCount(ctx context.Context, chunkID string) (int, error)

GetChunkRefCount returns the current reference count for a chunk. Used by GC to re-check ref count within a transaction before deleting.

func (*Postgres) GetChunkReplicas

func (p *Postgres) GetChunkReplicas(ctx context.Context, chunkID string) ([]db.ReplicaInfo, error)

GetChunkReplicas returns all replica locations for a chunk.

func (*Postgres) GetChunksByServer

func (p *Postgres) GetChunksByServer(ctx context.Context, serverID string) ([]string, error)

GetChunksByServer returns all chunk IDs stored on a specific server. Used for server decommissioning and rebalancing.

func (*Postgres) GetFederatedBucketsNeedingSync

func (p *Postgres) GetFederatedBucketsNeedingSync(ctx context.Context, limit int) ([]*s3types.FederationConfig, error)

GetFederatedBucketsNeedingSync returns buckets that are in migrating mode and not paused. Note: The bucket mode is stored in the Manager's Raft state, not in the metadata DB. This method returns all non-paused federation configs; the caller should check bucket mode.

func (*Postgres) GetFederationConfig

func (p *Postgres) GetFederationConfig(ctx context.Context, bucket string) (*s3types.FederationConfig, error)

GetFederationConfig retrieves the federation config for a bucket.

func (*Postgres) GetNotificationConfiguration

func (p *Postgres) GetNotificationConfiguration(ctx context.Context, bucket string) (*s3types.NotificationConfiguration, error)

GetNotificationConfiguration retrieves the notification config for a bucket.

func (*Postgres) GetObjectLegalHold

func (p *Postgres) GetObjectLegalHold(ctx context.Context, bucket, key string) (*s3types.ObjectLockLegalHold, error)

func (*Postgres) GetObjectLockConfiguration

func (p *Postgres) GetObjectLockConfiguration(ctx context.Context, bucket string) (*s3types.ObjectLockConfiguration, error)

func (*Postgres) GetObjectRetention

func (p *Postgres) GetObjectRetention(ctx context.Context, bucket, key string) (*s3types.ObjectLockRetention, error)

func (*Postgres) GetOwnershipControls

func (p *Postgres) GetOwnershipControls(ctx context.Context, bucket string) (*s3types.OwnershipControls, error)

func (*Postgres) GetPublicAccessBlock

func (p *Postgres) GetPublicAccessBlock(ctx context.Context, bucket string) (*s3types.PublicAccessBlockConfig, error)

func (*Postgres) GetScanState

func (p *Postgres) GetScanState(ctx context.Context, bucket string) (*db.LifecycleScanState, error)

func (*Postgres) GetZeroRefChunks

func (p *Postgres) GetZeroRefChunks(ctx context.Context, olderThan time.Time, limit int) ([]db.ZeroRefChunk, error)

GetZeroRefChunks returns chunks with ref_count=0 where zero_ref_since is older than the given time (past the grace period). Includes replica info for deletion.

func (*Postgres) IncrementChunkRefCount

func (p *Postgres) IncrementChunkRefCount(ctx context.Context, chunkID string, size int64) error

IncrementChunkRefCount increments the reference count for a chunk. If the chunk doesn't exist, it creates it with ref_count=1. Clears zero_ref_since if the chunk was previously at ref_count=0.

func (*Postgres) IncrementChunkRefCountBatch

func (p *Postgres) IncrementChunkRefCountBatch(ctx context.Context, chunks []db.ChunkInfo) error

IncrementChunkRefCountBatch increments ref counts for multiple chunks atomically.

func (*Postgres) ListBucketsWithLifecycle

func (p *Postgres) ListBucketsWithLifecycle(ctx context.Context) ([]string, error)

func (*Postgres) ListFederatedBuckets

func (p *Postgres) ListFederatedBuckets(ctx context.Context) ([]*s3types.FederationConfig, error)

ListFederatedBuckets returns all buckets with federation configurations.

func (*Postgres) ListLoggingConfigs

func (p *Postgres) ListLoggingConfigs(ctx context.Context) ([]*db.BucketLoggingConfig, error)

ListLoggingConfigs returns all bucket logging configurations.

func (*Postgres) Migrate

func (p *Postgres) Migrate(ctx context.Context) error

Migrate runs database migrations for PostgreSQL/CockroachDB

func (*Postgres) PutObject

func (p *Postgres) PutObject(ctx context.Context, obj *types.ObjectRef) error

PutObject creates or updates an object within a transaction. This method uses SELECT FOR UPDATE to serialize concurrent writes to the same bucket/key, preventing races where two concurrent calls both set is_latest=TRUE.

func (*Postgres) RemoveChunkReplica

func (p *Postgres) RemoveChunkReplica(ctx context.Context, chunkID, serverID string) error

RemoveChunkReplica removes the record of a chunk on a file server.

func (*Postgres) ResetScanState

func (p *Postgres) ResetScanState(ctx context.Context, bucket string) error

func (*Postgres) SetBucketLogging

func (p *Postgres) SetBucketLogging(ctx context.Context, config *db.BucketLoggingConfig) error

SetBucketLogging stores the logging configuration for a bucket.

func (*Postgres) SetDualWriteEnabled

func (p *Postgres) SetDualWriteEnabled(ctx context.Context, bucket string, enabled bool) error

SetDualWriteEnabled sets the dual_write_enabled flag for a bucket.

func (*Postgres) SetFederationConfig

func (p *Postgres) SetFederationConfig(ctx context.Context, config *s3types.FederationConfig) error

SetFederationConfig stores or updates the federation config for a bucket.

func (*Postgres) SetMigrationPaused

func (p *Postgres) SetMigrationPaused(ctx context.Context, bucket string, paused bool) error

SetMigrationPaused sets the migration_paused flag for a bucket.

func (*Postgres) SetNotificationConfiguration

func (p *Postgres) SetNotificationConfiguration(ctx context.Context, bucket string, config *s3types.NotificationConfiguration) error

SetNotificationConfiguration stores the notification config for a bucket.

func (*Postgres) SetObjectLegalHold

func (p *Postgres) SetObjectLegalHold(ctx context.Context, bucket, key string, legalHold *s3types.ObjectLockLegalHold) error

func (*Postgres) SetObjectLockConfiguration

func (p *Postgres) SetObjectLockConfiguration(ctx context.Context, bucket string, config *s3types.ObjectLockConfiguration) error

func (*Postgres) SetObjectRetention

func (p *Postgres) SetObjectRetention(ctx context.Context, bucket, key string, retention *s3types.ObjectLockRetention) error

func (*Postgres) SetOwnershipControls

func (p *Postgres) SetOwnershipControls(ctx context.Context, bucket string, controls *s3types.OwnershipControls) error

func (*Postgres) SetPublicAccessBlock

func (p *Postgres) SetPublicAccessBlock(ctx context.Context, bucket string, config *s3types.PublicAccessBlockConfig) error

func (*Postgres) SqlDB

func (p *Postgres) SqlDB() *sql.DB

SqlDB returns the underlying *sql.DB for use with taskqueue.DBQueue

func (*Postgres) UpdateMigrationProgress

func (p *Postgres) UpdateMigrationProgress(ctx context.Context, bucket string, objectsSynced, bytesSynced int64, lastSyncKey string) error

UpdateMigrationProgress updates the migration progress counters for a bucket.

func (*Postgres) UpdateScanState

func (p *Postgres) UpdateScanState(ctx context.Context, state *db.LifecycleScanState) error

func (*Postgres) UsageStore

func (p *Postgres) UsageStore() usage.Store

UsageStore returns a usage.Store backed by PostgreSQL.

func (*Postgres) WithTx

func (p *Postgres) WithTx(ctx context.Context, fn func(tx db.TxStore) error) error

WithTx executes fn within a database transaction.

Jump to

Keyboard shortcuts

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