Help us shape the future of Go! Take the 2026 Go Developer Survey

graphlock

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package graphlock serializes the transactions that remove relationships from the authorization graph with the graph reconciler's repairs.

A revocation removes the relationship from the graph inside the transaction that changes the database, after the database change and before the commit, holding the lock of every principal and organization whose relationships it removes. The reconciler (authz/mode) writes a missing relationship back only in a transaction holding the same locks, after reading the rows again. Whichever runs second sees the other's result: the reconciler cannot restore a relationship a revocation is removing, and a revocation cannot be undone by a repair already under way.

The locks are PostgreSQL transaction-scoped advisory locks, released when the transaction ends. SQLite has no advisory locks; Lock does nothing there, so the guarantee needs PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Grant

func Grant(ctx context.Context, client *ent.Client, keys []string, write func(ctx context.Context, c *ent.Client) error) (err error)

Grant writes to the graph the access a committed change granted, without undoing a revocation that committed since. It runs write in a transaction holding the locks named by keys; write reads the rows again through c, the transaction's client, and writes only the relationships they still call for (package identity/graphstate). A revocation holding one of the locks finishes first, so write sees its result; one that starts later waits for write, and removes what it wrote.

The transaction only reads and is rolled back when write returns. Grant returns write's error, joined with a failure to end the transaction. Lock it with the same keys as the reconciler's repair of the relationship: the organization and the principal for a relationship on an organization, its facet or a resource in it, the principal alone for platform administration, and both principals for a manager relation.

func Lock

func Lock(ctx context.Context, tx *ent.Tx, keys ...string) error

Lock takes the transaction-scoped locks named by keys, in sorted order so that two transactions locking overlapping sets cannot deadlock. The locks are held until tx commits or rolls back. On SQLite it does nothing.

func Organization

func Organization(id uuid.UUID) string

Organization is the lock key of an organization's relationships.

func Principal

func Principal(id uuid.UUID) string

Principal is the lock key of a principal's relationships: those it holds in organizations, applications and resources, its platform administration, and the manager relations on it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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