summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-09-25 14:08:28 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-09-25 22:13:39 -0400
commita1f9188b4d58daa4e80a344116dbd85b636962da (patch)
treebee3a3f252ef90ef97a052a4b07c8621fa31ea5a
parente402881e004283d292dd3e483a9df1dbd2b066e2 (diff)
downloadmongo-a1f9188b4d58daa4e80a344116dbd85b636962da.tar.gz
SERVER-14668 Use ensureShardVersionOKOrThrow for collection shard version checking
This commit exposes a SendStaleConfigException-based method for checking shard staleness. This will be used in all methods (other than the batch executor). Also clean-up some unnecessary includes.
-rw-r--r--src/mongo/client/parallel.cpp1
-rw-r--r--src/mongo/client/parallel.h3
-rw-r--r--src/mongo/db/client.cpp10
-rw-r--r--src/mongo/db/client.h2
-rw-r--r--src/mongo/db/exec/shard_filter.cpp1
-rw-r--r--src/mongo/db/exec/shard_filter.h1
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp4
-rw-r--r--src/mongo/s/commands_public.cpp1
-rw-r--r--src/mongo/s/d_state.cpp17
-rw-r--r--src/mongo/s/d_state.h16
-rw-r--r--src/mongo/s/strategy.cpp1
11 files changed, 34 insertions, 23 deletions
diff --git a/src/mongo/client/parallel.cpp b/src/mongo/client/parallel.cpp
index f00d4b2255f..a1dd6811386 100644
--- a/src/mongo/client/parallel.cpp
+++ b/src/mongo/client/parallel.cpp
@@ -43,6 +43,7 @@
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/s/version_manager.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/client/parallel.h b/src/mongo/client/parallel.h
index 3cfec0af10c..0a16d9c8a34 100644
--- a/src/mongo/client/parallel.h
+++ b/src/mongo/client/parallel.h
@@ -38,11 +38,12 @@
#include "mongo/db/matcher/matcher.h"
#include "mongo/db/namespace_string.h"
#include "mongo/s/shard.h"
-#include "mongo/s/stale_exception.h" // for StaleConfigException
#include "mongo/util/concurrency/mvar.h"
namespace mongo {
+ class StaleConfigException;
+
/**
* holder for a server address and a query to run
*/
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 779f21fe0e9..812e062ede9 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -59,7 +59,6 @@
#include "mongo/db/storage_options.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/d_state.h"
-#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/scripting/engine.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/file_allocator.h"
@@ -255,14 +254,7 @@ namespace mongo {
case dbDelete:
break;
default: {
- string errmsg;
- ChunkVersion received;
- ChunkVersion wanted;
- if ( ! shardVersionOk( _ns , errmsg, received, wanted ) ) {
- ostringstream os;
- os << "[" << _ns << "] shard version not ok in Client::Context: " << errmsg;
- throw SendStaleConfigException( _ns, os.str(), received, wanted );
- }
+ ensureShardVersionOKOrThrow(_ns);
}
}
}
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h
index 31a1b272f20..265b8439037 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -154,7 +154,7 @@ namespace mongo {
Context(OperationContext* txn, const std::string& ns, bool doVersion = true);
/** note: this does not call finishInit -- i.e., does not call
- shardVersionOk() for example.
+ ensureShardVersionOKOrThrow for example.
see also: reset().
*/
Context(OperationContext* txn, const std::string& ns, Database * db);
diff --git a/src/mongo/db/exec/shard_filter.cpp b/src/mongo/db/exec/shard_filter.cpp
index 009cec15dd9..7ccd53b23dc 100644
--- a/src/mongo/db/exec/shard_filter.cpp
+++ b/src/mongo/db/exec/shard_filter.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/exec/filter.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/keypattern.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/util/log.h"
namespace mongo {
diff --git a/src/mongo/db/exec/shard_filter.h b/src/mongo/db/exec/shard_filter.h
index aecb31d92b8..556732d0715 100644
--- a/src/mongo/db/exec/shard_filter.h
+++ b/src/mongo/db/exec/shard_filter.h
@@ -33,7 +33,6 @@
#include "mongo/db/exec/plan_stage.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/d_state.h"
-#include "mongo/s/stale_exception.h"
namespace mongo {
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index 5e96f5e7cf2..c501c7f38f7 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -26,7 +26,7 @@
* it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include "mongo/db/pipeline/document_source.h"
@@ -37,7 +37,7 @@
#include "mongo/db/query/find_constants.h"
#include "mongo/db/storage_options.h"
#include "mongo/s/d_state.h"
-#include "mongo/s/stale_exception.h" // for SendStaleConfigException
+
namespace mongo {
diff --git a/src/mongo/s/commands_public.cpp b/src/mongo/s/commands_public.cpp
index 2b8aadab8d2..2f6be050fe9 100644
--- a/src/mongo/s/commands_public.cpp
+++ b/src/mongo/s/commands_public.cpp
@@ -59,6 +59,7 @@
#include "mongo/s/cursors.h"
#include "mongo/s/distlock.h"
#include "mongo/s/grid.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/s/strategy.h"
#include "mongo/s/version_manager.h"
#include "mongo/scripting/engine.h"
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index 809053fb56e..71340b94288 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -59,6 +59,7 @@
#include "mongo/s/d_state.h"
#include "mongo/s/metadata_loader.h"
#include "mongo/s/shard.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/util/queue.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/concurrency/ticketholder.h"
@@ -1310,7 +1311,10 @@ namespace mongo {
* @ return true if not in sharded mode
or if version for this client is ok
*/
- bool shardVersionOk( const string& ns , string& errmsg, ChunkVersion& received, ChunkVersion& wanted ) {
+ static bool shardVersionOk(const string& ns,
+ string& errmsg,
+ ChunkVersion& received,
+ ChunkVersion& wanted) {
if ( ! shardingState.enabled() )
return true;
@@ -1386,6 +1390,17 @@ namespace mongo {
}
+ void ensureShardVersionOKOrThrow(const std::string& ns) {
+ string errmsg;
+ ChunkVersion received;
+ ChunkVersion wanted;
+ if (!shardVersionOk(ns, errmsg, received, wanted)) {
+ StringBuilder sb;
+ sb << "[" << ns << "] shard version not ok in Client::Context: " << errmsg;
+ throw SendStaleConfigException(ns, sb.str(), received, wanted);
+ }
+ }
+
void usingAShardConnection( const string& addr ) {
}
}
diff --git a/src/mongo/s/d_state.h b/src/mongo/s/d_state.h
index 44332bafe7e..07be13aa28f 100644
--- a/src/mongo/s/d_state.h
+++ b/src/mongo/s/d_state.h
@@ -29,8 +29,6 @@
#pragma once
-#include "mongo/pch.h"
-
#include "mongo/db/jsobj.h"
#include "mongo/s/collection_metadata.h"
#include "mongo/s/chunk_version.h"
@@ -357,13 +355,15 @@ namespace mongo {
bool haveLocalShardingInfo( const std::string& ns );
/**
- * @return true if the current threads shard version is ok, or not in sharded version
- * Also returns an error message and the Config/ChunkVersions causing conflicts
+ * Validates whether the shard chunk version for the specified collection is up to date and if
+ * not, throws SendStaleConfigException.
+ *
+ * It is important (but not enforced) that method be called with the collection locked in at
+ * least IS mode in order to ensure that the shard version won't change.
+ *
+ * @param ns Complete collection namespace to be cheched.
*/
- bool shardVersionOk( const std::string& ns,
- std::string& errmsg,
- ChunkVersion& received,
- ChunkVersion& wanted );
+ void ensureShardVersionOKOrThrow(const std::string& ns);
/**
* If a migration for the chunk in 'ns' where 'obj' lives is occurring, save this log entry
diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp
index 34d05825598..636d2923468 100644
--- a/src/mongo/s/strategy.cpp
+++ b/src/mongo/s/strategy.cpp
@@ -53,6 +53,7 @@
#include "mongo/s/cursors.h"
#include "mongo/s/grid.h"
#include "mongo/s/request.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/s/version_manager.h"
#include "mongo/s/write_ops/batch_upconvert.h"
#include "mongo/util/log.h"