Documentation
¶
Overview ¶
Package state 持久化 Runtime 操作状态与生命周期状态。
Index ¶
- Constants
- Variables
- func ValidateTransaction(kind TransactionKind, value TransactionState) error
- type Activity
- type BrokenEnvironment
- type BrokenReason
- type CorruptError
- type EnvironmentState
- type Inspection
- type MutexKind
- type MutexProbe
- type MutexProbeResult
- type NotFoundError
- type Option
- type PIDProbe
- type PIDProbeError
- type ReadError
- type Revision
- type Store
- func (s *Store) Close() error
- func (s *Store) NewBrokenEnvironment(lastSuccessful Revision, broken BrokenEnvironment) (EnvironmentState, error)
- func (s *Store) NewReadyEnvironment(version string, commit string) (EnvironmentState, error)
- func (s *Store) NewTransaction(kind TransactionKind, input TransactionInput) (TransactionState, error)
- func (s *Store) ReadEnvironment(ctx context.Context) (EnvironmentState, error)
- func (s *Store) ReadTransaction(ctx context.Context, kind TransactionKind) (TransactionSnapshot, error)
- func (s *Store) RemoveOwnedTransaction(ctx context.Context, kind TransactionKind, expected TransactionState) error
- func (s *Store) RemoveTransaction(ctx context.Context, snapshot TransactionSnapshot) error
- func (s *Store) ValidateEnvironment(value EnvironmentState) error
- func (s *Store) WriteEnvironment(ctx context.Context, value EnvironmentState) error
- func (s *Store) WriteTransaction(ctx context.Context, kind TransactionKind, value TransactionState) error
- type TransactionInput
- type TransactionKind
- type TransactionSnapshot
- type TransactionState
- type UnsupportedSchemaError
- type ValidationError
- type WriteError
- type WritePhase
Constants ¶
const SchemaVersion = 1
SchemaVersion 是首版状态文件唯一支持的 schema。
Variables ¶
var ErrClosed = errors.New("state store is closed")
ErrClosed 表示 Store 已经关闭文件能力。
var ErrCorrupt = errors.New("state file is corrupt")
ErrCorrupt 表示状态文件内容损坏或违反 v1 schema。
var ErrInvalidPID = errors.New("pid is invalid")
ErrInvalidPID 表示 PID 不能用于 Windows 进程查询。
var ErrNotFound = errors.New("state file not found")
ErrNotFound 表示固定状态文件不存在。
var ErrTransactionChanged = errors.New("state transaction changed")
ErrTransactionChanged 表示条件删除前事务文件身份或内容已经变化。
var ErrUnsupportedSchema = errors.New("state schema is unsupported")
ErrUnsupportedSchema 表示状态文件使用当前 Runtime 不支持的 schema。
Functions ¶
func ValidateTransaction ¶
func ValidateTransaction(kind TransactionKind, value TransactionState) error
ValidateTransaction 对内存输入和磁盘解码值执行同一语义规则。
Types ¶
type Activity ¶
type Activity string
Activity 标识事务状态文件与真实占用的分类结果。
const ( // ActivityActive 表示权威 Mutex 当前被持有。 ActivityActive Activity = "active" // ActivityStale 表示 Mutex free 且记录的 PID 已退出。 ActivityStale Activity = "stale" // ActivityInconsistent 表示 Mutex free 但相同数字的 PID 仍存活。 ActivityInconsistent Activity = "inconsistent" // ActivityUnknown 表示输入或任一必要探针无法确认。 ActivityUnknown Activity = "unknown" )
type BrokenEnvironment ¶
type BrokenEnvironment struct {
TargetVersion string `json:"targetVersion"`
Branch string `json:"branch"`
Commit string `json:"commit"`
PythonVersion string `json:"pythonVersion"`
UVVersion string `json:"uvVersion"`
Reason BrokenReason `json:"reason"`
Stage protocol.Stage `json:"stage"`
ExitCode int `json:"exitCode"`
LogPath string `json:"logPath"`
}
BrokenEnvironment 保存当前 active revision 无法启动主环境的原因。
type BrokenReason ¶
type BrokenReason string
BrokenReason 标识环境失效的稳定原因。
const ( // ReasonRepositoryChanged 表示 active repo 已替换但主环境尚未重新证明可用。 ReasonRepositoryChanged BrokenReason = "repository_changed" // ReasonOperationFailed 表示改变主环境后的具体叶子操作失败。 ReasonOperationFailed BrokenReason = "operation_failed" )
type CorruptError ¶
CorruptError 表示磁盘状态内容不满足严格 schema。
func (*CorruptError) Error ¶
func (e *CorruptError) Error() string
func (*CorruptError) Is ¶
func (e *CorruptError) Is(target error) bool
Is 让 CorruptError 匹配 ErrCorrupt。
type EnvironmentState ¶
type EnvironmentState struct {
SchemaVersion int `json:"schemaVersion"`
Status protocol.StateStatus `json:"status"`
UpdatedAt time.Time `json:"updatedAt"`
LastSuccessful Revision `json:"lastSuccessful"`
Broken *BrokenEnvironment `json:"broken"`
}
EnvironmentState 是跨 Runtime 进程持久化的稳定环境真相。
type Inspection ¶
type Inspection struct {
Activity Activity
MutexHeld bool
MutexRecovered bool
PIDChecked bool
PIDAlive bool
ProbeError error
}
Inspection 是事务文件与 Mutex/PID 事实的失败关闭分类。
func InspectTransaction ¶
func InspectTransaction( ctx context.Context, kind TransactionKind, value TransactionState, pidProbe PIDProbe, mutexProbe MutexProbe, ) Inspection
InspectTransaction 先查询权威 Mutex,只在 free 时查询 PID。
func (Inspection) CanAutoClean ¶
func (i Inspection) CanAutoClean() bool
CanAutoClean 只报告 stale 候选;调用方仍须持 Lease 重读并条件删除。
type MutexProbe ¶
type MutexProbe interface {
Probe(ctx context.Context, kind MutexKind) (MutexProbeResult, error)
}
MutexProbe 按 state 绑定的 MutexKind 查询真实占用。
type MutexProbeResult ¶
MutexProbeResult 保存零等待探测与 abandoned 恢复事实。
type NotFoundError ¶
NotFoundError 表示固定逻辑状态文件不存在。
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Is ¶
func (e *NotFoundError) Is(target error) bool
Is 让 NotFoundError 匹配 ErrNotFound。
type PIDProbeError ¶
PIDProbeError 表示查询指定 PID 的 Win32 操作失败。
func (*PIDProbeError) Error ¶
func (e *PIDProbeError) Error() string
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 线性化状态构造、文件 I/O 和关闭。
func (*Store) NewBrokenEnvironment ¶
func (s *Store) NewBrokenEnvironment( lastSuccessful Revision, broken BrokenEnvironment, ) (EnvironmentState, error)
NewBrokenEnvironment 构造保留最近成功 revision 的失效状态。
func (*Store) NewReadyEnvironment ¶
func (s *Store) NewReadyEnvironment( version string, commit string, ) (EnvironmentState, error)
NewReadyEnvironment 构造依赖已同步成功的稳定状态。
func (*Store) NewTransaction ¶
func (s *Store) NewTransaction( kind TransactionKind, input TransactionInput, ) (TransactionState, error)
NewTransaction 采样一次时钟并构造已完整校验的事务状态。
func (*Store) ReadEnvironment ¶
func (s *Store) ReadEnvironment( ctx context.Context, ) (EnvironmentState, error)
ReadEnvironment 严格读取稳定环境状态并丢弃文件 token。
func (*Store) ReadTransaction ¶
func (s *Store) ReadTransaction( ctx context.Context, kind TransactionKind, ) (TransactionSnapshot, error)
ReadTransaction 严格读取并保留不可重建的事务 snapshot。
func (*Store) RemoveOwnedTransaction ¶
func (s *Store) RemoveOwnedTransaction( ctx context.Context, kind TransactionKind, expected TransactionState, ) error
RemoveOwnedTransaction 仅在当前事务仍与调用方持有的完整业务 snapshot 一致时条件删除。 读取后的物理文件 token 仍由 RemoveTransaction 交给 StateFiles 复验,避免删除后来操作的事务。
func (*Store) RemoveTransaction ¶
func (s *Store) RemoveTransaction( ctx context.Context, snapshot TransactionSnapshot, ) error
RemoveTransaction 使用同一 Store 读取的原 token 条件删除事务。
func (*Store) ValidateEnvironment ¶
func (s *Store) ValidateEnvironment(value EnvironmentState) error
ValidateEnvironment 对内存输入和磁盘解码值执行同一稳定状态规则。
func (*Store) WriteEnvironment ¶
func (s *Store) WriteEnvironment( ctx context.Context, value EnvironmentState, ) error
WriteEnvironment 校验并原子发布稳定环境状态。
func (*Store) WriteTransaction ¶
func (s *Store) WriteTransaction( ctx context.Context, kind TransactionKind, value TransactionState, ) error
WriteTransaction 校验并原子发布一个完整事务状态。
type TransactionInput ¶
type TransactionInput struct {
OperationID string
Command string
PID uint32
TargetVersion string
Stage protocol.Stage
}
TransactionInput 是创建新事务时由应用服务提供的业务身份。
type TransactionKind ¶
type TransactionKind string
TransactionKind 标识三个互不替代的事务文件。
const ( // TransactionBackend 标识 backend supervision 事务。 TransactionBackend TransactionKind = "backend" // TransactionMutation 标识顶层受管变更事务。 TransactionMutation TransactionKind = "mutation" // TransactionUpdate 标识 mutation 内的 Git 更新事务。 TransactionUpdate TransactionKind = "update" )
type TransactionSnapshot ¶
type TransactionSnapshot struct {
// contains filtered or unexported fields
}
TransactionSnapshot 把已校验事务值绑定到 T2.5 原始条件删除 token。
func (TransactionSnapshot) Kind ¶
func (s TransactionSnapshot) Kind() TransactionKind
Kind 返回 snapshot 对应的事务类型。
func (TransactionSnapshot) State ¶
func (s TransactionSnapshot) State() TransactionState
State 返回已校验事务值的副本。
type TransactionState ¶
type TransactionState struct {
SchemaVersion int `json:"schemaVersion"`
OperationID string `json:"operationId"`
Command string `json:"command"`
PID uint32 `json:"pid"`
StartedAt time.Time `json:"startedAt"`
TargetVersion string `json:"targetVersion"`
Stage protocol.Stage `json:"stage"`
}
TransactionState 是三类事务文件共享的完整 JSON schema。
type UnsupportedSchemaError ¶
UnsupportedSchemaError 表示 schemaVersion 是合法整数但当前版本不支持。
func (*UnsupportedSchemaError) Error ¶
func (e *UnsupportedSchemaError) Error() string
func (*UnsupportedSchemaError) Is ¶
func (e *UnsupportedSchemaError) Is(target error) bool
Is 让 UnsupportedSchemaError 匹配 ErrUnsupportedSchema。
type ValidationError ¶
ValidationError 表示调用值或已解码字段违反稳定语义。
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error 仅报告稳定字段名,不回显调用值或磁盘内容。
type WriteError ¶
type WriteError struct {
File string
Phase WritePhase
MutationApplied bool
RecoveryRequired bool
Cause error
CleanupError error
}
WriteError 表示持久化写入或条件删除故障。
func (*WriteError) Error ¶
func (e *WriteError) Error() string
type WritePhase ¶
type WritePhase string
WritePhase 标识持久化写失败发生的稳定阶段。
const ( // WritePhaseEncode 表示稳定 JSON 编码阶段。 WritePhaseEncode WritePhase = "encode" // WritePhaseRecover 表示 guard 取得、preflight 或既有 intent 恢复阶段。 WritePhaseRecover WritePhase = "recover" // WritePhaseCreate 表示临时状态文件创建阶段。 WritePhaseCreate WritePhase = "create" // WritePhaseWrite 表示完整 payload 写入阶段。 WritePhaseWrite WritePhase = "write" // WritePhaseSync 表示临时文件刷盘阶段。 WritePhaseSync WritePhase = "sync" // WritePhaseRename 表示原子发布阶段。 WritePhaseRename WritePhase = "rename" // WritePhaseFinalize 表示 rollback 或事务 leaf POSIX unlink 阶段。 WritePhaseFinalize WritePhase = "finalize" // WritePhaseClose 表示已打开 handle 的收口阶段。 WritePhaseClose WritePhase = "close" // WritePhaseRemove 表示事务条件删除阶段。 WritePhaseRemove WritePhase = "remove" )