runtime

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package runtime encapsulates the unified IPC bootstrap sequence that every Pando entrypoint follows: open the database, derive ports, try the IPC lock, and wire the leader or follower role accordingly.

The IPC role no longer has anything to do with database writes: every instance opens pando.db read-write through the multi-writer engine (internal/db). The lock only elects the leader that runs the singleton background jobs (code index and its watcher, evaluator sweeps) and serves the IPC bus (instance browsing, remote view, hot-peer delegation).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BootstrapResult

type BootstrapResult struct {
	Role Role

	// Querier is the db.Querier callers should use for all DB operations: a
	// direct querier on SQLDB in every role.
	Querier db.Querier

	// SQLDB is the read-write connection pool on pando.db (migrations applied).
	SQLDB *sql.DB

	// Bus is non-nil only on the leader.
	Bus *ipc.Bus

	// IPCClient is non-nil only on followers (heartbeat subscription).
	IPCClient *ipc.Client

	InstanceID string
	PubPort    int
	RPCPort    int

	// LockFile is the open flock file held by the leader, nil on followers.
	LockFile *os.File

	// Watcher monitors leader liveness. Always non-nil.
	Watcher *failover.Watcher

	// Cleanup releases all resources acquired during Bootstrap in reverse order.
	// The caller MUST call this exactly once on shutdown.
	Cleanup func()
}

BootstrapResult carries everything a caller needs after Bootstrap returns. Call Cleanup() on shutdown to release resources in correct order.

func Bootstrap

func Bootstrap(ctx context.Context, workdir, instanceID string) (*BootstrapResult, error)

Bootstrap runs the unified startup sequence for the given workdir.

  1. Open pando.db read-write through the engine (migrations serialised across processes by internal/db).
  2. Derive deterministic PUB/RPC ports from the path.
  3. Attempt to acquire the exclusive IPC lock.
  4. Leader: settle its bus ports (ipc.ClaimLeaderPorts), create the Bus and the leader watcher.
  5. Follower: create the IPC client and a follower watcher.

On lock error the function continues as leader so the caller does not lose functionality — consistent with the existing root.go behaviour.

type Role

type Role string

Role describes the IPC role that this instance took during bootstrap.

const (
	// RolePrimary is the leader: it holds the IPC lock and serves the bus.
	RolePrimary Role = "primary"
	// RoleSecondary is a follower: another process holds the IPC lock.
	RoleSecondary Role = "secondary"
)

Jump to

Keyboard shortcuts

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