Documentation
¶
Overview ¶
Package pgunit runs Core's PostgreSQL transactions: pooled transactions for public and administrative work, and the execution owner's transactions on the connection that holds the database's execution lease.
Index ¶
Constants ¶
const ExecutionTimeout = 5 * time.Second
ExecutionTimeout bounds every leased operation, including its wait for the connection gate and for row locks. Code that groups several statements under one execution deadline uses it too.
Variables ¶
var ( ErrLeaseHeld = errors.New("another execution service owns this database") ErrLeaseClosed = errors.New("execution lease is closed") )
var ErrInvalidID = errors.New("nonzero UUID required")
ErrInvalidID reports a value that is not a nonzero UUID. Adapters translate it into their domain's invalid-input error.
Functions ¶
func IsUnstorableText ¶
IsUnstorableText reports PostgreSQL rejecting client text it cannot represent: U+0000 or invalid UTF-8 in a text parameter (22021), or a jsonb \u0000 escape (22P05). The rejected statement stores nothing, and writes sharing its transaction roll back. Adapters return textvalue.ErrUnstorable in its place and never keep the database error in the chain.
func LookupCursor ¶
LookupCursor resolves the cursor of a list whose unresolved cursor is a 404 (Agents, Sessions, Turns, Templates, Vaults and Credentials) like a path identifier: a value that cannot name a resource becomes an identifier that never exists, so the list follows exactly the missing-cursor path.
func ParseID ¶
ParseID parses a resource identifier that must name a resource, such as a request-body reference. A value that is not a nonzero UUID is ErrInvalidID.
func PathID ¶
PathID parses a caller-supplied resource path identifier. A value that cannot name a resource resolves to an identifier that never exists, so the request follows exactly the path of a well-formed missing identifier, including validation order. Request-body references use ParseID; cursors use LookupCursor.
Types ¶
type LargeObject ¶
LargeObject is stored content: its large object's OID, size and hex SHA-256 digest.
type LargeObjectWriter ¶
type LargeObjectWriter struct {
// contains filtered or unexported fields
}
LargeObjectWriter streams content into a new large object in bounded chunks and records its size and digest. The first failure is kept: every later Write returns it, and Err reports it.
func CreateLargeObject ¶
CreateLargeObject creates an empty large object in tx and opens it for writing. The object belongs to tx: it disappears when tx rolls back.
func (*LargeObjectWriter) Close ¶
func (w *LargeObjectWriter) Close() (LargeObject, error)
Close closes the object after the content is complete and describes it.
func (*LargeObjectWriter) Err ¶
func (w *LargeObjectWriter) Err() error
Err returns the first write failure, or nil.
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease owns the connection used for execution writes, not just election: the PostgreSQL advisory lock belongs to that session, so every execution write runs on it. Its gate serializes pgx operations on the connection; no daemon or model work holds the gate. Losing or closing the lease never falls back to a pooled connection.
func AcquireLease ¶
AcquireLease takes the database's execution lease on a dedicated connection from pool. It enforces single-service ownership per database and fails with ErrLeaseHeld when another service owns it.
func (*Lease) CancelOperations ¶
CancelOperations cancels coordinator-owned contexts between leased operations. Cancelling an in-flight pgx operation can close the connection that owns the advisory lock, so cancel runs only while the gate is held and after the connection answers a ping. cancel must only invoke synchronous context cancel functions; it must not perform database, provider or wait work. Caller cancellation and operation deadlines keep their own semantics.
func (*Lease) CheckOwnership ¶
CheckOwnership pings the leased connection, confirming that this service still owns the database before external work.
func (*Lease) Close ¶
Close releases the lease by closing its connection and waits, within ctx, for the driver's asynchronous cleanup. A later Close resumes that wait.
func (*Lease) Transaction ¶
Transaction runs apply in a read committed transaction on the leased connection and commits only when apply returns nil. apply receives the context carrying the execution deadline.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool runs transactions on pooled connections. It grants no execution authority.
func (*Pool) Queries ¶
Queries returns queries bound to the pool, outside any transaction. Use it only for a read that is a single statement and needs no transaction, such as a per-request key lookup, where Snapshot would add BEGIN and COMMIT round trips. A read of several statements uses Snapshot, and a write uses Transaction.