summaryrefslogtreecommitdiff
path: root/s/d_logic.h
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
committerAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
commit7645618fd3914cb8a20561625913c20d49504a49 (patch)
tree8370f846f58f6d71165b7a0e2eda04648584ec76 /s/d_logic.h
parent68c73c3c7608b4c87f07440dc3232801720b1168 (diff)
downloadmongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz
Imported Upstream version 1.6.0
Diffstat (limited to 's/d_logic.h')
-rw-r--r--s/d_logic.h139
1 files changed, 137 insertions, 2 deletions
diff --git a/s/d_logic.h b/s/d_logic.h
index e426cb2..0f7ba35 100644
--- a/s/d_logic.h
+++ b/s/d_logic.h
@@ -18,10 +18,135 @@
#pragma once
-#include "../stdafx.h"
+#include "../pch.h"
+#include "../db/jsobj.h"
+#include "util.h"
namespace mongo {
+
+ class ShardingState;
+
+ typedef ShardChunkVersion ConfigVersion;
+ typedef map<string,ConfigVersion> NSVersionMap;
+
+ // -----------
+
+ class ChunkMatcher {
+ typedef map<BSONObj,pair<BSONObj,BSONObj>,BSONObjCmp> MyMap;
+ public:
+
+ bool belongsToMe( const BSONObj& key , const DiskLoc& loc ) const;
+
+ private:
+ ChunkMatcher( ConfigVersion version );
+
+ void gotRange( const BSONObj& min , const BSONObj& max );
+
+ ConfigVersion _version;
+ BSONObj _key;
+ MyMap _map;
+
+ friend class ShardingState;
+ };
+
+ typedef shared_ptr<ChunkMatcher> ChunkMatcherPtr;
+
+ // --------------
+ // --- global state ---
+ // --------------
+
+ class ShardingState {
+ public:
+ ShardingState();
+
+ bool enabled() const { return _enabled; }
+ const string& getConfigServer() const { return _configServer; }
+ void enable( const string& server );
+
+ void gotShardName( const string& name );
+ void gotShardHost( const string& host );
+
+ bool hasVersion( const string& ns );
+ bool hasVersion( const string& ns , ConfigVersion& version );
+ ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues
+ void setVersion( const string& ns , const ConfigVersion& version );
+
+ void appendInfo( BSONObjBuilder& b );
+
+ ChunkMatcherPtr getChunkMatcher( const string& ns );
+
+ bool inCriticalMigrateSection();
+ private:
+
+ bool _enabled;
+
+ string _configServer;
+
+ string _shardName;
+ string _shardHost;
+
+ mongo::mutex _mutex;
+ NSVersionMap _versions;
+ map<string,ChunkMatcherPtr> _chunks;
+ };
+
+ extern ShardingState shardingState;
+
+ // --------------
+ // --- per connection ---
+ // --------------
+
+ class ShardedConnectionInfo {
+ public:
+ ShardedConnectionInfo();
+
+ const OID& getID() const { return _id; }
+ bool hasID() const { return _id.isSet(); }
+ void setID( const OID& id );
+
+ ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues
+ void setVersion( const string& ns , const ConfigVersion& version );
+
+ static ShardedConnectionInfo* get( bool create );
+ static void reset();
+
+ bool inForceMode() const {
+ return _forceMode;
+ }
+
+ void enterForceMode(){ _forceMode = true; }
+ void leaveForceMode(){ _forceMode = false; }
+
+ private:
+
+ OID _id;
+ NSVersionMap _versions;
+ bool _forceMode;
+
+ static boost::thread_specific_ptr<ShardedConnectionInfo> _tl;
+ };
+
+ struct ShardForceModeBlock {
+ ShardForceModeBlock(){
+ info = ShardedConnectionInfo::get( false );
+ if ( info )
+ info->enterForceMode();
+ }
+ ~ShardForceModeBlock(){
+ if ( info )
+ info->leaveForceMode();
+ }
+
+ ShardedConnectionInfo * info;
+ };
+
+ // -----------------
+ // --- core ---
+ // -----------------
+ unsigned long long extractVersion( BSONElement e , string& errmsg );
+
+
/**
* @return true if we have any shard info for the ns
*/
@@ -35,5 +160,15 @@ namespace mongo {
/**
* @return true if we took care of the message and nothing else should be done
*/
- bool handlePossibleShardedMessage( Message &m, DbResponse &dbresponse );
+ bool handlePossibleShardedMessage( Message &m, DbResponse * dbresponse );
+
+ void logOpForSharding( const char * opstr , const char * ns , const BSONObj& obj , BSONObj * patt );
+
+ // -----------------
+ // --- writeback ---
+ // -----------------
+
+ /* queue a write back on a remote server for a failed write */
+ void queueWriteBack( const string& remote , const BSONObj& o );
+
}