Documentation
¶
Index ¶
- Variables
- type ApplyCommitParams
- type Block
- type Change
- type ChangedSinceParams
- type ChangedSinceRow
- type CreateDatabaseParams
- type DBTX
- type Database
- type DatabaseExistsParams
- type DeleteBlocksFromParams
- type DeleteChangesParams
- type DeleteDatabaseParams
- type ExtendLeaseParams
- type FetchBlocksParams
- type FetchBlocksRow
- type GetDatabaseParams
- type GrantLeaseParams
- type InsertSlotParams
- type LockDatabaseParams
- type OldestChangeParams
- type PruneChangesParams
- type PurgeDatabaseParams
- type PurgeSubjectRow
- type PutBlocksBatchResults
- type PutBlocksParams
- type Queries
- func (q *Queries) ApplyCommit(ctx context.Context, arg ApplyCommitParams) (int64, error)
- func (q *Queries) ChangedSince(ctx context.Context, arg ChangedSinceParams) ([]ChangedSinceRow, error)
- func (q *Queries) CreateDatabase(ctx context.Context, arg CreateDatabaseParams) (Database, error)
- func (q *Queries) DatabaseExists(ctx context.Context, arg DatabaseExistsParams) (bool, error)
- func (q *Queries) DeleteBlocksFrom(ctx context.Context, arg DeleteBlocksFromParams) error
- func (q *Queries) DeleteChanges(ctx context.Context, arg DeleteChangesParams) error
- func (q *Queries) DeleteDatabase(ctx context.Context, arg DeleteDatabaseParams) (int64, error)
- func (q *Queries) DeleteSlotOf(ctx context.Context, owner string) error
- func (q *Queries) ExtendLease(ctx context.Context, arg ExtendLeaseParams) (int64, error)
- func (q *Queries) FetchBlocks(ctx context.Context, arg FetchBlocksParams) ([]FetchBlocksRow, error)
- func (q *Queries) GetDatabase(ctx context.Context, arg GetDatabaseParams) (Database, error)
- func (q *Queries) GetSlot(ctx context.Context, owner string) (Slot, error)
- func (q *Queries) GrantLease(ctx context.Context, arg GrantLeaseParams) (int64, error)
- func (q *Queries) HoldsSlot(ctx context.Context, subject string) (bool, error)
- func (q *Queries) InsertSlot(ctx context.Context, arg InsertSlotParams) (Slot, error)
- func (q *Queries) LockDatabase(ctx context.Context, arg LockDatabaseParams) (Database, error)
- func (q *Queries) LockSlot(ctx context.Context, owner string) (Slot, error)
- func (q *Queries) OldestChange(ctx context.Context, arg OldestChangeParams) (int64, error)
- func (q *Queries) PruneChanges(ctx context.Context, arg PruneChangesParams) error
- func (q *Queries) PurgeDatabase(ctx context.Context, arg PurgeDatabaseParams) error
- func (q *Queries) PurgeSubject(ctx context.Context, subject string) ([]PurgeSubjectRow, error)
- func (q *Queries) PutBlocks(ctx context.Context, arg []PutBlocksParams) *PutBlocksBatchResults
- func (q *Queries) RecordChange(ctx context.Context, arg RecordChangeParams) error
- func (q *Queries) ReleaseLease(ctx context.Context, arg ReleaseLeaseParams) (int64, error)
- func (q *Queries) ReleaseUnusedSlots(ctx context.Context, claimedAt pgtype.Timestamptz) error
- func (q *Queries) ReviveDatabase(ctx context.Context, arg ReviveDatabaseParams) (Database, error)
- func (q *Queries) SetSlotLabel(ctx context.Context, arg SetSlotLabelParams) (Slot, error)
- func (q *Queries) ShareSlot(ctx context.Context, owner string) (Slot, error)
- func (q *Queries) SyncStandbyNames(ctx context.Context) (string, error)
- func (q *Queries) UnusedDatabases(ctx context.Context, arg UnusedDatabasesParams) ([]UnusedDatabasesRow, error)
- func (q *Queries) UpdateSlot(ctx context.Context, arg UpdateSlotParams) (Slot, error)
- func (q *Queries) WithTx(tx pgx.Tx) *Queries
- type RecordChangeParams
- type ReleaseLeaseParams
- type ReviveDatabaseParams
- type SetSlotLabelParams
- type Slot
- type UnusedDatabasesParams
- type UnusedDatabasesRow
- type UpdateSlotParams
Constants ¶
This section is empty.
Variables ¶
var (
ErrBatchAlreadyClosed = errors.New("batch already closed")
)
Functions ¶
This section is empty.
Types ¶
type ApplyCommitParams ¶
type ChangedSinceParams ¶
type ChangedSinceRow ¶
type CreateDatabaseParams ¶
type DatabaseExistsParams ¶
type DeleteBlocksFromParams ¶
type DeleteChangesParams ¶
type DeleteDatabaseParams ¶
type ExtendLeaseParams ¶
type ExtendLeaseParams struct {
Subject string
DbID string
LeaseEpoch int64
LeaseExpires pgtype.Timestamptz
}
type FetchBlocksParams ¶
type FetchBlocksRow ¶
type GetDatabaseParams ¶
type GrantLeaseParams ¶
type GrantLeaseParams struct {
Subject string
DbID string
LeaseID []byte
LeaseHolder []byte
LeaseGranted pgtype.Timestamptz
LeaseExpires pgtype.Timestamptz
}
type InsertSlotParams ¶ added in v0.3.0
type InsertSlotParams struct {
Owner string
Subject string
Label string
ClaimedAt pgtype.Timestamptz
}
type LockDatabaseParams ¶
type OldestChangeParams ¶
type PruneChangesParams ¶
type PurgeDatabaseParams ¶ added in v0.3.0
type PurgeSubjectRow ¶ added in v0.3.0
type PutBlocksBatchResults ¶
type PutBlocksBatchResults struct {
// contains filtered or unexported fields
}
func (*PutBlocksBatchResults) Close ¶
func (b *PutBlocksBatchResults) Close() error
func (*PutBlocksBatchResults) Exec ¶
func (b *PutBlocksBatchResults) Exec(f func(int, error))
type PutBlocksParams ¶
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) ApplyCommit ¶
func (*Queries) ChangedSince ¶
func (q *Queries) ChangedSince(ctx context.Context, arg ChangedSinceParams) ([]ChangedSinceRow, error)
func (*Queries) CreateDatabase ¶
CreateDatabase inserts nothing if the row already exists. The caller then locks and reads the existing row.
func (*Queries) DatabaseExists ¶
func (*Queries) DeleteBlocksFrom ¶
func (q *Queries) DeleteBlocksFrom(ctx context.Context, arg DeleteBlocksFromParams) error
func (*Queries) DeleteChanges ¶
func (q *Queries) DeleteChanges(ctx context.Context, arg DeleteChangesParams) error
func (*Queries) DeleteDatabase ¶
DeleteDatabase marks a database as deleted and empties its state. It increases the lease epoch and the version and removes the lease, so that no earlier lease can commit again.
func (*Queries) DeleteSlotOf ¶ added in v0.3.0
func (*Queries) ExtendLease ¶
ExtendLease updates no row if the epoch is not current or the lease was released. The caller then returns ErrFenced, or ErrNotFound if the database does not exist.
func (*Queries) FetchBlocks ¶
func (q *Queries) FetchBlocks(ctx context.Context, arg FetchBlocksParams) ([]FetchBlocksRow, error)
FetchBlocks returns the stored parts of the blocks in a range, ordered by block and part. A block that was never written has no rows. The caller returns zeros for it.
func (*Queries) GetDatabase ¶
func (*Queries) GrantLease ¶
func (*Queries) InsertSlot ¶ added in v0.3.0
InsertSlot inserts nothing if another transaction inserted the owner's slot first. The caller then locks it.
func (*Queries) LockDatabase ¶
All SQL queries of the PostgreSQL store. sqlc generates internal/store/postgres/db from this file. LockDatabase locks the row of a database. Granting a lease, fencing and applying a commit all hold this lock, so they are serialized per database.
func (*Queries) LockSlot ¶ added in v0.3.0
LockSlot locks an owner's slot. Opening a database and claiming or deleting the slot take this lock before any database row, so they cannot deadlock.
func (*Queries) OldestChange ¶
OldestChange returns the oldest version in the change log, or 0 if the log is empty. The log is empty for a database created anew after a deletion, and for one whose commits all predate the change log.
func (*Queries) PruneChanges ¶
func (q *Queries) PruneChanges(ctx context.Context, arg PruneChangesParams) error
PruneChanges deletes the change log entries up to and including the given version.
func (*Queries) PurgeDatabase ¶ added in v0.3.0
func (q *Queries) PurgeDatabase(ctx context.Context, arg PurgeDatabaseParams) error
func (*Queries) PurgeSubject ¶ added in v0.3.0
PurgeSubject deletes all databases of a subject completely, with their blocks and change logs (foreign keys). It returns those that were not deleted before.
func (*Queries) PutBlocks ¶
func (q *Queries) PutBlocks(ctx context.Context, arg []PutBlocksParams) *PutBlocksBatchResults
PutBlocks inserts or updates the parts of the blocks of one commit. pgx sends all rows in one pipelined batch. An update of a part stays on the same page (HOT update), so the table does not grow. See migrations/00003_block_parts.sql.
func (*Queries) RecordChange ¶
func (q *Queries) RecordChange(ctx context.Context, arg RecordChangeParams) error
RecordChange adds the changed blocks of a commit to the change log. On a conflict it does nothing, so a repeated commit cannot fail here: the entry for that version already exists with the same content.
func (*Queries) ReleaseLease ¶
func (*Queries) ReleaseUnusedSlots ¶ added in v0.3.0
ReleaseUnusedSlots releases the slots that were claimed before the cutoff and whose key has no databases left.
func (*Queries) ReviveDatabase ¶
ReviveDatabase creates a deleted database anew, empty, with the given page size. Epoch and version continue.
func (*Queries) SetSlotLabel ¶ added in v0.4.0
SetSlotLabel changes the label only while subject holds the owner's slot.
func (*Queries) ShareSlot ¶ added in v0.3.0
ShareSlot locks an owner's slot against a concurrent claim while a database is opened.
func (*Queries) SyncStandbyNames ¶
SyncStandbyNames returns synchronous_standby_names. It is empty if PostgreSQL does not replicate commits synchronously.
func (*Queries) UnusedDatabases ¶
func (q *Queries) UnusedDatabases(ctx context.Context, arg UnusedDatabasesParams) ([]UnusedDatabasesRow, error)
UnusedDatabases returns up to $2 databases whose lease expired before $1, oldest first. It takes no lock: the caller locks each row and checks it again before deleting. No index covers lease_expires, because every commit and lease renewal updates it, and an index on it would prevent HOT updates of the row. A sweep reads the whole table.
func (*Queries) UpdateSlot ¶ added in v0.3.0
type RecordChangeParams ¶
type ReleaseLeaseParams ¶
type ReviveDatabaseParams ¶
type SetSlotLabelParams ¶ added in v0.4.0
type Slot ¶ added in v0.3.0
type Slot struct {
Owner string
Subject string
Label string
ClaimedAt pgtype.Timestamptz
}
type UnusedDatabasesParams ¶
type UnusedDatabasesParams struct {
LeaseExpires pgtype.Timestamptz
Limit int32
}
type UnusedDatabasesRow ¶
type UpdateSlotParams ¶ added in v0.3.0
type UpdateSlotParams struct {
Owner string
Subject string
Label string
ClaimedAt pgtype.Timestamptz
}