Skip to content

Commit

Permalink
Merge pull request juju#13396 from SimonRichardson/backport-mongo-4.4…
Browse files Browse the repository at this point in the history
…-fixes

juju#13396

The following was already fixed in the develop branch. If you indirectly
run `snap install juju-db` without targeting `--channel=4.0/stable` then
you can end up having issues.

As this isn't really going to break anything in 2.9 it's worthwhile to backport.

See: juju#12595

## QA steps

```sh
$ snap install juju-db
$ go test -v ./apiserver/facades/controller/metricsmanager -check.v
```
  • Loading branch information
jujubot authored Oct 8, 2021
2 parents 7283465 + 0c6b23e commit 9dbed19
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apiserver/facades/client/backups/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package backups

import (
"github.com/juju/errors"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"

"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/mongo"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/client/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/juju/errors"
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/version/v2"

"github.com/juju/juju/controller"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/version/v2"

"github.com/juju/juju/apiserver/common"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
jtesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/version/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/agent/agenttest/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/juju/errors"
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/version/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/agent/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
"github.com/juju/pubsub/v2"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/utils/v2"
"github.com/juju/utils/v2/symlink"
"github.com/juju/utils/v2/voyeur"
Expand Down
7 changes: 7 additions & 0 deletions core/controller/ha.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2021 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package controller

// MaxPeers defines the maximum number of peers that mongo supports.
const MaxPeers = 7
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ require (
github.com/juju/proxy v0.0.0-20210817195502-c6015cfe0258
github.com/juju/pubsub/v2 v2.0.0-20210804115646-050d38a80f5b
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441
github.com/juju/replicaset v0.0.0-20210302050932-0303c8575745
github.com/juju/replicaset/v2 v2.0.1-0.20210310024806-bbbdc5f31eb3
github.com/juju/retry v0.0.0-20180821225755-9058e192b216
github.com/juju/rfc/v2 v2.0.0-20210319034215-ed820200fad3
github.com/juju/romulus v0.0.0-20210309074704-4fa3bbd32568
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ github.com/juju/raft-boltdb v0.0.0-20200518034108-40b112c917c5 h1:+eWzUG6XLDSdcz
github.com/juju/raft-boltdb v0.0.0-20200518034108-40b112c917c5/go.mod h1:F7wHQBX+lEJkv9PhNCgNJgCeI+GISZW2RefLINbmgXU=
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441 h1:b5Jqi7ir58EzfeZDyp7OSYQG/IVgyY4JWfHuJUF2AZI=
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/juju/replicaset v0.0.0-20210302050932-0303c8575745 h1:3vZtSiDNo99/leCQugDbFAWUIzBuC85rLvzSx2huGfY=
github.com/juju/replicaset v0.0.0-20210302050932-0303c8575745/go.mod h1:V7wyjD9vFrprVDmycd6g0Lb+Pl5s+WM95bthwLrA1pA=
github.com/juju/replicaset/v2 v2.0.1-0.20210310024806-bbbdc5f31eb3 h1:PYmT5m/07JtXv8/DfSSw3bwD/1TpA9E83//jZldR8l4=
github.com/juju/replicaset/v2 v2.0.1-0.20210310024806-bbbdc5f31eb3/go.mod h1:NRTC6FXOBX/+Usgl6GjqU2VUcReSG8Odml56qE4bZ/g=
github.com/juju/retry v0.0.0-20151029024821-62c620325291/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4=
github.com/juju/retry v0.0.0-20160928201858-1998d01ba1c3/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4=
github.com/juju/retry v0.0.0-20180821225755-9058e192b216 h1:/eQL7EJQKFHByJe3DeE8Z36yqManj9UY5zppDoQi4FU=
Expand Down
2 changes: 1 addition & 1 deletion mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/juju/loggo"
"github.com/juju/mgo/v2"
"github.com/juju/os/v2/series"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/utils/v2"

"github.com/juju/juju/core/network"
Expand Down
2 changes: 1 addition & 1 deletion state/backups/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/juju/clock/testclock"
"github.com/juju/mgo/v2/bson"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2/ssh"
Expand Down
3 changes: 3 additions & 0 deletions state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func createCollection(raw *mgo.Collection, spec *mgo.CollectionInfo) error {
if err == nil || strings.HasSuffix(err.Error(), "already exists") {
return nil
}
if mgoAlreadyExistsErr(err) {
return nil
}
return err
}

Expand Down
7 changes: 4 additions & 3 deletions state/enableha.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"github.com/juju/mgo/v2/bson"
"github.com/juju/mgo/v2/txn"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
jujutxn "github.com/juju/txn"
"github.com/juju/utils/v2"
"github.com/juju/version/v2"

"github.com/juju/juju/core/constraints"
"github.com/juju/juju/core/controller"
"github.com/juju/juju/core/instance"
stateerrors "github.com/juju/juju/state/errors"
)
Expand Down Expand Up @@ -94,8 +95,8 @@ func (st *State) EnableHA(
if numControllers < 0 || (numControllers != 0 && numControllers%2 != 1) {
return ControllersChanges{}, errors.New("number of controllers must be odd and non-negative")
}
if numControllers > replicaset.MaxPeers {
return ControllersChanges{}, errors.Errorf("controller count is too large (allowed %d)", replicaset.MaxPeers)
if numControllers > controller.MaxPeers {
return ControllersChanges{}, errors.Errorf("controller count is too large (allowed %d)", controller.MaxPeers)
}
var change ControllersChanges
buildTxn := func(attempt int) ([]txn.Op, error) {
Expand Down
4 changes: 2 additions & 2 deletions state/enableha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"sort"

"github.com/juju/errors"
"github.com/juju/replicaset"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/core/constraints"
"github.com/juju/juju/core/controller"
"github.com/juju/juju/state"
statetesting "github.com/juju/juju/state/testing"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *EnableHASuite) TestEnableHAFailsWithBadCount(c *gc.C) {
c.Assert(err, gc.ErrorMatches, "number of controllers must be odd and non-negative")
c.Assert(changes.Added, gc.HasLen, 0)
}
_, err := s.State.EnableHA(replicaset.MaxPeers+2, constraints.Value{}, "", nil)
_, err := s.State.EnableHA(controller.MaxPeers+2, constraints.Value{}, "", nil)
c.Assert(err, gc.ErrorMatches, `controller count is too large \(allowed \d+\)`)
}

Expand Down
6 changes: 6 additions & 0 deletions state/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,12 @@ func collStats(coll *mgo.Collection) (bson.M, error) {
}
return nil, errors.Trace(err)
}
// For mongo 4.4, if the collection exists,
// there will be a "capped" attribute.
_, ok := result["capped"]
if !ok {
return nil, errors.NotFoundf("Collection [%s.%s]", coll.Database.Name, coll.Name)
}
return result, nil
}

