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

Delta Between Two Patch Sets: state/addmachine.go

Issue 90160044: cmd/juju/ensureavailability: default to 3 servers
Left Patch Set: Created 10 years, 11 months ago
Right Patch Set: cmd/juju/ensureavailability: default to 3 servers Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/juju/ensureavailability_test.go ('k') | state/apiserver/client/client.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 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 "strconv" 8 "strconv"
9 9
10 "labix.org/v2/mgo/bson" 10 "labix.org/v2/mgo/bson"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 {"$addToSet", bson.D{{"votingmachineids", bson.D{{"$each ", newVotingIds}}}}}, 490 {"$addToSet", bson.D{{"votingmachineids", bson.D{{"$each ", newVotingIds}}}}},
491 }, 491 },
492 }} 492 }}
493 return ops, nil 493 return ops, nil
494 } 494 }
495 495
496 // EnsureAvailability adds state server machines as necessary to make 496 // EnsureAvailability adds state server machines as necessary to make
497 // the number of live state servers equal to numStateServers. The given 497 // the number of live state servers equal to numStateServers. The given
498 // constraints and series will be attached to any new machines. 498 // constraints and series will be attached to any new machines.
499 func (st *State) EnsureAvailability(numStateServers int, cons constraints.Value, series string) error { 499 func (st *State) EnsureAvailability(numStateServers int, cons constraints.Value, series string) error {
500 » if numStateServers%2 != 1 || numStateServers <= 0 { 500 » if numStateServers < 0 || (numStateServers != 0 && numStateServers%2 != 1) {
501 » » return fmt.Errorf("number of state servers must be odd and great er than zero") 501 » » return fmt.Errorf("number of state servers must be odd and non-n egative")
502 } 502 }
503 if numStateServers > replicaset.MaxPeers { 503 if numStateServers > replicaset.MaxPeers {
504 return fmt.Errorf("state server count is too large (allowed %d)" , replicaset.MaxPeers) 504 return fmt.Errorf("state server count is too large (allowed %d)" , replicaset.MaxPeers)
505 } 505 }
506 for i := 0; i < 5; i++ { 506 for i := 0; i < 5; i++ {
507 currentInfo, err := st.StateServerInfo() 507 currentInfo, err := st.StateServerInfo()
508 if err != nil { 508 if err != nil {
509 return err 509 return err
510 } 510 }
511 » » if len(currentInfo.VotingMachineIds) > numStateServers { 511 » » desiredStateServerCount := numStateServers
512 » » if desiredStateServerCount == 0 {
513 » » » desiredStateServerCount = len(currentInfo.VotingMachineI ds)
514 » » » if desiredStateServerCount <= 1 {
515 » » » » desiredStateServerCount = 3
516 » » » }
517 » » }
518 » » if len(currentInfo.VotingMachineIds) > desiredStateServerCount {
512 return fmt.Errorf("cannot reduce state server count") 519 return fmt.Errorf("cannot reduce state server count")
513 } 520 }
514 521
515 intent, err := st.ensureAvailabilityIntentions(currentInfo) 522 intent, err := st.ensureAvailabilityIntentions(currentInfo)
516 if err != nil { 523 if err != nil {
517 return err 524 return err
518 } 525 }
519 voteCount := 0 526 voteCount := 0
520 for _, m := range intent.maintain { 527 for _, m := range intent.maintain {
521 if m.WantsVote() { 528 if m.WantsVote() {
522 voteCount++ 529 voteCount++
523 } 530 }
524 } 531 }
525 » » if voteCount == numStateServers && len(intent.remove) == 0 { 532 » » if voteCount == desiredStateServerCount && len(intent.remove) == 0 {
526 return nil 533 return nil
527 } 534 }
528 // Promote as many machines as we can to fulfil the shortfall. 535 // Promote as many machines as we can to fulfil the shortfall.
529 » » if n := numStateServers - voteCount; n < len(intent.promote) { 536 » » if n := desiredStateServerCount - voteCount; n < len(intent.prom ote) {
530 intent.promote = intent.promote[:n] 537 intent.promote = intent.promote[:n]
531 } 538 }
532 voteCount += len(intent.promote) 539 voteCount += len(intent.promote)
533 » » intent.newCount = numStateServers - voteCount 540 » » intent.newCount = desiredStateServerCount - voteCount
534 logger.Infof("%d new machines; promoting %v", intent.newCount, i ntent.promote) 541 logger.Infof("%d new machines; promoting %v", intent.newCount, i ntent.promote)
535 ops, err := st.ensureAvailabilityIntentionOps(intent, currentInf o, cons, series) 542 ops, err := st.ensureAvailabilityIntentionOps(intent, currentInf o, cons, series)
536 if err != nil { 543 if err != nil {
537 return err 544 return err
538 } 545 }
539 err = st.runTransaction(ops) 546 err = st.runTransaction(ops)
540 if err == nil { 547 if err == nil {
541 return nil 548 return nil
542 } 549 }
543 if err != txn.ErrAborted { 550 if err != txn.ErrAborted {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 Update: bson.D{ 693 Update: bson.D{
687 {"$pull", bson.D{{"jobs", JobManageEnviron}}}, 694 {"$pull", bson.D{{"jobs", JobManageEnviron}}},
688 {"$set", bson.D{{"novote", false}}}, 695 {"$set", bson.D{{"novote", false}}},
689 }, 696 },
690 }, { 697 }, {
691 C: m.st.stateServers.Name, 698 C: m.st.stateServers.Name,
692 Id: environGlobalKey, 699 Id: environGlobalKey,
693 Update: bson.D{{"$pull", bson.D{{"machineids", m.doc.Id}}}}, 700 Update: bson.D{{"$pull", bson.D{{"machineids", m.doc.Id}}}},
694 }} 701 }}
695 } 702 }
LEFTRIGHT

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