db

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBatchAlreadyClosed = errors.New("batch already closed")
)

Functions

This section is empty.

Types

type AppendAuditParams

type AppendAuditParams struct {
	Actor   string
	Action  string
	Subject string
	Details []byte
}

type AppendEventBatchResults

type AppendEventBatchResults struct {
	// contains filtered or unexported fields
}

func (*AppendEventBatchResults) Close

func (b *AppendEventBatchResults) Close() error

func (*AppendEventBatchResults) Exec

func (b *AppendEventBatchResults) Exec(f func(int, error))

type AppendEventParams

type AppendEventParams struct {
	TaskID  string
	Seq     int64
	Kind    string
	Ts      time.Time
	Payload []byte
}

type AppendLogChunkBatchResults

type AppendLogChunkBatchResults struct {
	// contains filtered or unexported fields
}

func (*AppendLogChunkBatchResults) Close

func (b *AppendLogChunkBatchResults) Close() error

func (*AppendLogChunkBatchResults) Exec

func (b *AppendLogChunkBatchResults) Exec(f func(int, error))

type AppendLogChunkParams

type AppendLogChunkParams struct {
	TaskID       string
	Seq          int64
	Stream       string
	Sidecar      *string
	Ts           time.Time
	Bytes        []byte
	SourceOffset int64
}

type Artifact

type Artifact struct {
	ID          string
	TaskID      string
	Kind        string
	Name        string
	ObjectKey   string
	SizeBytes   int64
	ContentType string
	Sha256      string
	CreatedAt   time.Time
}

type AssignTaskParams

type AssignTaskParams struct {
	NodeID         *string
	LeaseID        *string
	LeaseExpiresAt *time.Time
	ID             string
}

type AuditLog

type AuditLog struct {
	ID      int64
	Ts      time.Time
	Actor   string
	Action  string
	Subject string
	Details []byte
}

type ConsumeEnrollmentTokenParams

type ConsumeEnrollmentTokenParams struct {
	UsedByNodeID *string
	TokenHash    []byte
}

type CreateArtifactParams

type CreateArtifactParams struct {
	ID          string
	TaskID      string
	Kind        string
	Name        string
	ObjectKey   string
	SizeBytes   int64
	ContentType string
	Sha256      string
}

type CreateEnrollmentTokenParams

type CreateEnrollmentTokenParams struct {
	ID        string
	TokenHash []byte
	Labels    []byte
	ExpiresAt time.Time
	CreatedBy string
}

type CreateNodeParams

type CreateNodeParams struct {
	ID          string
	Name        string
	Tags        []string
	Labels      []byte
	Capacity    []byte
	NodeKeyHash []byte
	Status      string
	Version     *string
	TsStableID  *string
}

type CreateSessionParams added in v0.2.0

type CreateSessionParams struct {
	ID        string
	TokenHash []byte
	Login     string
	ExpiresAt time.Time
}

type CreateTaskParams

type CreateTaskParams struct {
	ID          string
	Spec        []byte
	Status      string
	Priority    int32
	RequestedBy string
	MaxAttempts int32
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
}

type EnrollmentToken

type EnrollmentToken struct {
	ID           string
	TokenHash    []byte
	Labels       []byte
	ExpiresAt    time.Time
	UsedAt       *time.Time
	UsedByNodeID *string
	CreatedBy    string
	CreatedAt    time.Time
}

type ExtendLeaseParams

type ExtendLeaseParams struct {
	LeaseExpiresAt *time.Time
	ID             string
	LeaseID        *string
}

type InsertInstanceParams added in v0.2.0

type InsertInstanceParams struct {
	HostedDomain string
	ClaimedBy    string
}

type Instance added in v0.2.0

type Instance struct {
	ID           int32
	HostedDomain string
	ClaimedBy    string
	ClaimedAt    time.Time
}

type ListArtifactsByKindParams

type ListArtifactsByKindParams struct {
	TaskID string
	Kind   string
}

type ListAuditParams

type ListAuditParams struct {
	Action   string
	Subject  string
	RowLimit int32
}

type ListEventsParams

type ListEventsParams struct {
	TaskID    string
	FromSeq   int64
	PageLimit int32
}

type ListLogChunksParams

type ListLogChunksParams struct {
	TaskID    string
	FromSeq   int64
	PageLimit int32
}

type ListTasksOnNodeParams

type ListTasksOnNodeParams struct {
	NodeID   *string
	Statuses []string
}

