Merge lp:~dimitern/juju-core/300-lp-1174610-unit-ids-unique into lp:~go-bot/juju-core/trunk
Status: | Rejected | ||||
---|---|---|---|---|---|
Rejected by: | William Reade | ||||
Proposed branch: | lp:~dimitern/juju-core/300-lp-1174610-unit-ids-unique | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
139 lines (+33/-14) 5 files modified
state/open.go (+1/-0) state/sequence.go (+1/-1) state/service.go (+6/-11) state/service_test.go (+24/-2) state/state.go (+1/-0) |
||||
To merge this branch: | bzr merge lp:~dimitern/juju-core/300-lp-1174610-unit-ids-unique | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+206765@code.launchpad.net |
Description of the change
state: Make unit ids unique. Fix #1174610
This changes the way unit names are generated
when adding a new unit to a service. Before,
we used serviceDoc.UnitSeq to generate the
last part of a unit name. Now, we use the
sequence collection with a key "s#<svcname>#unit"
as the unit ids sequence (as we do for machine,
containers, etc.).
This is a schema change (removing of UnitSeq from
the service document). So it should be handled the
same way as any schema change during an upgrade,
but this CL does not do that.
I realized the sequence collection is not created
as all the other collections in state.Initialize,
so I added it there.
Also added a test to guarantee unit ids increase
each time for the same service name (like the bug
suggests and how it was before).
Per fwereade's suggestion, I changed the error
message AddUnit() returns when a service is not
found: "service is no longer alive" rather than
"service "blah" not found", and also fixed a
test that relied on that.
Reviewers: mp+206765_ code.launchpad. net,
Message:
Please take a look.
Description:
state: Make unit ids unique. Fix #1174610
This changes the way unit names are generated
when adding a new unit to a service. Before,
we used serviceDoc.UnitSeq to generate the
last part of a unit name. Now, we use the
sequence collection with a key "s#<svcname>#unit"
as the unit ids sequence (as we do for machine,
containers, etc.).
This is a schema change (removing of UnitSeq from
the service document). So it should be handled the
same way as any schema change during an upgrade,
but this CL does not do that.
I realized the sequence collection is not created
as all the other collections in state.Initialize,
so I added it there.
Also added a test to guarantee unit ids increase
each time for the same service name (like the bug
suggests and how it was before).
Per fwereade's suggestion, I changed the error
message AddUnit() returns when a service is not
found: "service is no longer alive" rather than
"service "blah" not found", and also fixed a
test that relied on that.
https:/ /code.launchpad .net/~dimitern/ juju-core/ 300-lp- 1174610- unit-ids- unique/ +merge/ 206765
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/64890044/
Affected files (+35, -14 lines): test.go
A [revision details]
M state/open.go
M state/sequence.go
M state/service.go
M state/service_
M state/state.go
Index: [revision details] 20140217133244- ukuzvegy1wqly6n m
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision:
<email address hidden>
Index: state/open.go ns"), ers"), nfo{Capped: true, MaxBytes: logSize}
=== modified file 'state/open.go'
--- state/open.go 2014-02-07 18:38:02 +0000
+++ state/open.go 2014-02-17 16:32:56 +0000
@@ -255,6 +255,7 @@
annotations: db.C("annotatio
statuses: db.C("statuses"),
stateServers: db.C("stateServ
+ sequences: db.C("sequence"),
}
log := db.C("txns.log")
logInfo := mgo.CollectionI
Index: state/sequence.go
=== modified file 'state/sequence.go'
--- state/sequence.go 2013-07-09 10:32:23 +0000
+++ state/sequence.go 2014-02-17 16:32:56 +0000
@@ -16,7 +16,7 @@
}
func (s *State) sequence(name string) (int, error) { "sequence" ).Find( D{{"_id" , name}}) FindId( name)
- query := s.db.C(
+ query := s.sequences.
inc := mgo.Change{
Update: bson.M{"$inc": bson.M{"counter": 1}},
Upsert: true,
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. Find(D{ {"_id", s.doc.Name} }).Apply. ..
func (s *Service) newUnitName() (string, error) {
- change := mgo.Change{Update: D{{"$inc", D{{"unitseq", 1}}}}}
- result := serviceDoc{}
- if _, err := s.st.services.