From e5ed8a29684c221915cc092d1f45082bf60e30e6 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Fri, 20 Sep 2024 10:30:29 -0400 Subject: [PATCH] Add to job table when unsetting job tag on latest version --- nomad/state/state_store.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 75184400edc..48f4ee4a8ab 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -4982,17 +4982,6 @@ func (s *StateStore) updateJobVersionTagImpl(index uint64, namespace, jobID stri return s.upsertJobVersion(index, versionCopy, txn) } -func (s *StateStore) UnsetJobVersionTag(index uint64, namespace, jobID string, name string) error { - txn := s.db.WriteTxn(index) - defer txn.Abort() - - if err := s.unsetJobVersionTagImpl(index, namespace, jobID, name, txn); err != nil { - return err - } - - return txn.Commit() -} - func (s *StateStore) unsetJobVersionTagImpl(index uint64, namespace, jobID string, name string, txn *txn) error { job, err := s.JobVersionByTagName(nil, namespace, jobID, name) if err != nil { @@ -5005,6 +4994,16 @@ func (s *StateStore) unsetJobVersionTagImpl(index uint64, namespace, jobID strin versionCopy := job.Copy() versionCopy.TaggedVersion = nil versionCopy.ModifyIndex = index + latestJob, err := s.JobByID(nil, namespace, jobID) + if err != nil { + return err + } + if versionCopy.Version == latestJob.Version { + if err := txn.Insert("jobs", versionCopy); err != nil { + return err + } + } + return s.upsertJobVersion(index, versionCopy, txn) }