Files
mongo/dbgrid/gridconfig.cpp

70 lines
2.0 KiB
C++
Raw Normal View History

// gridconfig.cpp
2008-10-13 17:58:51 -04:00
/**
* Copyright (C) 2008 10gen Inc.
2008-12-28 20:28:49 -05:00
*
2008-10-13 17:58:51 -04:00
* 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.
2008-12-28 20:28:49 -05:00
*
2008-10-13 17:58:51 -04:00
* 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.
2008-12-28 20:28:49 -05:00
*
2008-10-13 17:58:51 -04:00
* 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
2009-01-14 17:09:51 -05:00
namespace mongo {
/* --- Machine --- */
map<string, Machine*> Machine::machines;
2008-10-19 17:46:53 -05: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];
if ( cc == 0 ) {
cc = new ClientConfig();
if ( !cc->loadByName(database.c_str()) ) {
log() << "couldn't find database " << database << " in grid db" << endl;
// note here that cc->primary == 0.
}
2008-10-19 17:46:53 -05:00
}
return cc;
2008-10-19 17:46:53 -05:00
}
/* --- Grid --- */
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
if ( !cc->partitioned ) {
if ( !cc->primary )
throw UserAssertionException(string("dbgrid: no primary for ")+ns);
return cc->primary;
}
2008-10-14 14:02:43 -04:00
uassert("dbgrid: not implemented 100", false);
return 0;
}
2009-01-14 17:09:51 -05:00
} // namespace mongo