package host import ( "context" "errors" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostguard" "os" ) // A row mutation can commit before the inventory journal. Settle that exact // root intention locally even if the claim has since advanced. This grants no // new timer write: SQL is checked only against the effect root already intended. func (h ClaimRootHTTP) settleTimerInventory(ctx context.Context, q hostbox.JournalRequest, raw []byte) (bool, error) { if q.Timer == nil { return false, nil } if h.Reconcile.Registry == nil || h.Journals == nil { return false, hostbox.ErrUnsupported } m := q.Timer applied := func() (bool, error) { row, err := h.Reconcile.Registry.GetTimer(m.Timer.Host, m.Timer.Name) if errors.Is(err, os.ErrNotExist) { return m.Remove, nil } if err != nil { return false, err } return !m.Remove && row != nil && *row == m.Timer, nil } done, err := applied() if err != nil || !done { return false, err } err = h.Stop.Coordinator.Guard.SettleRootInventory(ctx, q.Target.Host, raw, func(in hostguard.RootInstallation) error { if in.Host != q.Inventory.Host || in.Incarnation != q.Inventory.Incarnation || in.Stamp != q.Inventory.InstallationStamp || in.InventoryRevision != q.Revision+1 { return hostbox.ErrChanged } exact, err := applied() if err != nil { return err } if !exact { return hostbox.ErrChanged } _, err = h.Journals.CompletePendingInventory(ctx, in.Box+"/"+in.Enrollment, q) return err }) return err == nil, err }