Skip to content

Commit

Permalink
Merge v2-unstable into v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed May 29, 2015
2 parents 7c85a0d + 90e509a commit 01ee097
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ func (q *Query) SetMaxScan(n int) *Query {
// This can be used to efficiently prevent and identify unexpectedly slow queries.
//
// A few important notes about the mechanism enforcing this limit:
//
//
// - Requests can block behind locking operations on the server, and that blocking
// time is not accounted for. In other words, the timer starts ticking only after
// the actual start of the query when it initially acquires the appropriate lock;
Expand All @@ -2654,7 +2654,7 @@ func (q *Query) SetMaxScan(n int) *Query {
//
// - This limit does not override the inactive cursor timeout for idle cursors
// (default is 10 min).
//
//
// This mechanism was introduced in MongoDB 2.6.
//
// Relevant documentation:
Expand All @@ -2663,7 +2663,7 @@ func (q *Query) SetMaxScan(n int) *Query {
//
func (q *Query) SetMaxTime(d time.Duration) *Query {
q.m.Lock()
q.op.options.MaxTimeMS = int(d/time.Millisecond)
q.op.options.MaxTimeMS = int(d / time.Millisecond)
q.op.hasOptions = true
q.m.Unlock()
return q
Expand Down Expand Up @@ -4071,14 +4071,15 @@ func (c *Collection) writeQuery(op interface{}) (lerr *LastError, err error) {
safeOp := s.safeOp
s.m.RUnlock()

if socket.ServerInfo().MaxWireVersion >= 2 {
// TODO Enable this path for wire version 2 as well.
if socket.ServerInfo().MaxWireVersion >= 3 {
// Servers with a more recent write protocol benefit from write commands.
if op, ok := op.(*insertOp); ok && len(op.documents) > 1000 {
var firstErr error
// Maximum batch size is 1000. Must split out in separate operations for compatibility.
all := op.documents
for i := 0; i < len(all); i += 1000 {
l := i+1000
l := i + 1000
if l > len(all) {
l = len(all)
}
Expand Down
12 changes: 7 additions & 5 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ func (s *S) TestQuerySetMaxTime(c *C) {
}

query := coll.Find(nil)
query.SetMaxTime(1*time.Millisecond)
query.SetMaxTime(1 * time.Millisecond)
query.Batch(2)
var result []M
err = query.All(&result)
Expand Down Expand Up @@ -1673,7 +1673,7 @@ func (s *S) TestFindTailTimeoutWithSleep(c *C) {
// 1*QUERY for nonce + 1*GET_MORE_OP on Next + 1*GET_MORE_OP on Next after sleep +
// 1*INSERT_OP + 1*QUERY_OP for getLastError on insert of 47
stats := mgo.GetStats()
if s.versionAtLeast(2, 6) {
if s.versionAtLeast(3, 0) { // TODO Will be 2.6 when write commands are enabled for it.
c.Assert(stats.SentOps, Equals, 4)
} else {
c.Assert(stats.SentOps, Equals, 5)
Expand Down Expand Up @@ -1770,7 +1770,7 @@ func (s *S) TestFindTailTimeoutNoSleep(c *C) {
// 1*QUERY_OP for nonce + 1*GET_MORE_OP on Next +
// 1*INSERT_OP + 1*QUERY_OP for getLastError on insert of 47
stats := mgo.GetStats()
if s.versionAtLeast(2, 6) {
if s.versionAtLeast(3, 0) { // TODO Will be 2.6 when write commands are enabled for it.
c.Assert(stats.SentOps, Equals, 3)
} else {
c.Assert(stats.SentOps, Equals, 4)
Expand Down Expand Up @@ -1866,7 +1866,7 @@ func (s *S) TestFindTailNoTimeout(c *C) {
// 1*QUERY_OP for nonce + 1*GET_MORE_OP on Next +
// 1*INSERT_OP + 1*QUERY_OP for getLastError on insert of 47
stats := mgo.GetStats()
if s.versionAtLeast(2, 6) {
if s.versionAtLeast(3, 0) { // TODO Will be 2.6 when write commands are enabled for it.
c.Assert(stats.SentOps, Equals, 3)
} else {
c.Assert(stats.SentOps, Equals, 4)
Expand Down Expand Up @@ -2490,7 +2490,9 @@ func (s *S) TestSafeInsert(c *C) {

// It must have sent two operations (INSERT_OP + getLastError QUERY_OP)
stats := mgo.GetStats()
if s.versionAtLeast(2, 6) {

// TODO Will be 2.6 when write commands are enabled for it.
if s.versionAtLeast(3, 0) {
c.Assert(stats.SentOps, Equals, 1)
} else {
c.Assert(stats.SentOps, Equals, 2)
Expand Down
2 changes: 1 addition & 1 deletion testserver/testserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *S) TestStop(c *C) {
server.Stop()

// Server should not be running anymore.
session, err = mgo.DialWithTimeout(addr, 500 * time.Millisecond)
session, err = mgo.DialWithTimeout(addr, 500*time.Millisecond)
if session != nil {
session.Close()
c.Fatalf("Stop did not stop the server")
Expand Down

0 comments on commit 01ee097

Please sign in to comment.