instance

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package instance guards one llm-router process per database. The lock file next to the database carries a kernel file lock, so a crashed process never leaves a stale lock behind, and a JSON record of the holder for status, stop and error messages.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("another llm-router instance holds the database")

ErrHeld matches the error returned when another process holds the lock.

Functions

func LockPath

func LockPath(databasePath string) string

LockPath returns the lock file for a database path.

Types

type HeldError

type HeldError struct {
	Info Info
}

HeldError reports the holder of a lock that Acquire could not take.

func (*HeldError) Error

func (err *HeldError) Error() string

func (*HeldError) Unwrap

func (err *HeldError) Unwrap() error

type Info

type Info struct {
	PID        int       `json:"pid"`
	Mode       Mode      `json:"mode"`
	Started    time.Time `json:"started"`
	Executable string    `json:"executable"`
	Address    string    `json:"address"`
	Version    string    `json:"version"`
}

Info describes the lock holder.

func Probe

func Probe(path string) (Info, bool, error)

Probe reports whether a process holds the lock at path and who it is. A missing file means nobody holds it.

type Lock

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

Lock is a held instance lock.

func Acquire

func Acquire(path string, info Info) (*Lock, error)

Acquire takes the exclusive lock and records info. A zero PID and Started are filled from the current process. A held lock returns *HeldError.

func (*Lock) Release

func (lock *Lock) Release() error

Release clears the record and drops the lock. The file stays: removing it would let two processes lock different files of the same name.

type Mode

type Mode string

Mode names how the lock holder was started.

const (
	ModeForeground  Mode = "foreground"
	ModeDaemon      Mode = "daemon"
	ModeMaintenance Mode = "maintenance"
)

Jump to

Keyboard shortcuts

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