Documentation
¶
Overview ¶
Package state owns BrokerKit's local transactional database and process lease.
Index ¶
- Variables
- type Database
- func (d *Database) Close() error
- func (d *Database) CountOperations(ctx context.Context) (int64, error)
- func (d *Database) DeleteTerminalOperationsBefore(ctx context.Context, cutoff time.Time) (int64, error)
- func (d *Database) GrantSnapshot(ctx context.Context) (GrantSnapshot, error)
- func (d *Database) InsertOperation(ctx context.Context, record OperationRecord) error
- func (d *Database) InsertOperationWithPlan(ctx context.Context, record OperationRecord, plan PlanRecord) error
- func (d *Database) IntegrityCheck(ctx context.Context) (string, error)
- func (d *Database) OperationByID(ctx context.Context, id string) (OperationRecord, error)
- func (d *Database) OperationByIdempotency(ctx context.Context, clientID, key string) (OperationRecord, error)
- func (d *Database) OperationForClient(ctx context.Context, id, clientID string) (OperationRecord, error)
- func (d *Database) Plan(ctx context.Context, digest string) (PlanRecord, error)
- func (d *Database) PutPlan(ctx context.Context, schemaName string, canonical []byte, createdAt time.Time) (string, error)
- func (d *Database) Queries() *dbsql.Queries
- func (d *Database) SQL() *sql.DB
- func (d *Database) SaveGrantSnapshot(ctx context.Context, before, after GrantSnapshot) error
- func (d *Database) SaveGrantSnapshotWithPlan(ctx context.Context, before, after GrantSnapshot, plan PlanRecord) error
- func (d *Database) UnfinishedOperations(ctx context.Context) ([]OperationRecord, error)
- func (d *Database) UpdateOperation(ctx context.Context, record OperationRecord, expectedRevision int64) (bool, error)
- func (d *Database) UpdateOperationWithPlan(ctx context.Context, record OperationRecord, expectedRevision int64, ...) (bool, error)
- type GrantDecisionRecord
- type GrantLifecycleRecord
- type GrantRecord
- type GrantSnapshot
- type NotificationOutboxRecord
- type OperationRecord
- type Options
- type PlanRecord
Constants ¶
This section is empty.
Variables ¶
var ErrGrantStateConflict = errors.New("grant state revision conflict")
var ErrNotFound = sql.ErrNoRows
var ErrStateInUse = errors.New("broker state directory is already in use")
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func (*Database) CountOperations ¶
func (*Database) DeleteTerminalOperationsBefore ¶
func (*Database) GrantSnapshot ¶
func (d *Database) GrantSnapshot(ctx context.Context) (GrantSnapshot, error)
func (*Database) InsertOperation ¶
func (d *Database) InsertOperation(ctx context.Context, record OperationRecord) error
func (*Database) InsertOperationWithPlan ¶
func (d *Database) InsertOperationWithPlan(ctx context.Context, record OperationRecord, plan PlanRecord) error
InsertOperationWithPlan commits an immutable plan and its operation in one transaction so execution can never observe an unbound operation.
func (*Database) IntegrityCheck ¶
IntegrityCheck runs SQLite's operational consistency check. PRAGMA queries are intentionally kept outside sqlc because sqlc does not generate them.
func (*Database) OperationByID ¶
func (*Database) OperationByIdempotency ¶
func (*Database) OperationForClient ¶
func (*Database) SaveGrantSnapshot ¶
func (d *Database) SaveGrantSnapshot(ctx context.Context, before, after GrantSnapshot) error
SaveGrantSnapshot atomically persists one lifecycle mutation. before is checked inside the SQL transaction so a stale in-memory snapshot cannot overwrite a newer grant revision.
func (*Database) SaveGrantSnapshotWithPlan ¶
func (d *Database) SaveGrantSnapshotWithPlan(ctx context.Context, before, after GrantSnapshot, plan PlanRecord) error
SaveGrantSnapshotWithPlan commits an immutable plan and its grant lifecycle mutation together. A failure in either half rolls the complete request back.
func (*Database) UnfinishedOperations ¶
func (d *Database) UnfinishedOperations(ctx context.Context) ([]OperationRecord, error)
func (*Database) UpdateOperation ¶
func (*Database) UpdateOperationWithPlan ¶
func (d *Database) UpdateOperationWithPlan(ctx context.Context, record OperationRecord, expectedRevision int64, plan PlanRecord) (bool, error)
UpdateOperationWithPlan commits an immutable plan and its operation binding in one transaction.
type GrantDecisionRecord ¶
type GrantLifecycleRecord ¶
type GrantRecord ¶
type GrantRecord struct {
ID, DecisionTokenVerifier, Client, ClientRequestID, Operation string
TargetJSON, AttrsJSON, MetadataJSON []byte
PlanDigest, Reason, Status string
Revision int64
CreatedAt, PendingExpiresAt time.Time
ExpiresAt time.Time
Duration, RequestedDuration, PendingTimeout time.Duration
DecidedAt time.Time
DecidedBy, DecidedOnBehalfOf string
UsedAt time.Time
UsedCount, UseRevision, ReservedCount int
ReservedAt time.Time
ReservationRetained bool
ReservationRevision int
MaxUses, RequestedMaxUses *int
RequestedMaxUsesDefaulted bool
ExpiredFrom string
NotificationJSON []byte
NotificationStatus string
NotificationClaimedAt, NotificationClaimUntil time.Time
NotificationDeliveryUnresolved bool
}
type GrantSnapshot ¶
type GrantSnapshot struct {
Grants []GrantRecord
Events []GrantLifecycleRecord
Decisions []GrantDecisionRecord
Outbox []NotificationOutboxRecord
}
type OperationRecord ¶
type OperationRecord struct {
ID string
APIVersion string
Broker string
ClientID string
IdempotencyKey string
Operation string
TargetJSON []byte
ArgumentsJSON []byte
Reason string
State string
Revision int64
CreatedAt time.Time
UpdatedAt time.Time
TerminalAt *time.Time
ApprovalID string
PresentationJSON []byte
ResultJSON []byte
ErrorJSON []byte
PlanDigest string
}