LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package state | 4 package state |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "labix.org/v2/mgo" | 8 "labix.org/v2/mgo" |
9 "labix.org/v2/mgo/txn" | 9 "labix.org/v2/mgo/txn" |
10 "launchpad.net/juju-core/utils" | 10 "launchpad.net/juju-core/utils" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if i != 0 { | 67 if i != 0 { |
68 return fmt.Errorf("%s no longer exists", a.tag) | 68 return fmt.Errorf("%s no longer exists", a.tag) |
69 } | 69 } |
70 ops, err = a.insertOps(toInsert) | 70 ops, err = a.insertOps(toInsert) |
71 if err != nil { | 71 if err != nil { |
72 return err | 72 return err |
73 } | 73 } |
74 } else { | 74 } else { |
75 ops = a.updateOps(toUpdate, toRemove) | 75 ops = a.updateOps(toUpdate, toRemove) |
76 } | 76 } |
77 » » if err := a.st.runner.Run(ops, "", nil); err == nil { | 77 » » if err := a.st.runTransaction(ops); err == nil { |
78 return nil | 78 return nil |
79 } else if err != txn.ErrAborted { | 79 } else if err != txn.ErrAborted { |
80 return err | 80 return err |
81 } | 81 } |
82 } | 82 } |
83 return ErrExcessiveContention | 83 return ErrExcessiveContention |
84 } | 84 } |
85 | 85 |
86 // insertOps returns the operations required to insert annotations in MongoDB. | 86 // insertOps returns the operations required to insert annotations in MongoDB. |
87 func (a *annotator) insertOps(toInsert map[string]string) ([]txn.Op, error) { | 87 func (a *annotator) insertOps(toInsert map[string]string) ([]txn.Op, error) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // annotationRemoveOp returns an operation to remove a given annotation | 146 // annotationRemoveOp returns an operation to remove a given annotation |
147 // document from MongoDB. | 147 // document from MongoDB. |
148 func annotationRemoveOp(st *State, id string) txn.Op { | 148 func annotationRemoveOp(st *State, id string) txn.Op { |
149 return txn.Op{ | 149 return txn.Op{ |
150 C: st.annotations.Name, | 150 C: st.annotations.Name, |
151 Id: id, | 151 Id: id, |
152 Remove: true, | 152 Remove: true, |
153 } | 153 } |
154 } | 154 } |
LEFT | RIGHT |