Files
mongo/dbgrid/gridconfig.cpp

66 lines
1.9 KiB
C++
Raw Normal View History

// gridconfig.cpp
2008-10-13 17:58:51 -04:00
/**
* 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/>.
*/
#include "stdafx.h"
#include "../grid/message.h"
#include "../util/unittest.h"
2008-10-31 19:17:54 -05:00
#include "../client/connpool.h"
#include "../db/pdfile.h"
2008-10-13 17:58:51 -04:00
#include "gridconfig.h"
2008-10-24 17:51:28 -04:00
#include "../client/model.h"
2008-10-13 17:58:51 -04:00
2008-10-24 17:51:28 -04:00
/* --- Machine --- */
2008-10-24 17:51:28 -04:00
map<string, Machine*> Machine::machines;
2008-10-19 17:46:53 -05:00
2008-10-24 17:51:28 -04:00
/* --- GridConfig --- */
2008-10-19 17:46:53 -05:00
2008-10-24 17:51:28 -04:00
//static boost::mutex loc_mutex;
Grid grid;
2008-10-19 17:46:53 -05:00
ClientConfig* GridConfig::getClientConfig(string database) {
ClientConfig*& cc = databases[database];
2008-10-24 17:51:28 -04:00
if( cc == 0 ) {
cc = new ClientConfig();
if( !cc->loadByName(database.c_str()) ) {
log() << "couldn't find database " << database << " in grid db" << endl;
2008-10-24 17:51:28 -04:00
// note here that cc->primary == 0.
2008-10-19 17:46:53 -05:00
}
}
2008-10-24 17:51:28 -04:00
return cc;
}
2008-10-24 17:51:28 -04:00
/* --- Grid --- */
2008-10-24 17:51:28 -04:00
Machine* Grid::owner(const char *ns, BSONObj& objOrKey) {
ClientConfig *cc = gc.getClientConfig( nsToClient(ns) );
if( cc == 0 ) {
throw UserAssertionException(
string("dbgrid: no config for db for ") + ns);
}
2008-10-19 17:46:53 -05:00
2008-10-24 17:51:28 -04:00
if( !cc->partitioned ) {
if( !cc->primary )
throw UserAssertionException(string("dbgrid: no primary for ")+ns);
2008-10-24 17:51:28 -04:00
return cc->primary;
}
2008-10-14 14:02:43 -04:00
uassert("dbgrid: not implemented 100", false);
2008-10-24 17:51:28 -04:00
return 0;
2008-10-14 14:02:43 -04:00
}