summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/client/dbclient.cpp2
-rw-r--r--src/mongo/client/dbclientcursor.cpp2
-rw-r--r--src/mongo/client/parallel.cpp1
-rw-r--r--src/mongo/client/parallel.h2
-rw-r--r--src/mongo/db/client.cpp2
-rw-r--r--src/mongo/db/commands/mr.cpp28
-rw-r--r--src/mongo/db/dbcommands.cpp2
-rw-r--r--src/mongo/db/instance.cpp2
-rw-r--r--src/mongo/db/ops/query.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp2
-rw-r--r--src/mongo/s/shard_version.cpp3
-rw-r--r--src/mongo/s/shardconnection.cpp13
-rw-r--r--src/mongo/s/stale_exception.h174
-rw-r--r--src/mongo/s/strategy.cpp2
-rw-r--r--src/mongo/s/util.h113
15 files changed, 210 insertions, 140 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 3e3c40be2f8..db3955e357c 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -26,7 +26,7 @@
#include "mongo/db/json.h"
#include "mongo/db/namespace-inl.h"
#include "mongo/db/namespacestring.h"
-#include "mongo/s/util.h" // for RecvStaleConfigException
+#include "mongo/s/stale_exception.h" // for RecvStaleConfigException
#include "mongo/util/md5.hpp"
#ifdef MONGO_SSL
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index 13f92b8ed94..095b3a7a7cf 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -24,7 +24,7 @@
#include "mongo/db/dbmessage.h"
#include "mongo/db/namespacestring.h"
#include "mongo/s/shard.h"
-#include "mongo/s/util.h" // for RecvStaleConfigException
+#include "mongo/s/stale_exception.h" // for RecvStaleConfigException
namespace mongo {
diff --git a/src/mongo/client/parallel.cpp b/src/mongo/client/parallel.cpp
index 62ad404b260..c4d634f7f99 100644
--- a/src/mongo/client/parallel.cpp
+++ b/src/mongo/client/parallel.cpp
@@ -27,7 +27,6 @@
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard.h"
-#include "mongo/s/util.h" // for RecvStaleConfigException
namespace mongo {
diff --git a/src/mongo/client/parallel.h b/src/mongo/client/parallel.h
index 0ba6fee400b..bae89c36cc6 100644
--- a/src/mongo/client/parallel.h
+++ b/src/mongo/client/parallel.h
@@ -25,7 +25,7 @@
#include "mongo/db/matcher.h"
#include "mongo/db/namespacestring.h"
#include "mongo/s/shard.h"
-#include "mongo/s/util.h" // for StaleConfigException
+#include "mongo/s/stale_exception.h" // for StaleConfigException
#include "mongo/util/concurrency/mvar.h"
namespace mongo {
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index d71ff163c84..f45eedb099c 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -46,7 +46,7 @@
#include "mongo/db/security.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/d_logic.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/scripting/engine.h"
#include "mongo/util/file_allocator.h"
#include "mongo/util/mongoutils/checksum.h"
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 9e64a9a3f21..9a657cc8c46 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -17,22 +17,24 @@
*/
#include "pch.h"
-#include "../db.h"
-#include "../instance.h"
-#include "../commands.h"
-#include "../../scripting/engine.h"
-#include "../../client/connpool.h"
-#include "../../client/parallel.h"
-#include "../matcher.h"
-#include "../clientcursor.h"
-#include "../replutil.h"
-#include "../../s/d_chunk_manager.h"
-#include "../../s/d_logic.h"
-#include "../../s/grid.h"
-#include "mongo/db/kill_current_op.h"
#include "mr.h"
+#include "mongo/client/connpool.h"
+#include "mongo/client/parallel.h"
+#include "mongo/db/clientcursor.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/db.h"
+#include "mongo/db/instance.h"
+#include "mongo/db/kill_current_op.h"
+#include "mongo/db/matcher.h"
+#include "mongo/db/replutil.h"
+#include "mongo/scripting/engine.h"
+#include "mongo/s/d_chunk_manager.h"
+#include "mongo/s/d_logic.h"
+#include "mongo/s/grid.h"
+#include "mongo/s/stale_exception.h"
+
namespace mongo {
namespace mr {
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 0b188931b71..ee592b155f2 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -52,7 +52,7 @@
#include "mongo/db/replutil.h"
#include "mongo/db/security.h"
#include "mongo/s/d_writeback.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/scripting/engine.h"
#include "mongo/server.h"
#include "mongo/util/lruishmap.h"
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 8bae4646b2a..5a8ef365c26 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -57,7 +57,7 @@
#include "mongo/db/security.h"
#include "mongo/db/stats/counters.h"
#include "mongo/s/d_logic.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/util/file_allocator.h"
#include "mongo/util/goodies.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/db/ops/query.cpp b/src/mongo/db/ops/query.cpp
index a9ef07bc1bd..69154969df9 100644
--- a/src/mongo/db/ops/query.cpp
+++ b/src/mongo/db/ops/query.cpp
@@ -31,7 +31,7 @@
#include "mongo/db/replutil.h"
#include "mongo/db/scanandorder.h"
#include "mongo/s/d_logic.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/server.h"
namespace mongo {
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index 490e8118980..d5ddab1d069 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -22,7 +22,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/pipeline/document.h"
#include "mongo/s/d_logic.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
namespace mongo {
diff --git a/src/mongo/s/shard_version.cpp b/src/mongo/s/shard_version.cpp
index 7ce1bb6e4a3..ad382e69255 100644
--- a/src/mongo/s/shard_version.cpp
+++ b/src/mongo/s/shard_version.cpp
@@ -23,7 +23,8 @@
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
+#include "mongo/s/util.h"
#include "mongo/s/writeback_listener.h"
namespace mongo {
diff --git a/src/mongo/s/shardconnection.cpp b/src/mongo/s/shardconnection.cpp
index 6e1a44b2f67..92b0da040fa 100644
--- a/src/mongo/s/shardconnection.cpp
+++ b/src/mongo/s/shardconnection.cpp
@@ -17,14 +17,17 @@
*/
#include "pch.h"
-#include "../server.h"
-#include "shard.h"
-#include "config.h"
-#include "request.h"
+
+#include <set>
+
#include "mongo/db/client.h"
#include "mongo/db/security.h"
+#include "mongo/s/config.h"
+#include "mongo/s/request.h"
+#include "mongo/s/shard.h"
+#include "mongo/s/stale_exception.h"
+#include "mongo/server.h"
#include "mongo/util/stacktrace.h"
-#include <set>
namespace mongo {
diff --git a/src/mongo/s/stale_exception.h b/src/mongo/s/stale_exception.h
new file mode 100644
index 00000000000..2f7eb069a48
--- /dev/null
+++ b/src/mongo/s/stale_exception.h
@@ -0,0 +1,174 @@
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include "mongo/db/jsobj.h"
+#include "mongo/s/chunk_version.h"
+#include "mongo/util/assert_util.h"
+#include "mongo/util/mongoutils/str.h"
+
+namespace mongo {
+
+ using mongoutils::str::stream;
+
+ /**
+ * Thrown whenever your config info for a given shard/chunk is out of date.
+ */
+ class StaleConfigException : public AssertionException {
+ public:
+ StaleConfigException( const string& ns,
+ const string& raw,
+ int code,
+ ChunkVersion received,
+ ChunkVersion wanted,
+ bool justConnection = false )
+ : AssertionException(stream() << raw << " ( ns : " << ns
+ << ", received : " << received.toString()
+ << ", wanted : " << wanted.toString()
+ << ", " << ( code == SendStaleConfigCode ?
+ "send" : "recv" ) << " )",
+ code ),
+ _justConnection(justConnection),
+ _ns(ns),
+ _received( received ),
+ _wanted( wanted ) {
+ }
+
+ /** Preferred if we're rebuilding this from a thrown exception */
+ StaleConfigException( const string& raw,
+ int code,
+ const BSONObj& error,
+ bool justConnection = false )
+ : AssertionException( stream() << raw << " ( ns : "
+ << ( error["ns"].type() == String ?
+ error["ns"].String() : string("<unknown>") )
+ << ", received : "
+ << ChunkVersion::fromBSON( error, "vReceived" ).toString()
+ << ", wanted : "
+ << ChunkVersion::fromBSON( error, "vWanted" ).toString()
+ << ", "
+ << ( code == SendStaleConfigCode ?
+ "send" : "recv" ) << " )",
+ code ),
+ _justConnection(justConnection) ,
+ // For legacy reasons, we may not always get a namespace here
+ _ns( error["ns"].type() == String ? error["ns"].String() : "" ),
+ _received( ChunkVersion::fromBSON( error, "vReceived" ) ),
+ _wanted( ChunkVersion::fromBSON( error, "vWanted" ) ) {
+ }
+
+ /**
+ * Needs message so when we trace all exceptions on construction we get a useful
+ * message
+ */
+ StaleConfigException() :
+ AssertionException( "initializing empty stale config exception object", 0 ) {
+ }
+
+ virtual ~StaleConfigException() throw() {}
+
+ virtual void appendPrefix( stringstream& ss ) const {
+ ss << "stale sharding config exception: ";
+ }
+
+ bool justConnection() const { return _justConnection; }
+
+ string getns() const { return _ns; }
+
+ /**
+ * true if this exception would require a full reload of config data to resolve
+ */
+ bool requiresFullReload() const {
+ return ! _received.hasCompatibleEpoch( _wanted ) ||
+ _received.isSet() != _wanted.isSet();
+ }
+
+ static bool parse( const string& big , string& ns , string& raw ) {
+ string::size_type start = big.find( '[' );
+ if ( start == string::npos )
+ return false;
+ string::size_type end = big.find( ']' ,start );
+ if ( end == string::npos )
+ return false;
+
+ ns = big.substr( start + 1 , ( end - start ) - 1 );
+ raw = big.substr( end + 1 );
+ return true;
+ }
+
+ ChunkVersion getVersionReceived() const {
+ return _received;
+ }
+
+ ChunkVersion getVersionWanted() const {
+ return _wanted;
+ }
+
+ StaleConfigException& operator=( const StaleConfigException& elem ) {
+
+ this->_ei.msg = elem._ei.msg;
+ this->_ei.code = elem._ei.code;
+ this->_justConnection = elem._justConnection;
+ this->_ns = elem._ns;
+ this->_received = elem._received;
+ this->_wanted = elem._wanted;
+
+ return *this;
+ }
+
+ private:
+ bool _justConnection;
+ string _ns;
+ ChunkVersion _received;
+ ChunkVersion _wanted;
+ };
+
+ class SendStaleConfigException : public StaleConfigException {
+ public:
+ SendStaleConfigException( const string& ns,
+ const string& raw,
+ ChunkVersion received,
+ ChunkVersion wanted,
+ bool justConnection = false )
+ : StaleConfigException( ns, raw, SendStaleConfigCode, received, wanted, justConnection ){
+ }
+
+ SendStaleConfigException( const string& raw,
+ const BSONObj& error,
+ bool justConnection = false )
+ : StaleConfigException( raw, SendStaleConfigCode, error, justConnection ) {
+ }
+ };
+
+ class RecvStaleConfigException : public StaleConfigException {
+ public:
+ RecvStaleConfigException( const string& ns,
+ const string& raw,
+ ChunkVersion received,
+ ChunkVersion wanted,
+ bool justConnection = false )
+ : StaleConfigException( ns, raw, RecvStaleConfigCode, received, wanted, justConnection ){
+ }
+
+ RecvStaleConfigException( const string& raw,
+ const BSONObj& error,
+ bool justConnection = false )
+ : StaleConfigException( raw, RecvStaleConfigCode, error, justConnection ) {
+ }
+ };
+
+} // namespace mongo
diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp
index 3e60e60c02a..da04511fd0f 100644
--- a/src/mongo/s/strategy.cpp
+++ b/src/mongo/s/strategy.cpp
@@ -28,7 +28,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/request.h"
#include "mongo/s/server.h"
-#include "mongo/s/util.h" // for SendStaleConfigException
+#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/s/writeback_listener.h"
#include "mongo/util/mongoutils/str.h"
diff --git a/src/mongo/s/util.h b/src/mongo/s/util.h
index f2507213661..584bfb79897 100644
--- a/src/mongo/s/util.h
+++ b/src/mongo/s/util.h
@@ -16,11 +16,7 @@
#pragma once
-#include "mongo/pch.h"
-
#include "mongo/db/jsobj.h"
-#include "mongo/s/chunk_version.h"
-#include "mongo/util/mongoutils/str.h"
/**
some generic sharding utils that can be used in mongod or mongos
@@ -28,114 +24,9 @@
namespace mongo {
- /**
- * your config info for a given shard/chunk is out of date
- */
- class StaleConfigException : public AssertionException {
- public:
- StaleConfigException( const string& ns , const string& raw , int code, ChunkVersion received, ChunkVersion wanted, bool justConnection = false )
- : AssertionException(
- mongoutils::str::stream() << raw << " ( ns : " << ns <<
- ", received : " << received.toString() <<
- ", wanted : " << wanted.toString() <<
- ", " << ( code == SendStaleConfigCode ? "send" : "recv" ) << " )",
- code ),
- _justConnection(justConnection) ,
- _ns(ns),
- _received( received ),
- _wanted( wanted )
- {}
-
- // Preferred if we're rebuilding this from a thrown exception
- StaleConfigException( const string& raw , int code, const BSONObj& error, bool justConnection = false )
- : AssertionException( mongoutils::str::stream()
- << raw << " ( ns : " << ( error["ns"].type() == String ? error["ns"].String() : string("<unknown>") )
- << ", received : " << ChunkVersion::fromBSON( error, "vReceived" ).toString()
- << ", wanted : " << ChunkVersion::fromBSON( error, "vWanted" ).toString()
- << ", " << ( code == SendStaleConfigCode ? "send" : "recv" ) << " )",
- code ),
-
- _justConnection(justConnection) ,
- // For legacy reasons, we may not always get a namespace here
- _ns( error["ns"].type() == String ? error["ns"].String() : "" ),
- _received( ChunkVersion::fromBSON( error, "vReceived" ) ),
- _wanted( ChunkVersion::fromBSON( error, "vWanted" ) )
- {}
-
- // Needs message so when we trace all exceptions on construction we get a useful
- // message
- StaleConfigException() :
- AssertionException( "initializing empty stale config exception object", 0 ) {}
-
- virtual ~StaleConfigException() throw() {}
-
- virtual void appendPrefix( stringstream& ss ) const { ss << "stale sharding config exception: "; }
-
- bool justConnection() const { return _justConnection; }
-
- string getns() const { return _ns; }
-
- /**
- * true if this exception would require a full reload of config data to resolve
- */
- bool requiresFullReload() const {
- return ! _received.hasCompatibleEpoch( _wanted ) ||
- _received.isSet() != _wanted.isSet();
- }
-
- static bool parse( const string& big , string& ns , string& raw ) {
- string::size_type start = big.find( '[' );
- if ( start == string::npos )
- return false;
- string::size_type end = big.find( ']' ,start );
- if ( end == string::npos )
- return false;
-
- ns = big.substr( start + 1 , ( end - start ) - 1 );
- raw = big.substr( end + 1 );
- return true;
- }
-
- ChunkVersion getVersionReceived() const { return _received; }
- ChunkVersion getVersionWanted() const { return _wanted; }
-
- StaleConfigException& operator=( const StaleConfigException& elem ) {
-
- this->_ei.msg = elem._ei.msg;
- this->_ei.code = elem._ei.code;
- this->_justConnection = elem._justConnection;
- this->_ns = elem._ns;
- this->_received = elem._received;
- this->_wanted = elem._wanted;
-
- return *this;
- }
-
- private:
- bool _justConnection;
- string _ns;
- ChunkVersion _received;
- ChunkVersion _wanted;
- };
-
- class SendStaleConfigException : public StaleConfigException {
- public:
- SendStaleConfigException( const string& ns , const string& raw , ChunkVersion received, ChunkVersion wanted, bool justConnection = false )
- : StaleConfigException( ns, raw, SendStaleConfigCode, received, wanted, justConnection ) {}
- SendStaleConfigException( const string& raw , const BSONObj& error, bool justConnection = false )
- : StaleConfigException( raw, SendStaleConfigCode, error, justConnection ) {}
- };
-
- class RecvStaleConfigException : public StaleConfigException {
- public:
- RecvStaleConfigException( const string& ns , const string& raw , ChunkVersion received, ChunkVersion wanted, bool justConnection = false )
- : StaleConfigException( ns, raw, RecvStaleConfigCode, received, wanted, justConnection ) {}
- RecvStaleConfigException( const string& raw , const BSONObj& error, bool justConnection = false )
- : StaleConfigException( raw, RecvStaleConfigCode, error, justConnection ) {}
- };
-
class ShardConnection;
class DBClientBase;
+
class VersionManager {
public:
VersionManager(){};
@@ -151,4 +42,4 @@ namespace mongo {
extern VersionManager versionManager;
-}
+} // namespace mongo