type ListTasksParams

type ListTasksParams struct {
	Statuses      []string
	NodeID        string
	RequestedBy   string
	Search        string
	CreatedAfter  *time.Time
	CreatedBefore *time.Time
	AfterID       string
	PageLimit     int32
}

type MarkLogsRolledUpParams

type MarkLogsRolledUpParams struct {
	HighSeq      int64
	StdoutOffset int64
	StderrOffset int64
	ID           string
}

type MarkScheduleAttemptParams

type MarkScheduleAttemptParams struct {
	QueuedReason string
	ID           string
}

type Node

type Node struct {
	ID               string
	Name             string
	Tags             []string
	Labels           []byte
	Capacity         []byte
	NodeKeyHash      []byte
	Status           string
	Version          *string
	LastHeartbeatAt  *time.Time
	CreatedAt        time.Time
	TsStableID       *string
	Draining         bool
	MaxTasksOverride *int32
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) AppendAudit

func (q *Queries) AppendAudit(ctx context.Context, arg AppendAuditParams) (AuditLog, error)

func (*Queries) AppendEvent

func (q *Queries) AppendEvent(ctx context.Context, arg []AppendEventParams) *AppendEventBatchResults

AppendEvent is issued as a pgx batch, so a whole event batch costs one round trip. The (task_id, seq) primary key plus DO NOTHING makes a replayed batch a no-op.

func (*Queries) AppendLogChunk

func (*Queries) AssignTask

func (q *Queries) AssignTask(ctx context.Context, arg AssignTaskParams) (Task, error)

func (*Queries) ClaimActiveTasks

func (q *Queries) ClaimActiveTasks(ctx context.Context) ([]Task, error)

ClaimActiveTasks is the reconciliation sweep: every task the control plane still owes someone an answer for. It is deliberately not paginated — a control plane with more than a few thousand tasks in flight has a bigger problem than this query.

func (*Queries) ClaimQueuedTasks

func (q *Queries) ClaimQueuedTasks(ctx context.Context, pageLimit int32) ([]Task, error)

ClaimQueuedTasks must run inside a transaction: FOR UPDATE SKIP LOCKED only partitions candidates between concurrent claimers for as long as their transactions stay open.

func (*Queries) ConsumeEnrollmentToken

func (q *Queries) ConsumeEnrollmentToken(ctx context.Context, arg ConsumeEnrollmentTokenParams) (EnrollmentToken, error)

ConsumeEnrollmentToken is the whole single-use check: one statement, so two racing enrollments cannot both win.

func (*Queries) CreateArtifact

func (q *Queries) CreateArtifact(ctx context.Context, arg CreateArtifactParams) (Artifact, error)

func (*Queries) CreateEnrollmentToken

func (q *Queries) CreateEnrollmentToken(ctx context.Context, arg CreateEnrollmentTokenParams) (EnrollmentToken, error)

func (*Queries) CreateNode

func (q *Queries) CreateNode(ctx context.Context, arg CreateNodeParams) (Node, error)

func (*Queries) CreateSession added in v0.2.0

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)

func (*Queries) CreateTask

func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error)

func (*Queries) DeleteNode

func (q *Queries) DeleteNode(ctx context.Context, id string) (int64, error)

func (*Queries) DeleteRegistry

func (q *Queries) DeleteRegistry(ctx context.Context, host string) (int64, error)

func (*Queries) DeleteSecret

func (q *Queries) DeleteSecret(ctx context.Context, name string) (int64, error)

func (*Queries) DeleteSessionByTokenHash added in v0.2.0

func (q *Queries) DeleteSessionByTokenHash(ctx context.Context, tokenHash []byte) error

func (*Queries) ExtendLease

func (q *Queries) ExtendLease(ctx context.Context, arg ExtendLeaseParams) (int64, error)

ExtendLease pushes a live task's lease out. It is guarded by the lease id as well as the id, so a stale scheduler cannot extend a lease that has already moved to another node.

func (*Queries) GetArtifact

func (q *Queries) GetArtifact(ctx context.Context, id string) (Artifact, error)

func (*Queries) GetEnrollmentTokenByHash

func (q *Queries) GetEnrollmentTokenByHash(ctx context.Context, tokenHash []byte) (EnrollmentToken, error)

func (*Queries) GetInstance added in v0.2.0

func (q *Queries) GetInstance(ctx context.Context) (Instance, error)

