Skip to content

Commit 59e0104

Browse files
author
Divjot Arora
committed
Implement the compression specification
GODRIVER-20 Change-Id: I9296a36d5c99a65d838f4993ec9a4d9549e77155
1 parent 201b3c3 commit 59e0104

37 files changed

+3245
-31
lines changed

.evergreen/config.yml

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ functions:
238238
fi
239239
fi
240240
241-
AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" TOPOLOGY=${TOPOLOGY} make evg-test
241+
AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" TOPOLOGY=${TOPOLOGY} MONGO_GO_DRIVER_COMPRESSOR=${MONGO_GO_DRIVER_COMPRESSOR} make evg-test
242242
243243
244244
send-perf-data:
@@ -262,7 +262,7 @@ functions:
262262
export GOPATH=$(dirname $(dirname $(dirname $(dirname `pwd`))))
263263
fi;
264264
export PATH="${GCC_PATH}:$PATH"
265-
MONGODB_URI="${MONGODB_URI}" make -s evg-test-auth
265+
MONGODB_URI="${MONGODB_URI}" MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
266266
267267
run-enterprise-gssapi-auth-tests:
268268
- command: shell.exec
@@ -285,7 +285,7 @@ functions:
285285
export MONGODB_URI="${gssapi_auth_linux_mongodb_uri}"
286286
fi;
287287
export PATH="${GCC_PATH}:$PATH"
288-
make -s evg-test-auth
288+
MONGO_GO_DRIVER_COMPRESSOR="${MONGO_GO_DRIVER_COMPRESSOR}" make -s evg-test-auth
289289
290290
pre:
291291
- func: fetch-source
@@ -361,6 +361,21 @@ tasks:
361361
AUTH: "noauth"
362362
SSL: "nossl"
363363

364+
- name: test-standalone-noauth-nossl-compression
365+
tags: ["test", "standalone", "compression"]
366+
commands:
367+
- func: bootstrap-mongo-orchestration
368+
vars:
369+
TOPOLOGY: "server"
370+
AUTH: "noauth"
371+
SSL: "nossl"
372+
- func: run-tests
373+
vars:
374+
TOPOLOGY: "server"
375+
AUTH: "noauth"
376+
SSL: "nossl"
377+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
378+
364379
- name: test-standalone-auth-ssl
365380
tags: ["test", "standalone"]
366381
commands:
@@ -375,6 +390,21 @@ tasks:
375390
AUTH: "auth"
376391
SSL: "ssl"
377392

393+
- name: test-standalone-auth-ssl-compression
394+
tags: ["test", "standalone"]
395+
commands:
396+
- func: bootstrap-mongo-orchestration
397+
vars:
398+
topology: "server"
399+
auth: "auth"
400+
ssl: "ssl"
401+
- func: run-tests
402+
vars:
403+
topology: "server"
404+
auth: "auth"
405+
ssl: "ssl"
406+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
407+
378408
- name: test-replicaset-noauth-nossl
379409
tags: ["test", "replicaset"]
380410
commands:
@@ -389,6 +419,21 @@ tasks:
389419
AUTH: "noauth"
390420
SSL: "nossl"
391421

422+
- name: test-replicaset-noauth-nossl-compression
423+
tags: ["test", "replicaset"]
424+
commands:
425+
- func: bootstrap-mongo-orchestration
426+
vars:
427+
TOPOLOGY: "replica_set"
428+
AUTH: "noauth"
429+
SSL: "nossl"
430+
- func: run-tests
431+
vars:
432+
TOPOLOGY: "replica_set"
433+
AUTH: "noauth"
434+
SSL: "nossl"
435+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
436+
392437
- name: test-replicaset-auth-ssl
393438
tags: ["test", "replicaset"]
394439
commands:
@@ -403,6 +448,21 @@ tasks:
403448
AUTH: "auth"
404449
SSL: "ssl"
405450

