Skip to content

Commit e80083f

Browse files
committed
CXX-381 Backport server r2.6.5..r2.6.6 changes to 26compat branch
1 parent a3fb94c commit e80083f

File tree

7 files changed

+104
-52
lines changed

7 files changed

+104
-52
lines changed

src/mongo/base/owned_pointer_vector.h

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#pragma once
1717

18+
#include <cstring>
1819
#include <vector>
1920

2021
#include "mongo/base/disallow_copying.h"
@@ -31,8 +32,24 @@ namespace mongo {
3132
MONGO_DISALLOW_COPYING(OwnedPointerVector);
3233

3334
public:
34-
OwnedPointerVector();
35-
~OwnedPointerVector();
35+
OwnedPointerVector() {}
36+
~OwnedPointerVector() { clear(); }
37+
38+
/**
39+
* Takes ownership of all pointers contained in 'other'.
40+
* NOTE: argument is intentionally taken by value.
41+
*/
42+
OwnedPointerVector(std::vector<T*> other) { _vector.swap(other); }
43+
44+
/**
45+
* Takes ownership of all pointers contained in 'other'.
46+
* NOTE: argument is intentionally taken by value.
47+
*/
48+
OwnedPointerVector& operator=(std::vector<T*> other) {
49+
clear();
50+
_vector.swap(other);
51+
return *this;
52+
}
3653

3754
typedef typename std::vector<T*>::const_iterator const_iterator;
3855
typedef typename std::vector<T*>::const_reverse_iterator const_reverse_iterator;
@@ -49,23 +66,69 @@ namespace mongo {
4966
const_iterator end() const { return _vector.end(); }
5067
const_reverse_iterator rend() const { return _vector.rend(); }
5168

69+
T* operator[] (size_t i) const { return _vector[i]; }
70+
T* back() const { return _vector.back(); }
71+
T* front() const { return _vector.front(); }
72+
73+
void push_back(T* ptr) { _vector.push_back(ptr); }
74+
75+
/**
76+
* Deletes all pointers in the vector, then sets its size to 0.
77+
*/
5278
void clear();
5379

80+
/**
81+
* Deletes the pointer at 'it', then erases it from the vector.
82+
*/
83+
void erase(const_iterator it) {
84+
delete *it;
85+
// vector::erase(const_iterator) is new in c++11, so converting to non-const iterator.
86+
_vector.erase(_vector.begin() + (it - begin()));
87+
}
88+
89+
//
90+
// extensions
91+
//
92+
93+
/**
94+
* Releases the entire vector to allow you to transfer ownership.
95+
*
96+
* Leaves the OwnedPointerVector empty.
97+
* Named after the similar method and pattern in std::auto_ptr.
98+
*/
99+
std::vector<T*> release() {
100+
std::vector<T*> out;
101+
out.swap(_vector);
102+
return out;
103+
}
104+
105+
/**
106+
* Releases ownership of a single element.
107+
*
108+
* Sets that element to NULL and does not change size().
109+
*/
110+
T* releaseAt(size_t i) {
111+
T* out = _vector[i];
112+
_vector[i] = NULL;
113+
return out;
114+
}
115+
116+
T* popAndReleaseBack() {
117+
T* out = _vector.back();
118+
_vector.pop_back();
119+
return out;
120+
}
121+
122+
void popAndDeleteBack() {
123+
delete popAndReleaseBack();
124+
}
125+
54126
private:
55127
std::vector<T*> _vector;
56128
};
57129

58130
template<class T>
59-
OwnedPointerVector<T>::OwnedPointerVector() {
60-
}
61-
62-
template<class T>
63-
OwnedPointerVector<T>::~OwnedPointerVector() {
64-
clear();
65-
}
66-
67-
template<class T>
68-
void OwnedPointerVector<T>::clear() {
131+
inline void OwnedPointerVector<T>::clear() {
69132
for( typename std::vector<T*>::iterator i = _vector.begin(); i != _vector.end(); ++i ) {
70133
delete *i;
71134
}

src/mongo/client/connpool.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,10 @@ namespace mongo {
102102
}
103103

104104
void PoolForHost::flush() {
105-
vector<StoredConnection> all;
106-
while ( ! _pool.empty() ) {
105+
while (!_pool.empty()) {
107106
StoredConnection c = _pool.top();
108107
_pool.pop();
109-
bool res;
110-
bool alive = false;
111-
try {
112-
c.conn->isMaster( res );
113-
alive = true;
114-
} catch ( const DBException e ) {
115-
// There's something wrong with this connection, swallow the exception and do not
116-
// put the connection back in the pool.
117-
LOG(1) << "Exception thrown when checking pooled connection to " <<
118-
c.conn->getServerAddress() << ": " << causedBy(e) << endl;
119-
delete c.conn;
120-
c.conn = NULL;
121-
}
122-
if ( alive ) {
123-
all.push_back( c );
124-
}
125-
}
126-
127-
for ( vector<StoredConnection>::iterator i=all.begin(); i != all.end(); ++i ) {
128-
_pool.push( *i );
108+
delete c.conn;
129109
}
130110
}
131111

src/mongo/client/dbclient.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,10 @@ namespace mongo {
835835

836836
list<string> DBClientWithCommands::getDatabaseNames() {
837837
BSONObj info;
838-
uassert( 10005 , "listdatabases failed" , runCommand( "admin" , BSON( "listDatabases" << 1 ) , info ) );
838+
uassert(10005, "listdatabases failed", runCommand("admin",
839+
BSON("listDatabases" << 1),
840+
info,
841+
QueryOption_SlaveOk));
839842
uassert( 10006 , "listDatabases.databases not array" , info["databases"].type() == Array );
840843

841844
list<string> names;

src/mongo/client/dbclientinterface.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ namespace mongo {
8585
*/
8686
QueryOption_PartialResults = 1 << 7 ,
8787

88-
QueryOption_AllSupported = QueryOption_CursorTailable | QueryOption_SlaveOk | QueryOption_OplogReplay | QueryOption_NoCursorTimeout | QueryOption_AwaitData | QueryOption_Exhaust | QueryOption_PartialResults
89-
88+
QueryOption_AllSupported = QueryOption_CursorTailable |
89+
QueryOption_SlaveOk |
90+
QueryOption_OplogReplay |
91+
QueryOption_NoCursorTimeout |
92+
QueryOption_AwaitData |
93+
QueryOption_Exhaust |
94+
QueryOption_PartialResults,
9095
};
9196

9297
enum MONGO_CLIENT_API UpdateOptions {

src/mongo/util/mongoutils/str.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,16 @@
1717

1818
#pragma once
1919

20-
/* Things in the mongoutils namespace
21-
(1) are not database specific, rather, true utilities
22-
(2) are cross platform
23-
(3) may require boost headers, but not libs
24-
(4) are clean and easy to use in any c++ project without pulling in lots of other stuff
25-
26-
Note: within this module, we use int for all offsets -- there are no unsigned offsets
27-
and no size_t's. If you need 3 gigabyte long strings, don't use this module.
28-
*/
20+
/**
21+
* String utilities.
22+
*
23+
* TODO: De-inline.
24+
* TODO: Retire the mongoutils namespace, and move str under the mongo namespace.
25+
*/
2926

3027
#include <string>
3128
#include <sstream>
3229

33-
// this violates the README rules for mongoutils:
3430
#include "mongo/bson/util/builder.h"
3531

3632
namespace mongoutils {
@@ -214,6 +210,10 @@ namespace mongoutils {
214210
}
215211
}
216212

217-
}
213+
} // namespace str
214+
215+
} // namespace mongoutils
218216

219-
}
217+
namespace mongo {
218+
using namespace mongoutils;
219+
} // namespace mongo

src/mongo/util/net/ssl_manager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,9 @@ namespace mongo {
532532
context);
533533

534534
// SSL_OP_ALL - Activate all bug workaround options, to support buggy client SSL's.
535-
// SSL_OP_NO_SSLv2 - Disable SSL v2 support
536-
SSL_CTX_set_options(*context, SSL_OP_ALL|SSL_OP_NO_SSLv2);
535+
// SSL_OP_NO_SSLv2 - Disable SSL v2 support
536+
// SSL_OP_NO_SSLv3 - Disable SSL v3 support
537+
SSL_CTX_set_options(*context, SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
537538

538539
// HIGH - Enable strong ciphers
539540
// !EXPORT - Disable export ciphers (40/56 bit)

src/mongo/util/version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace mongo {
3131
* 1.2.3-rc4-pre-
3232
* If you really need to do something else you'll need to fix _versionArray()
3333
*/
34-
const char versionString[] = "2.6.5";
34+
const char versionString[] = "2.6.6";
3535

3636
// See unit test for example outputs
3737
BSONArray toVersionArray(const char* version){

0 commit comments

Comments
 (0)