Cell 生命周期

wesgine Cell 从创建到销毁的完整生命周期管理。


生命周期操作

Create → Start → Hot/Warm/Cool → Stop → Delete

创建

cell, err := hyp.Cells().Create(ctx, CellSpec{ID: "dept-legal", ...})

或幂等创建:

cell, err := hyp.Cells().GetOrCreate(ctx, spec)

启动

err := cell.Start(ctx) // 由 GetOrCreate 内部调用

INV-CELL-08:Cell.Start 的合法输入 = 身份 + 已 Bind 的进程 hook。hyp.Start 永不 Cell.Start。

停止

err := hyp.Cells().Stop(ctx, cellID)

排空活跃 Run,释放资源。

删除

err := hyp.Cells().Delete(ctx, cellID)

删除 registry 行 + 磁盘字节,二者都删,无保留模式。

重启

err := hyp.Cells().Restart(ctx, cellID)

Stop + Start 的组合。


温度状态

温度含义激活成本
Hot有活跃 Run0
Warmgoroutine/DB 在0
Cool磁盘保留,无 goroutine100-500ms
ColdStopped1-3s

温度转换

Hot → Warm(Run 结束)
Warm → Cool(idle 15min)
Cool → Cold(idle N 天)

外设需 Warm(Cron/IMAP)→ Cell 无法 Cool。

Cool 态首请求

Cold 态首请求


Hypervisor 启动序列

hyp, _ := wesgine.NewHypervisor(ctx, config)
hyp.Start(ctx)                    // 只挂 Cool/Cold 骨架
hyp.ActivatePersisted(ctx)        // HTTP serve 后、后台执行

INV-SERVE-REACHABLE-01:可达性不随数据量增长。


GetOrCreate 流程

GetOrCreate(spec)
    ↓
registry 查找
    ├── 找到 → merge json:"-" hook → EnsureActive
    └── 未找到 → Create(spec) → Start

关键约束:


Cell 身份连续性

INV-CELL-06:registry 有 ID ⇔ 内存必有骨架(Stopped 除外)。

INV-CELL-07:孤儿目录改名仅在 registry.Create 成功之后。


Export / Import

导出

reader, err := hyp.Cells().Export(ctx, cellID)

默认包含 workspace/,.scratch/ 永不包含。

导入

newID, err := hyp.Cells().Import(ctx, reader, ImportOpts{})

故障重置

err := hyp.Cells().ResetFaults(ctx, cellID)

重置故障计数,清除 faulted 状态。


相关文档