Skip to content

Commit

Permalink
MongoDB 3.6: implement the new wire protocol (#61)
Browse files Browse the repository at this point in the history
* test against 3.6

* update go and mongodb version

  - use last minor version for each major serie of
    mongodb
  - use travis 'go' param instead of eval "$(gimme $GO)"
    as it fails to install correctly last minor version
    ( 1.8.x notation for example)

* test fixes on 3.2.17

also re-enable TestFindIterSnapshot as it was fixed
a long time ago

* fix X509 test

fix TestAuthX509CredRDNConstruction test: need to
create an user with {"username": subject} before
trying to login

* Fix auth test on 3.6-rc3

Make sure that "rs3/127.0.0.1/40031" is elected
at primary.
Create user before running 'addShard' command as
it requires root access
Also add a retry mechanism to make sure that shard
are correctly added
cf https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/

* implement OP_MSG wire protocole

require maxWireVersion >= 6 on server side, and
`experimental=opmsg` in the connection string

  - get `MaxMessageSizeBytes` and `MaxWriteBatchSize`
    from handshake
  - allow unacknowledged writes with `moreToCome` flag
  - split bulk operations in batch of `maxWriteBatchSize`
  - add 'experimental' param in URL. To enable an experimental
    feature, add `experimental=featureName` in the connection
    URL

flush logout directly

Previously, `flushLogout()` was called at the beginning
of each Query to the database.
To avoid these useless calls, we flush logout directly
when `Logout()` or `LogoutAll()` is called

* re-enable TestViewWithCollation

SERVER-31049 is fixed in 3.4.10, so re-enable
it

* refactor memory pooling

use the same pool for send and received
messages.
Slices are returned to the pool without being
resized.

Default allocation size might need to be updated
(currently 256, no benchmarks available yet)

* update to 3.6.0 stable
  • Loading branch information
feliixx authored and domodwyer committed Dec 12, 2017
1 parent ea8e8e6 commit 90c056c
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 601 deletions.
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ language: go

go_import_path: github.com/globalsign/mgo

go:
- 1.8.x
- 1.9.x

env:
global:
- BUCKET=https://s3.eu-west-2.amazonaws.com/globalsign-mgo
- FASTDL=https://fastdl.mongodb.org/linux
matrix:
- GO=1.7 MONGODB=x86_64-2.6.11
- GO=1.8.x MONGODB=x86_64-2.6.11
- GO=1.7 MONGODB=x86_64-3.0.9
- GO=1.8.x MONGODB=x86_64-3.0.9
- GO=1.7 MONGODB=x86_64-3.2.3-nojournal
- GO=1.8.x MONGODB=x86_64-3.2.3-nojournal
- GO=1.7 MONGODB=x86_64-3.2.12
- GO=1.8.x MONGODB=x86_64-3.2.12
- GO=1.7 MONGODB=x86_64-3.2.16
- GO=1.8.x MONGODB=x86_64-3.2.16
- GO=1.7 MONGODB=x86_64-3.4.8
- GO=1.8.x MONGODB=x86_64-3.4.8
- MONGODB=x86_64-ubuntu1404-3.0.15
- MONGODB=x86_64-ubuntu1404-3.2.17
- MONGODB=x86_64-ubuntu1404-3.4.10
- MONGODB=x86_64-ubuntu1404-3.6.0

install:
- eval "$(gimme $GO)"

- wget $BUCKET/mongodb-linux-$MONGODB.tgz
- wget $FASTDL/mongodb-linux-$MONGODB.tgz
- tar xzvf mongodb-linux-$MONGODB.tgz
- export PATH=$PWD/mongodb-linux-$MONGODB/bin:$PATH

Expand Down
57 changes: 27 additions & 30 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ func (socket *mongoSocket) Login(cred Credential) error {
return nil
}
}
if socket.dropLogout(cred) {
debugf("Socket %p to %s: login: db=%q user=%q (cached)", socket, socket.addr, cred.Source, cred.Username)
socket.creds = append(socket.creds, cred)
socket.Unlock()
return nil
}
socket.Unlock()

debugf("Socket %p to %s: login: db=%q user=%q", socket, socket.addr, cred.Source, cred.Username)
Expand Down Expand Up @@ -412,36 +406,50 @@ func (socket *mongoSocket) Logout(db string) {
cred, found := socket.dropAuth(db)
if found {
debugf("Socket %p to %s: logout: db=%q (flagged)", socket, socket.addr, db)
socket.logout = append(socket.logout, cred)
socket.Unlock()
err := socket.flushLogout(cred)
if err != nil {
debugf("fail to logout for cred %v; error: %v", cred, err)
}
} else {
socket.Unlock()
}
socket.Unlock()
}

func (socket *mongoSocket) LogoutAll() {
socket.Lock()
if l := len(socket.creds); l > 0 {
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
socket.logout = append(socket.logout, socket.creds...)
credCopy := make([]Credential, l)
copy(credCopy, socket.creds)
socket.creds = socket.creds[0:0]
socket.Unlock()
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
err := socket.flushLogout(credCopy...)
if err != nil {
debugf("fail to logout for cred %v, error: %v", credCopy, err)
}
} else {
socket.Unlock()
}
socket.Unlock()
}

func (socket *mongoSocket) flushLogout() (ops []interface{}) {
socket.Lock()
if l := len(socket.logout); l > 0 {
func (socket *mongoSocket) flushLogout(cred ...Credential) error {
if l := len(cred); l > 0 {
debugf("Socket %p to %s: logout all (flushing %d)", socket, socket.addr, l)
ops := make([]interface{}, l)
for i := 0; i != l; i++ {
op := queryOp{}
op.query = &logoutCmd{1}
op.collection = socket.logout[i].Source + ".$cmd"
op.collection = cred[i].Source + ".$cmd"
op.limit = -1
ops = append(ops, &op)
ops[i] = &op
}
err := socket.Query(ops...)
if err != nil {
return fmt.Errorf("fail to logout: %v", err)
}
socket.logout = socket.logout[0:0]
}
socket.Unlock()
return
return nil
}

func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
Expand All @@ -454,14 +462,3 @@ func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
}
return cred, false
}

func (socket *mongoSocket) dropLogout(cred Credential) (found bool) {
for i, sockCred := range socket.logout {
if sockCred == cred {
copy(socket.logout[i:], socket.logout[i+1:])
socket.logout = socket.logout[:len(socket.logout)-1]
return true
}
}
return false
}
Loading

0 comments on commit 90c056c

Please sign in to comment.