func (*Queries) GetNode

func (q *Queries) GetNode(ctx context.Context, id string) (Node, error)

func (*Queries) GetNodeByKeyHash

func (q *Queries) GetNodeByKeyHash(ctx context.Context, nodeKeyHash []byte) (Node, error)

func (*Queries) GetRegistries

func (q *Queries) GetRegistries(ctx context.Context, hosts []string) ([]Registry, error)

func (*Queries) GetSecret

func (q *Queries) GetSecret(ctx context.Context, name string) (Secret, error)

func (*Queries) GetSecrets

func (q *Queries) GetSecrets(ctx context.Context, names []string) ([]Secret, error)

func (*Queries) GetSessionByTokenHash added in v0.2.0

func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (Session, error)

func (*Queries) GetTask

func (q *Queries) GetTask(ctx context.Context, id string) (Task, error)

func (*Queries) GetTaskForUpdate

func (q *Queries) GetTaskForUpdate(ctx context.Context, id string) (Task, error)

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, login string) (User, error)

func (*Queries) InsertInstance added in v0.2.0

func (q *Queries) InsertInstance(ctx context.Context, arg InsertInstanceParams) (Instance, error)

func (*Queries) ListArtifacts

func (q *Queries) ListArtifacts(ctx context.Context, taskID string) ([]Artifact, error)

func (*Queries) ListArtifactsByKind

func (q *Queries) ListArtifactsByKind(ctx context.Context, arg ListArtifactsByKindParams) ([]Artifact, error)

ListArtifactsByKind is how the roll-up finds the objects it wrote for a task, so a pruned task's logs can be served back from the object store.

func (*Queries) ListAudit

func (q *Queries) ListAudit(ctx context.Context, arg ListAuditParams) ([]AuditLog, error)

func (*Queries) ListEvents

func (q *Queries) ListEvents(ctx context.Context, arg ListEventsParams) ([]TaskEvent, error)

func (*Queries) ListLogChunks

func (q *Queries) ListLogChunks(ctx context.Context, arg ListLogChunksParams) ([]TaskLogChunk, error)

func (*Queries) ListNodes

func (q *Queries) ListNodes(ctx context.Context) ([]Node, error)

func (*Queries) ListRegistries

func (q *Queries) ListRegistries(ctx context.Context) ([]Registry, error)

func (*Queries) ListRegistriesForUpdate

func (q *Queries) ListRegistriesForUpdate(ctx context.Context) ([]Registry, error)

func (*Queries) ListSecrets

func (q *Queries) ListSecrets(ctx context.Context) ([]Secret, error)

func (*Queries) ListSecretsForUpdate

func (q *Queries) ListSecretsForUpdate(ctx context.Context) ([]Secret, error)

ListSecretsForUpdate is the rotation read: it locks every row so a concurrent SetSecret waits rather than being re-encrypted under a key it did not use.

func (*Queries) ListTasks

func (q *Queries) ListTasks(ctx context.Context, arg ListTasksParams) ([]Task, error)

The search clause uses starts_with/strpos rather than like, so a user typing % or _ is searching for those characters instead of writing a wildcard nobody asked for.

func (*Queries) ListTasksOnNode

func (q *Queries) ListTasksOnNode(ctx context.Context, arg ListTasksOnNodeParams) ([]Task, error)

func (*Queries) MarkLogsRolledUp

func (q *Queries) MarkLogsRolledUp(ctx context.Context, arg MarkLogsRolledUpParams) error

func (*Queries) MarkScheduleAttempt

func (q *Queries) MarkScheduleAttempt(ctx context.Context, arg MarkScheduleAttemptParams) error

func (*Queries) MaxEventSeq

func (q *Queries) MaxEventSeq(ctx context.Context, taskID string) (int64, error)

func (*Queries) MaxLogChunkSeq

func (q *Queries) MaxLogChunkSeq(ctx context.Context, taskID string) (int64, error)

func (*Queries) MaxTaskSeq

func (q *Queries) MaxTaskSeq(ctx context.Context, taskID string) (int64, error)

MaxTaskSeq folds in tasks.logs_high_seq for the same reason TaskStreamOffsets folds in the offsets: pruning a rolled-up task's chunks must not let the high-water mark drop, or a synthetic event would collide with a sequence number that is already spent.

func (*Queries) NotifyTaskEvents

func (q *Queries) NotifyTaskEvents(ctx context.Context, taskID string) error

