Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: state/service.go

Issue 64890044: state: Make unit ids unique. Fix #1174610
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/sequence.go ('k') | state/service_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/service.go
=== modified file 'state/service.go'
--- state/service.go 2014-01-15 06:52:56 +0000
+++ state/service.go 2014-02-17 16:32:56 +0000
@@ -37,7 +37,6 @@
CharmURL *charm.URL
ForceCharm bool
Life Life
- UnitSeq int
UnitCount int
RelationCount int
Exposed bool
@@ -529,15 +528,11 @@
// newUnitName returns the next unit name.
func (s *Service) newUnitName() (string, error) {
- change := mgo.Change{Update: D{{"$inc", D{{"unitseq", 1}}}}}
- result := serviceDoc{}
- if _, err := s.st.services.Find(D{{"_id", s.doc.Name}}).Apply(change, &result); err == mgo.ErrNotFound {
- return "", errors.NotFoundf("service %q", s)
- } else if err != nil {
- return "", fmt.Errorf("cannot increment unit sequence: %v", err)
+ seq, err := s.st.sequence(s.globalKey() + "#unit")
+ if err != nil {
+ return "", err
}
- name := s.doc.Name + "/" + strconv.Itoa(result.UnitSeq)
- return name, nil
+ return s.doc.Name + "/" + strconv.Itoa(seq), nil
}
// addUnitOps returns a unique name for a new unit, and a list of txn operations
@@ -591,7 +586,7 @@
})
} else {
scons, err := s.Constraints()
- if err != nil {
+ if err != nil && !errors.IsNotFoundError(err) {
return "", nil, err
}
econs, err := s.st.EnvironConstraints()
@@ -631,7 +626,7 @@
if alive, err := isAlive(s.st.services, s.doc.Name); err != nil {
return nil, err
} else if !alive {
- return nil, fmt.Errorf("service is not alive")
+ return nil, fmt.Errorf("service is no longer alive")
}
return nil, fmt.Errorf("inconsistent state")
} else if err != nil {
« no previous file with comments | « state/sequence.go ('k') | state/service_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b