mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
sharding version management for mongod
This commit is contained in:
parent
a58e2ce7bd
commit
d02951083c
@ -139,6 +139,10 @@ coreServerFiles = [ "util/message_server_port.cpp" , "util/message_server_asio.c
|
||||
|
||||
serverOnlyFiles = Split( "db/query.cpp db/introspect.cpp db/btree.cpp db/clientcursor.cpp db/javajs.cpp db/tests.cpp db/repl.cpp db/btreecursor.cpp db/cloner.cpp db/namespace.cpp db/matcher.cpp db/dbcommands.cpp db/dbeval.cpp db/dbwebserver.cpp db/dbinfo.cpp db/dbhelpers.cpp db/instance.cpp db/pdfile.cpp db/cursor.cpp db/security_commands.cpp db/security.cpp util/miniwebserver.cpp db/storage.cpp db/reccache.cpp db/queryoptimizer.cpp" )
|
||||
|
||||
coreShardFiles = []
|
||||
shardServerFiles = coreShardFiles + Glob( "s/strategy*.cpp" ) + [ "s/commands.cpp" , "s/request.cpp" , "s/cursors.cpp" , "s/server.cpp" ] + [ "s/shard.cpp" , "s/shardkey.cpp" , "s/config.cpp" ]
|
||||
serverOnlyFiles += coreShardFiles + [ "s/commands_db.cpp" ]
|
||||
|
||||
allClientFiles = commonFiles + coreDbFiles + [ "client/clientOnly.cpp" , "client/gridfs.cpp" ];
|
||||
|
||||
onlyServer = len( COMMAND_LINE_TARGETS ) == 0 or ( len( COMMAND_LINE_TARGETS ) == 1 and str( COMMAND_LINE_TARGETS[0] ) == "mongod" )
|
||||
@ -522,7 +526,7 @@ env.Program( "mongoimportjson" , allToolFiles + [ "tools/importJSON.cpp" ] )
|
||||
env.Program( "mongofiles" , allToolFiles + [ "tools/files.cpp" ] )
|
||||
|
||||
# mongos
|
||||
mongos = env.Program( "mongos" , commonFiles + coreDbFiles + coreServerFiles + Glob( "s/*.cpp" ) )
|
||||
mongos = env.Program( "mongos" , commonFiles + coreDbFiles + coreServerFiles + shardServerFiles )
|
||||
|
||||
# c++ library
|
||||
clientLibName = str( env.Library( "mongoclient" , allClientFiles )[0] )
|
||||
|
20
jstests/sharding/version1.js
Normal file
20
jstests/sharding/version1.js
Normal file
@ -0,0 +1,20 @@
|
||||
// version1.js
|
||||
|
||||
s = new ShardingTest( "version1" , 1 , 2 )
|
||||
|
||||
a = s._connections[0].getDB( "admin" );
|
||||
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).ok == 0 );
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : "a" } ).ok == 0 );
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 2 } ).ok == 1 );
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : "a" , version : 2 } ).ok == 0 );
|
||||
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 2 } ).ok == 1 );
|
||||
assert( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 1 } ).ok == 0 );
|
||||
|
||||
assert.eq( a.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 3 } ).oldVersion.i , 2 , "oldVersion" );
|
||||
|
||||
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" } ).mine.i , 3 , "my get version A" );
|
||||
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" } ).global.i , 3 , "my get version B" );
|
||||
|
||||
s.stop();
|
165
s/commands_db.cpp
Normal file
165
s/commands_db.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
// commands_db.cpp
|
||||
|
||||
/**
|
||||
* Copyright (C) 2008 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/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
these are commands that live in mongod
|
||||
mostly around shard management and checking
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "../db/commands.h"
|
||||
#include "../db/jsobj.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mongo {
|
||||
|
||||
typedef map<string,unsigned long long> NSVersions;
|
||||
|
||||
NSVersions myVersions;
|
||||
boost::thread_specific_ptr<NSVersions> clientShardVersions;
|
||||
string shardConfigServer;
|
||||
|
||||
|
||||
class MongodShardCommand : public Command {
|
||||
public:
|
||||
MongodShardCommand( const char * n ) : Command( n ){
|
||||
}
|
||||
virtual bool slaveOk(){
|
||||
return false;
|
||||
}
|
||||
virtual bool adminOnly() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// setShardVersion( ns )
|
||||
|
||||
class SetShardVersion : public MongodShardCommand {
|
||||
public:
|
||||
SetShardVersion() : MongodShardCommand("setShardVersion"){}
|
||||
|
||||
virtual void help( stringstream& help ) const {
|
||||
help << " example: { setShardVersion : 'alleyinsider.foo' , version : 1 , configdb : '' } ";
|
||||
}
|
||||
|
||||
bool run(const char *cmdns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
||||
|
||||
string configdb = cmdObj["configdb"].valuestrsafe();
|
||||
{ // configdb checking
|
||||
if ( configdb.size() == 0 ){
|
||||
errmsg = "no configdb";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( shardConfigServer.size() == 0 ){
|
||||
shardConfigServer = configdb;
|
||||
}
|
||||
else if ( shardConfigServer != configdb ){
|
||||
errmsg = "specified a different configdb!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long version;
|
||||
{
|
||||
BSONElement e = cmdObj["version"];
|
||||
if ( e.eoo() ){
|
||||
errmsg = "no version";
|
||||
return false;
|
||||
}
|
||||
else if ( e.isNumber() )
|
||||
version = (unsigned long long)e.number();
|
||||
else if ( e.type() == Date || e.type() == Timestamp )
|
||||
version = e.date();
|
||||
else {
|
||||
errmsg = "version is not a numberic type";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NSVersions * versions = clientShardVersions.get();
|
||||
|
||||
if ( ! versions ){
|
||||
log(1) << "entering shard mode for connection" << endl;
|
||||
versions = new NSVersions();
|
||||
clientShardVersions.reset( versions );
|
||||
}
|
||||
|
||||
string ns = cmdObj["setShardVersion"].valuestrsafe();
|
||||
if ( ns.size() == 0 ){
|
||||
errmsg = "need to speciy fully namespace";
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long long& oldVersion = (*versions)[ns];
|
||||
if ( version < oldVersion ){
|
||||
errmsg = "going to older version for you!";
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long long& myVersion = myVersions[ns];
|
||||
if ( version < myVersion ){
|
||||
errmsg = "going to older version for global";
|
||||
return false;
|
||||
}
|
||||
|
||||
result.appendTimestamp( "oldVersion" , oldVersion );
|
||||
oldVersion = version;
|
||||
myVersion = version;
|
||||
|
||||
result.append( "ok" , 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
} setShardVersion;
|
||||
|
||||
class GetShardVersion : public MongodShardCommand {
|
||||
public:
|
||||
GetShardVersion() : MongodShardCommand("getShardVersion"){}
|
||||
|
||||
virtual void help( stringstream& help ) const {
|
||||
help << " example: { getShardVersion : 'alleyinsider.foo' } ";
|
||||
}
|
||||
|
||||
bool run(const char *cmdns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
||||
string ns = cmdObj["getShardVersion"].valuestrsafe();
|
||||
if ( ns.size() == 0 ){
|
||||
errmsg = "need to speciy fully namespace";
|
||||
return false;
|
||||
}
|
||||
|
||||
result.appendTimestamp( "global" , myVersions[ns] );
|
||||
if ( clientShardVersions.get() )
|
||||
result.appendTimestamp( "mine" , (*clientShardVersions.get())[ns] );
|
||||
else
|
||||
result.appendTimestamp( "mine" , 0 );
|
||||
|
||||
result.append( "ok" , 1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
} getShardVersion;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user