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 | 有活跃 Run | 0 |
| Warm | goroutine/DB 在 | 0 |
| Cool | 磁盘保留,无 goroutine | 100-500ms |
| Cold | Stopped | 1-3s |
温度转换
Hot → Warm(Run 结束)
Warm → Cool(idle 15min)
Cool → Cold(idle N 天)
外设需 Warm(Cron/IMAP)→ Cell 无法 Cool。
Cool 态首请求
- Gateway:自动 WarmUp
- SDK:同步唤醒
Cold 态首请求
- Gateway:503 +
Retry-After: 5+ 异步唤醒 - SDK:同步唤醒
Hypervisor 启动序列
hyp, _ := wesgine.NewHypervisor(ctx, config)
hyp.Start(ctx) // 只挂 Cool/Cold 骨架
hyp.ActivatePersisted(ctx) // HTTP serve 后、后台执行
INV-SERVE-REACHABLE-01:可达性不随数据量增长。
hyp.Start永不Cell.StartActivatePersisted在监听端口之后、后台 goroutine 里- 热身可被取消(每轮查
ctx.Err())
GetOrCreate 流程
GetOrCreate(spec)
↓
registry 查找
├── 找到 → merge json:"-" hook → EnsureActive
└── 未找到 → Create(spec) → Start
关键约束:
- 禁止在 GetOrCreate 前调用 ActivatePersisted
- json:"-" hook 必须在 GetOrCreate 前绑齐
- wes:/org: SourceLive 缺 getter → fail-loud
Cell 身份连续性
INV-CELL-06:registry 有 ID ⇔ 内存必有骨架(Stopped 除外)。
Get未命中必须 hydrate- restore/Create 失败不得把仍注册的目录当孤儿改名
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 状态。
相关文档
- CellSpec 总览 →
cellspec-overview.md - Cell Boot 序列 →
cell-boot-sequence.md - Cell 温度管理 →
cell-temperature.md - 数据韧性 →
data-resilience.md