451+
- name: test-replicaset-auth-ssl-compression
452+
tags: ["test", "replicaset"]
453+
commands:
454+
- func: bootstrap-mongo-orchestration
455+
vars:
456+
TOPOLOGY: "replica_set"
457+
AUTH: "auth"
458+
SSL: "ssl"
459+
- func: run-tests
460+
vars:
461+
TOPOLOGY: "replica_set"
462+
AUTH: "auth"
463+
SSL: "ssl"
464+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
465+
406466
- name: test-sharded-noauth-nossl
407467
tags: ["test", "sharded"]
408468
commands:
@@ -417,6 +477,21 @@ tasks:
417477
AUTH: "noauth"
418478
SSL: "nossl"
419479

480+
- name: test-sharded-noauth-nossl-compression
481+
tags: ["test", "sharded"]
482+
commands:
483+
- func: bootstrap-mongo-orchestration
484+
vars:
485+
TOPOLOGY: "sharded_cluster"
486+
AUTH: "noauth"
487+
SSL: "nossl"
488+
- func: run-tests
489+
vars:
490+
TOPOLOGY: "sharded_cluster"
491+
AUTH: "noauth"
492+
SSL: "nossl"
493+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
494+
420495
- name: test-sharded-auth-ssl
421496
tags: ["test", "sharded"]
422497
commands:
@@ -431,17 +506,42 @@ tasks:
431506
AUTH: "auth"
432507
SSL: "ssl"
433508

509+
- name: test-sharded-auth-ssl-compression
510+
tags: ["test", "sharded"]
511+
commands:
512+
- func: bootstrap-mongo-orchestration
513+
vars:
514+
TOPOLOGY: "sharded_cluster"
515+
AUTH: "auth"
516+
SSL: "ssl"
517+
- func: run-tests
518+
vars:
519+
TOPOLOGY: "sharded_cluster"
520+
AUTH: "auth"
521+
SSL: "ssl"
522+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
523+
434524
- name: test-enterprise-auth-plain
435525
tags: ["test", "enterprise-auth"]
436526
commands:
437527
- func: run-enterprise-auth-tests
438528
vars:
439529
MONGODB_URI: "${plain_auth_mongodb_uri}"
440530

531+
- name: test-enterprise-auth-plain-compression
532+
tags: ["test", "enterprise-auth"]
533+
commands:
534+
- func: run-enterprise-auth-tests
535+
vars:
536+
MONGODB_URI: "${plain_auth_mongodb_uri}"
537+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
538+
441539
- name: test-enterprise-auth-gssapi
442540
tags: ["test", "enterprise-auth"]
443541
commands:
444542
- func: run-enterprise-gssapi-auth-tests
543+
vars:
544+
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
445545

446546
- name: go1.8-build
447547
tags: ["compile-check"]

THIRD-PARTY-NOTICES

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,38 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
8080
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
8181
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8282

83+
----------------------------------------------------------------------
84+
License notice for github.com/golang/snappy
85+
----------------------------------------------------------------------
86+
87+
Copyright (c) 2011 The Snappy-Go Authors. All rights reserved.
88+
89+
Redistribution and use in source and binary forms, with or without
90+
modification, are permitted provided that the following conditions are
91+
met:
92+
93+
* Redistributions of source code must retain the above copyright
94+
notice, this list of conditions and the following disclaimer.
95+
* Redistributions in binary form must reproduce the above
96+
copyright notice, this list of conditions and the following disclaimer
97+
in the documentation and/or other materials provided with the
98+
distribution.
99+
* Neither the name of Google Inc. nor the names of its
100+
contributors may be used to endorse or promote products derived from
101+
this software without specific prior written permission.
102+
103+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
104+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
105+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
106+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
107+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
108+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
109+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
110+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
111+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
112+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
113+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114+
83115
----------------------------------------------------------------------
84116
License notice for github.com/google/go-cmp
85117
----------------------------------------------------------------------