Expand Down
2 changes: 1 addition & 1 deletion state/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/juju/mgo/v2/txn"
"github.com/juju/names/v4"
"github.com/juju/os/v2/series"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/kr/pretty"
core "k8s.io/api/core/v1"

Expand Down
2 changes: 1 addition & 1 deletion upgrades/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package upgrades
import (
"time"

"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"

"github.com/juju/juju/cloud"
"github.com/juju/juju/controller"
Expand Down
2 changes: 1 addition & 1 deletion upgrades/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hashicorp/raft"
raftboltdb "github.com/hashicorp/raft-boltdb"
"github.com/juju/errors"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"

"github.com/juju/juju/agent"
"github.com/juju/juju/core/raftlease"
Expand Down
2 changes: 1 addition & 1 deletion upgrades/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
raftboltdb "github.com/hashicorp/raft-boltdb"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/desired.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"

"github.com/juju/juju/core/network"
"github.com/juju/juju/core/status"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/desired_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/initiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/juju/errors"
"github.com/juju/mgo/v2"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/utils/v2"

"github.com/juju/juju/agent"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"sync"

"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sync"

"github.com/juju/errors"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/utils/v2/voyeur"
"github.com/juju/worker/v2"
"gopkg.in/tomb.v2"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package peergrouper
import (
"github.com/juju/errors"
"github.com/juju/mgo/v2"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"

"github.com/juju/juju/core/status"
"github.com/juju/juju/state"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
"github.com/juju/worker/v2"
"github.com/juju/worker/v2/catacomb"
"github.com/kr/pretty"
Expand Down
2 changes: 1 addition & 1 deletion worker/peergrouper/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/juju/clock/testclock"
"github.com/juju/loggo"
"github.com/juju/pubsub/v2"
"github.com/juju/replicaset"
"github.com/juju/replicaset/v2"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2/voyeur"
"github.com/juju/worker/v2"
Expand Down
4 changes: 2 additions & 2 deletions worker/raft/rafttransport/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/pubsub/v2"
"github.com/juju/replicaset"
"github.com/juju/worker/v2"
"github.com/juju/worker/v2/catacomb"

"github.com/juju/juju/api"
"github.com/juju/juju/apiserver/apiserverhttp"
"github.com/juju/juju/apiserver/httpcontext"
"github.com/juju/juju/core/controller"
"github.com/juju/juju/worker/raft/raftutil"
)

Expand All @@ -30,7 +30,7 @@ var (
)

const (
maxPoolSize = replicaset.MaxPeers
maxPoolSize = controller.MaxPeers
)

// Config is the configuration required for running an apiserver-based
Expand Down

0 comments on commit 9dbed19

Please sign in to comment.