func (*Queries) PruneRolledUpLogChunks

func (q *Queries) PruneRolledUpLogChunks(ctx context.Context, olderThan time.Time) (int64, error)

PruneRolledUpLogChunks drops the hot rows of tasks whose logs are safely in the object store and have been for longer than the grace period. It is deliberately scoped by task rather than by chunk age: a task still running after the horizon would otherwise have its own log truncated under it.

func (*Queries) ReEncryptRegistry

func (q *Queries) ReEncryptRegistry(ctx context.Context, arg ReEncryptRegistryParams) (int64, error)

func (*Queries) ReEncryptSecret

func (q *Queries) ReEncryptSecret(ctx context.Context, arg ReEncryptSecretParams) (int64, error)

func (*Queries) RequestCancel

func (q *Queries) RequestCancel(ctx context.Context, arg RequestCancelParams) (Task, error)

RequestCancel records a durable stop intent. TransitionTask reads it back and rewrites the terminal status the node's finished event would otherwise have produced, so a server restart between the request and the event cannot lose it.

func (*Queries) SetNodeDraining

func (q *Queries) SetNodeDraining(ctx context.Context, arg SetNodeDrainingParams) (int64, error)

func (*Queries) SetNodeLabels

func (q *Queries) SetNodeLabels(ctx context.Context, arg SetNodeLabelsParams) (Node, error)

func (*Queries) SetNodeMaxTasks

func (q *Queries) SetNodeMaxTasks(ctx context.Context, arg SetNodeMaxTasksParams) (int64, error)

func (*Queries) SetNodeStatus

func (q *Queries) SetNodeStatus(ctx context.Context, arg SetNodeStatusParams) (int64, error)

func (*Queries) SetNodeTSStableID

func (q *Queries) SetNodeTSStableID(ctx context.Context, arg SetNodeTSStableIDParams) (int64, error)

func (*Queries) SetUserRoles added in v0.2.0

func (q *Queries) SetUserRoles(ctx context.Context, arg SetUserRolesParams) (User, error)

func (*Queries) TaskLogRollUp

func (q *Queries) TaskLogRollUp(ctx context.Context, id string) (TaskLogRollUpRow, error)

func (*Queries) TaskStreamOffsets

func (q *Queries) TaskStreamOffsets(ctx context.Context, taskID string) (TaskStreamOffsetsRow, error)

TaskStreamOffsets is the reconciliation answer for one task: how far into each of the container's own streams the control plane has committed. Sidecar chunks are excluded — an adopted task's sidecars are never re-attached, so their offsets mean nothing.

The stored roll-up watermarks are folded in with greatest() so the answer cannot go backwards when a rolled-up task's chunks are pruned. A node resumed from a smaller offset would re-send the whole container log under fresh sequence numbers, which is exactly the duplicate step 12 exists to have fixed.

func (*Queries) TasksPendingLogRollUp

func (q *Queries) TasksPendingLogRollUp(ctx context.Context, arg TasksPendingLogRollUpParams) ([]string, error)

TasksPendingLogRollUp is every terminal task whose logs are still only in Postgres. finished_at is null for a task the control plane wrote off without a node event, so coalesce it to created_at rather than skipping the task forever.

func (*Queries) UpdateNodeHeartbeat

func (q *Queries) UpdateNodeHeartbeat(ctx context.Context, arg UpdateNodeHeartbeatParams) (Node, error)

func (*Queries) UpdateTaskTransition

func (q *Queries) UpdateTaskTransition(ctx context.Context, arg UpdateTaskTransitionParams) (Task, error)

UpdateTaskTransition applies the patch columns; a nil patch field leaves the column alone. Requeueing (to_status = 'queued') always clears the node and lease bookkeeping.

func (*Queries) UpsertRegistry

func (q *Queries) UpsertRegistry(ctx context.Context, arg UpsertRegistryParams) (Registry, error)

func (*Queries) UpsertSecret

func (q *Queries) UpsertSecret(ctx context.Context, arg UpsertSecretParams) (Secret, error)

func (*Queries) UpsertUser

