diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-10 00:39:30 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-10 00:39:30 -0400 |
commit | b9d61d202c7acebac58ce55c1da89f8e67dd29a7 (patch) | |
tree | fe56d8117ca8010afc1f904d3c6a131f95436d65 | |
parent | 30d4cf6114b4eb8321b67baabf52a592d0d80014 (diff) | |
download | mongo-b9d61d202c7acebac58ce55c1da89f8e67dd29a7.tar.gz |
sharding config db versioning SHARDING-33
-rw-r--r-- | s/config.cpp | 44 | ||||
-rw-r--r-- | s/config.h | 12 | ||||
-rw-r--r-- | s/server.cpp | 8 |
3 files changed, 62 insertions, 2 deletions
diff --git a/s/config.cpp b/s/config.cpp index b830b83664a..51334d79b47 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -29,6 +29,8 @@ namespace mongo { + int ConfigServer::VERSION = 2; + /* --- DBConfig --- */ string DBConfig::modelServer() { @@ -314,6 +316,48 @@ namespace mongo { return true; } + + int ConfigServer::dbConfigVersion(){ + ScopedDbConnection conn( _primary ); + int version = dbConfigVersion( conn.conn() ); + conn.done(); + return version; + } + + int ConfigServer::dbConfigVersion( DBClientBase& conn ){ + auto_ptr<DBClientCursor> c = conn.query( "config.version" , BSONObj() ); + int version = 0; + if ( c->more() ){ + BSONObj o = c->next(); + version = o["version"].numberInt(); + uassert( "should only have 1 thing in config.version" , ! c->more() ); + } + else { + if ( conn.count( "config.shard" ) || conn.count( "config.databases" ) ){ + version = 1; + } + } + + return version; + } + + int ConfigServer::checkConfigVersion(){ + int cur = dbConfigVersion(); + if ( cur == VERSION ) + return 0; + + if ( cur == 0 ){ + ScopedDbConnection conn( _primary ); + conn->insert( "config.version" , BSON( "version" << VERSION ) ); + pool.flush(); + assert( VERSION == dbConfigVersion( conn.conn() ) ); + conn.done(); + return 0; + } + + log() << "don't know how to upgrade " << cur << " to " << VERSION << endl; + return -8; + } string ConfigServer::getHost( string name , bool withPort ){ if ( name.find( ":" ) ){ diff --git a/s/config.h b/s/config.h index 9e34c9fc243..edf813cce64 100644 --- a/s/config.h +++ b/s/config.h @@ -29,7 +29,7 @@ #include "shardkey.h" namespace mongo { - + class Grid; class ConfigServer; @@ -150,6 +150,16 @@ namespace mongo { call at startup, this will initiate connection to the grid db */ bool init( vector<string> configHosts , bool infer ); + + int dbConfigVersion(); + int dbConfigVersion( DBClientBase& conn ); + + /** + * @return 0 = ok, otherwise error # + */ + int checkConfigVersion(); + + static int VERSION; private: string getHost( string name , bool withPort ); diff --git a/s/server.cpp b/s/server.cpp index 8a8177498f4..f878c1372c8 100644 --- a/s/server.cpp +++ b/s/server.cpp @@ -164,8 +164,14 @@ int main(int argc, char* argv[], char *envp[] ) { cerr << "couldn't connectd to config db" << endl; return 7; } - + assert( configServer.ok() ); + + int configError = configServer.checkConfigVersion(); + if ( configError ){ + cerr << "config server error: " << configError << endl; + return configError; + } init(); start(); |