Очередь job получила lease и fencing, телеметрия и прогресс deploy сохраняются, ревизия пишет manifest входов. Обновление префиксов не переписывает неизменённый снимок, большие наборы идут через COPY, а устаревшая ревизия не попадает в deploy. Бандл ноды кэшируется, prune и постановка job больше не держат горячий путь. Co-authored-by: Cursor <[email protected]>
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
// moduleIngestInputHash fingerprints module config and child entries so snapshots invalidate on CRUD.
|
|
func moduleIngestInputHash(st store.Backend, tenantID string, mod *store.Module) (string, error) {
|
|
return store.ComputeModuleInputHash(st, tenantID, mod)
|
|
}
|
|
|
|
func persistModuleSnapshot(ctx context.Context, st store.Backend, tenantID string, mod *store.Module, rows []store.PrefixRow) error {
|
|
if st == nil || mod == nil {
|
|
return nil
|
|
}
|
|
hash, err := moduleIngestInputHash(st, tenantID, mod)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return st.SetModulePrefixSnapshot(ctx, tenantID, mod.ID, hash, rows)
|
|
}
|
|
|
|
// snapshotRowsIfCurrent returns rows when snap still matches the module input hash.
|
|
// The caller already loaded snap, so this does not read the snapshot again.
|
|
func snapshotRowsIfCurrent(ctx context.Context, st store.Backend, tenantID string, mod *store.Module, snap *store.ModulePrefixSnapshot) ([]store.PrefixRow, bool, error) {
|
|
if snap == nil {
|
|
return nil, false, nil
|
|
}
|
|
if h := strings.TrimSpace(mod.InputHash); h != "" {
|
|
if snap.InputHash != h {
|
|
return nil, false, nil
|
|
}
|
|
return append([]store.PrefixRow(nil), snap.Prefixes...), true, nil
|
|
}
|
|
// Fallback for rows written before module.input_hash existed: recompute and backfill.
|
|
hash, err := moduleIngestInputHash(st, tenantID, mod)
|
|
if err != nil {
|
|
return nil, false, err
|
|
}
|
|
if snap.InputHash != hash {
|
|
return nil, false, nil
|
|
}
|
|
if err := st.SetModuleInputHash(ctx, tenantID, mod.ID, hash); err != nil {
|
|
return nil, false, err
|
|
}
|
|
return append([]store.PrefixRow(nil), snap.Prefixes...), true, nil
|
|
}
|