From 113eb67ee063e249a73e39b7a75133a82aed03cb Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Tue, 28 Oct 2014 11:25:09 +1100 Subject: [PATCH] go.tools/dashboard/app: update commit in transaction on perf regression The sendPerfFailMail function populated a dummy commit value and then calls commonNotify, which then updated and stored that dummy commit, hosing the original commit entity. LGTM=rsc R=rsc, bradfitz, dvyukov CC=golang-codereviews https://golang.org/cl/164960043 --- dashboard/app/build/notify.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dashboard/app/build/notify.go b/dashboard/app/build/notify.go index abb5ef1a747..42fa04dfcbf 100644 --- a/dashboard/app/build/notify.go +++ b/dashboard/app/build/notify.go @@ -201,21 +201,28 @@ var ( ) func sendPerfFailMail(c appengine.Context, builder string, res *PerfResult) error { - com := &Commit{Hash: res.CommitHash} - logHash := "" - parsed := res.ParseData() - for _, data := range parsed[builder] { - if !data.OK { - logHash = data.Artifacts["log"] - break + return datastore.RunInTransaction(c, func(c appengine.Context) error { + com := &Commit{Hash: res.CommitHash} + if err := datastore.Get(c, com.Key(c), com); err != nil { + return err } - } - if logHash == "" { - return fmt.Errorf("can not find failed result for commit %v on builder %v", com.Hash, builder) - } - return commonNotify(c, com, builder, logHash) + logHash := "" + parsed := res.ParseData() + for _, data := range parsed[builder] { + if !data.OK { + logHash = data.Artifacts["log"] + break + } + } + if logHash == "" { + return fmt.Errorf("can not find failed result for commit %v on builder %v", com.Hash, builder) + } + return commonNotify(c, com, builder, logHash) + }, nil) } +// commonNotify MUST!!! be called from within a transaction inside which +// the provided Commit entity was retrieved from the datastore. func commonNotify(c appengine.Context, com *Commit, builder, logHash string) error { if com.Num == 0 || com.Desc == "" { stk := make([]byte, 10000)