Permalink
Browse files

Merge pull request #6028 from babbageclunk/update-mgo

Update mgo dependency

This version includes the fixes for the duplicate key error on upsert, which means we don't need the patch any more.

[go-mgo/mgo#291](go-mgo/mgo#291)
[go-mgo/mgo#316](go-mgo/mgo#316)

Add a readme to keep the patches directory alive and explain its use. mgz has made a change to apply_patches.py to ignore any files with a different extension.

(Review request: http://reviews.vapour.ws/r/5477/)
  • Loading branch information...
2 parents 4df5f92 + 212cba2 commit 5ac0e259560382ea0c0e2a4120e028f2613ed857 @jujubot jujubot committed Aug 22, 2016
Showing with 14 additions and 107 deletions.
  1. +1 −1 dependencies.tsv
  2. +0 −106 patches/001-mgo.v2-issue-277-fix.diff
  3. +13 −0 patches/README.md
View
@@ -81,7 +81,7 @@ gopkg.in/juju/jujusvg.v2 git d82160011935ef79fc7aca84aba2c6f74700fe75 2016-06-09
gopkg.in/juju/names.v2 git fa4c1959bef64b8f18569dc83a85b25d15204503 2016-08-16T07:05:44Z
gopkg.in/macaroon-bakery.v1 git 469b44e6f1f9479e115c8ae879ef80695be624d5 2016-06-22T12:14:21Z
gopkg.in/macaroon.v1 git ab3940c6c16510a850e1c2dd628b919f0f3f1464 2015-01-21T11:42:31Z
-gopkg.in/mgo.v2 git 29cc868a5ca65f401ff318143f9408d02f4799cc 2016-06-09T18:00:28Z
+gopkg.in/mgo.v2 git f2b6f6c918c452ad107eec89615f074e3bd80e33 2016-08-18T01:52:18Z
gopkg.in/natefinch/lumberjack.v2 git 514cbda263a734ae8caac038dadf05f8f3f9f738 2016-01-25T11:17:49Z
gopkg.in/natefinch/npipe.v2 git c1b8fa8bdccecb0b8db834ee0b92fdbcfa606dd6 2016-06-21T03:49:01Z
gopkg.in/tomb.v1 git dd632973f1e7218eb1089048e0798ec9ae7dceb8 2014-10-24T13:56:13Z
@@ -1,106 +0,0 @@
-diff --git a/session.go b/session.go
-index a8ad115..75cb838 100644
-
-This applies the minimal changes to fix the mgo duplicate key error,
-see https://github.com/go-mgo/mgo/pull/291 and https://github.com/go-mgo/mgo/pull/302
-
-It also includes logging so we can see that the patch is applied.
-
-Diff on github: https://github.com/go-mgo/mgo/compare/v2...babbageclunk:fix-277-v2-minimal?expand=1
-Generated with "git diff v2..fix-277-v2-minimal"
-
-Apply from $GOPATH/src with: patch -p1 < github.com/juju/juju/patches/001-mgo.v2-issue-277-fix.diff
-
---- a/gopkg.in/mgo.v2/session.go
-+++ b/gopkg.in/mgo.v2/session.go
-@@ -41,6 +41,7 @@ import (
- "sync"
- "time"
-
-+ "github.com/juju/loggo"
- "gopkg.in/mgo.v2/bson"
- )
-
-@@ -144,9 +145,18 @@ type Iter struct {
- var (
- ErrNotFound = errors.New("not found")
- ErrCursor = errors.New("invalid cursor")
-+
-+ logPatchedOnce sync.Once
-+ logger = loggo.GetLogger("mgo")
- )
-
--const defaultPrefetch = 0.25
-+const (
-+ defaultPrefetch = 0.25
-+
-+ // How many times we will retry an upsert if it produces duplicate
-+ // key errors.
-+ maxUpsertRetries = 5
-+)
-
- // Dial establishes a new session to the cluster identified by the given seed
- // server(s). The session will enable communication with all of the servers in
-@@ -410,6 +420,16 @@ func (addr *ServerAddr) TCPAddr() *net.TCPAddr {
-
- // DialWithInfo establishes a new session to the cluster identified by info.
- func DialWithInfo(info *DialInfo) (*Session, error) {
-+ // This is using loggo because that can be done here in a
-+ // localised patch, while using mgo's logging would need a change
-+ // in Juju to call mgo.SetLogger. It's in this short-lived patch
-+ // as a stop-gap because it's proving difficult to tell if the
-+ // patch is applied in a running system. If you see it in
-+ // committed code then something has gone very awry - please
-+ // complain loudly! (babbageclunk)
-+ logPatchedOnce.Do(func() {
-+ logger.Debugf("duplicate key error patch applied")
-+ })
- addrs := make([]string, len(info.Addrs))
- for i, addr := range info.Addrs {
- p := strings.LastIndexAny(addr, "]:")
-@@ -2478,7 +2498,16 @@ func (c *Collection) Upsert(selector interface{}, update interface{}) (info *Cha
- Flags: 1,
- Upsert: true,
- }
-- lerr, err := c.writeOp(&op, true)
-+ var lerr *LastError
-+ // <= to allow for the first attempt (not a retry).
-+ for i := 0; i <= maxUpsertRetries; i++ {
-+ lerr, err = c.writeOp(&op, true)
-+ // Retry duplicate key errors on upserts.
-+ // https://docs.mongodb.com/v3.2/reference/method/db.collection.update/#use-unique-indexes
-+ if !IsDup(err) {
-+ break
-+ }
-+ }
- if err == nil && lerr != nil {
- info = &ChangeInfo{}
- if lerr.UpdatedExisting {
-@@ -4208,13 +4237,22 @@ func (q *Query) Apply(change Change, result interface{}) (info *ChangeInfo, err
- session.SetMode(Strong, false)
-
- var doc valueResult
-- err = session.DB(dbname).Run(&cmd, &doc)
-- if err != nil {
-- if qerr, ok := err.(*QueryError); ok && qerr.Message == "No matching object found" {
-- return nil, ErrNotFound
-+ for retries := 0; ; retries++ {
-+ err = session.DB(dbname).Run(&cmd, &doc)
-+ if err != nil {
-+ if qerr, ok := err.(*QueryError); ok && qerr.Message == "No matching object found" {
-+ return nil, ErrNotFound
-+ }
-+ if change.Upsert && IsDup(err) && retries < maxUpsertRetries {
-+ // Retry duplicate key errors on upserts.
-+ // https://docs.mongodb.com/v3.2/reference/method/db.collection.update/#use-unique-indexes
-+ continue
-+ }
-+ return nil, err
- }
-- return nil, err
-+ break // No error, so don't retry.
- }
-+
- if doc.LastError.N == 0 {
- return nil, ErrNotFound
- }
View
@@ -0,0 +1,13 @@
+Emergency patches for dependencies
+==================================
+
+Files in this directory named `*.patch` or `*.diff` will be applied to
+the source tree before building Juju for release. The expectation is
+that these should be changes that will be accepted upstream, but that
+we need to apply sooner.
+
+They're applied with `$GOPATH/src` as the current directory, and with
+`-p1` to strip one component off the start of the file path.
+
+For more details, see `lp:juju-release-tools/apply_patches.py` or ask
+babbageclunk or mgz in IRC.

0 comments on commit 5ac0e25

Please sign in to comment.