func (q *Queries) UpsertUser(ctx context.Context, arg UpsertUserParams) (User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type ReEncryptRegistryParams

type ReEncryptRegistryParams struct {
	Ciphertext []byte
	Nonce      []byte
	KeyID      string
	Host       string
}

type ReEncryptSecretParams

type ReEncryptSecretParams struct {
	Ciphertext []byte
	Nonce      []byte
	KeyID      string
	Name       string
}

type Registry

type Registry struct {
	Host       string
	Username   string
	Ciphertext []byte
	Nonce      []byte
	KeyID      string
	CreatedBy  string
	UpdatedAt  time.Time
}

type RequestCancelParams

type RequestCancelParams struct {
	CancelReason string
	CancelStatus string
	ID           string
}

type Secret

type Secret struct {
	Name       string
	Ciphertext []byte
	Nonce      []byte
	Version    int32
	KeyID      string
	CreatedBy  string
	UpdatedAt  time.Time
}

type Session added in v0.2.0

type Session struct {
	ID        string
	TokenHash []byte
	Login     string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type SetNodeDrainingParams

type SetNodeDrainingParams struct {
	Draining bool
	ID       string
}

type SetNodeLabelsParams

type SetNodeLabelsParams struct {
	Labels []byte
	ID     string
}

type SetNodeMaxTasksParams

type SetNodeMaxTasksParams struct {
	MaxTasksOverride *int32
	ID               string
}

type SetNodeStatusParams

type SetNodeStatusParams struct {
	Status string
	ID     string
}

type SetNodeTSStableIDParams

type SetNodeTSStableIDParams struct {
	TsStableID *string
	ID         string
}

type SetUserRolesParams added in v0.2.0

type SetUserRolesParams struct {
	Roles []string
	Login string
}

type Task

type Task struct {
	ID                    string
	Spec                  []byte
	Status                string
	Priority              int32
	RequestedBy           string
	NodeID                *string
	LeaseID               *string
	LeaseExpiresAt        *time.Time
	Attempts              int32
	MaxAttempts           int32
	CreatedAt             time.Time
	ScheduledAt           *time.Time
	StartedAt             *time.Time
	FinishedAt            *time.Time
	ExitCode              *int32
	Usage                 []byte
	FailureReason         *string
	LastScheduleAttemptAt *time.Time
	QueuedReason          *string
	CancelRequestedAt     *time.Time
	CancelReason          *string
	CancelStatus          *string
	LogsRolledUpAt        *time.Time
	LogsHighSeq           int64
	LogsStdoutOffset      int64
	LogsStderrOffset      int64
}

type TaskEvent

type TaskEvent struct {
	TaskID  string
	Seq     int64
	Kind    string
	Ts      time.Time
	Payload []byte
}

type TaskLogChunk

type TaskLogChunk struct {
	TaskID       string
	Seq          int64
	Stream       string
	Sidecar      *string
	Ts           time.Time
	Bytes        []byte
	SourceOffset int64
}

type TaskLogRollUpRow

type TaskLogRollUpRow struct {
	LogsRolledUpAt   *time.Time
	LogsHighSeq      int64
	LogsStdoutOffset int64
	LogsStderrOffset int64
}

type TaskStreamOffsetsRow

type TaskStreamOffsetsRow struct {
	StdoutOffset int64
	StderrOffset int64
}

type TasksPendingLogRollUpParams

type TasksPendingLogRollUpParams struct {
	FinishedBefore time.Time
	PageLimit      int32
}

type UpdateNodeHeartbeatParams

type UpdateNodeHeartbeatParams struct {
	Status   string
	Capacity []byte
	Version  *string
	ID       string
}

type UpdateTaskTransitionParams

type UpdateTaskTransitionParams struct {
	ToStatus       string
	StartedAt      *time.Time
	FinishedAt     *time.Time
	ExitCode       *int32
	Usage          []byte
	FailureReason  *string
	NodeID         *string
	LeaseID        *string
	LeaseExpiresAt *time.Time
	ID             string
}

type UpsertRegistryParams

type UpsertRegistryParams struct {
	Host       string
	Username   string
	Ciphertext []byte
	Nonce      []byte
	KeyID      string
	CreatedBy  string
}

type UpsertSecretParams

type UpsertSecretParams struct {
	Name       string
	Ciphertext []byte
	Nonce      []byte
	KeyID      string
	CreatedBy  string
}

type UpsertUserParams

type UpsertUserParams struct {
	Login        string
	DisplayName  *string
	HostedDomain *string
	PictureUrl   *string
}

type User

type User struct {
	Login        string
	DisplayName  *string
	Roles        []string
	FirstSeenAt  time.Time
	HostedDomain *string
	PictureUrl   *string
}

Jump to

Keyboard shortcuts

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