core/auth/auth.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,26 @@ func RegisterAuthenticatorFactory(name string, factory AuthenticatorFactory) {
9090
// })
9191
// }
9292

93-
// Handshaker creates a connection handshaker for the given authenticator. The
94-
// handshaker will handle calling isMaster.
95-
func Handshaker(appName string, h connection.Handshaker, authenticator Authenticator) connection.Handshaker {
93+
// HandshakeOptions packages options that can be passed to the Handshaker() function
94+
type HandshakeOptions struct {
95+
AppName string
96+
Authenticator Authenticator
97+
Compressors []string
98+
}
99+
100+
// Handshaker creates a connection handshaker for the given authenticator.
101+
func Handshaker(h connection.Handshaker, options *HandshakeOptions) connection.Handshaker {
96102
return connection.HandshakerFunc(func(ctx context.Context, addr address.Address, rw wiremessage.ReadWriter) (description.Server, error) {
97-
desc, err := (&command.Handshake{Client: command.ClientDoc(appName)}).Handshake(ctx, addr, rw)
103+
desc, err := (&command.Handshake{
104+
Client: command.ClientDoc(options.AppName),
105+
Compressors: options.Compressors,
106+
}).Handshake(ctx, addr, rw)
107+
98108
if err != nil {
99109
return description.Server{}, newAuthError("handshake failure", err)
100110
}
101111

102-
err = authenticator.Auth(ctx, desc, rw)
112+
err = options.Authenticator.Auth(ctx, desc, rw)
103113
if err != nil {
104114
return description.Server{}, newAuthError("auth error", err)
105115
}

core/auth/gssapi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package auth
1111

1212
import (
1313
"context"
14+
1415
"github.com/mongodb/mongo-go-driver/core/auth/internal/gssapi"
1516
"github.com/mongodb/mongo-go-driver/core/description"
1617
"github.com/mongodb/mongo-go-driver/core/wiremessage"

core/auth/plain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package auth
88

99
import (
1010
"context"
11+
1112
"github.com/mongodb/mongo-go-driver/core/description"
1213
"github.com/mongodb/mongo-go-driver/core/wiremessage"
1314
)

core/command/handshake.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323
//
2424
// The isMaster and buildInfo commands are used to build a server description.
2525
type Handshake struct {
26-
Client *bson.Document
26+
Client *bson.Document
27+
Compressors []string
2728

2829
ismstr result.IsMaster
2930
err error
@@ -32,10 +33,11 @@ type Handshake struct {
3233
// Encode will encode the handshake commands into a wire message containing isMaster
3334
func (h *Handshake) Encode() (wiremessage.WireMessage, error) {
3435
var wm wiremessage.WireMessage
35-
ismstr, err := (&IsMaster{Client: h.Client}).Encode()
36+
ismstr, err := (&IsMaster{Client: h.Client, Compressors: h.Compressors}).Encode()
3637
if err != nil {
3738
return wm, err
3839
}
40+
3941
wm = ismstr
4042
return wm, nil
4143
}

core/command/ismaster.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
//
2323
// Since IsMaster can only be run on a connection, there is no Dispatch method.
2424
type IsMaster struct {
25-
Client *bson.Document
25+
Client *bson.Document
26+
Compressors []string
2627

2728
err error
2829
res result.IsMaster
@@ -34,6 +35,15 @@ func (im *IsMaster) Encode() (wiremessage.WireMessage, error) {
3435
if im.Client != nil {
3536
cmd.Append(bson.EC.SubDocument("client", im.Client))
3637
}
38+
39+
// always send compressors even if empty slice
40+
array := bson.NewArray()
41+
for _, compressor := range im.Compressors {
42+
array.Append(bson.VC.String(compressor))
43+
}
44+
45+
cmd.Append(bson.EC.Array("compression", array))
46+
3747
rdr, err := cmd.MarshalBSON()
3848
if err != nil {
3949
return nil, err

0 commit comments

Comments
 (0)