summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/database_holder.h
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-09-26 14:02:49 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-10-06 17:30:12 -0400
commit101e026f45dea5e9e68520238495c89a476e6172 (patch)
treebbdd3710ffc5721527ad9f5682ef0dbb4876dfee /src/mongo/db/catalog/database_holder.h
parent10c86dc6cad9853514148e0ab59894a0d29353b9 (diff)
downloadmongo-101e026f45dea5e9e68520238495c89a476e6172.tar.gz
SERVER-14668/SERVER-15294 Collection-level locking for all read paths
Diffstat (limited to 'src/mongo/db/catalog/database_holder.h')
-rw-r--r--src/mongo/db/catalog/database_holder.h59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h
index c4ca5a47280..dd3afdf2470 100644
--- a/src/mongo/db/catalog/database_holder.h
+++ b/src/mongo/db/catalog/database_holder.h
@@ -39,30 +39,41 @@ namespace mongo {
* Registry of opened databases.
*/
class DatabaseHolder {
- typedef StringMap<Database*> DBs;
- // todo: we want something faster than this if called a lot:
- mutable SimpleMutex _m;
- DBs _dbs;
public:
DatabaseHolder() : _m("dbholder") { }
- Database* get(OperationContext* txn,
- const StringData& ns) const;
-
- Database* getOrCreate(OperationContext* txn,
- const StringData& ns,
- bool& justCreated);
+ /**
+ * Retrieves an already opened database or returns NULL. Must be called with the database
+ * locked in at least IS-mode.
+ */
+ Database* get(OperationContext* txn, const StringData& ns) const;
+ /**
+ * Retrieves a database reference if it is already opened, or opens it if it hasn't been
+ * opened/created yet. Must be called with the database locked in X-mode.
+ *
+ * @param justCreated Returns whether the database was newly created (true) or it already
+ * existed (false). Can be NULL if this information is not necessary.
+ */
+ Database* openDb(OperationContext* txn, const StringData& ns, bool* justCreated = NULL);
+ /**
+ * Closes the specified database. Must be called with the database locked in X-mode.
+ */
void close(OperationContext* txn, const StringData& ns);
- /** @param force - force close even if something underway - use at shutdown */
- bool closeAll(OperationContext* txn,
- BSONObjBuilder& result,
- bool force);
+ /**
+ * Closes all opened databases. Must be called with the global lock acquired in X-mode.
+ *
+ * @param result Populated with the names of the databases, which were closed.
+ * @param force Force close even if something underway - use at shutdown
+ */
+ bool closeAll(OperationContext* txn, BSONObjBuilder& result, bool force);
/**
- * need some lock
+ * Retrieves the names of all currently opened databases. Does not require locking, but it
+ * is not guaranteed that the returned set of names will be still valid unless a global
+ * lock is held, which would prevent database from disappearing or being created.
*/
void getAllShortNames( std::set<std::string>& all ) const {
SimpleMutex::scoped_lock lk(_m);
@@ -72,20 +83,10 @@ namespace mongo {
}
private:
- static StringData _todb( const StringData& ns ) {
- StringData d = __todb( ns );
- uassert(13280, "invalid db name: " + ns.toString(), NamespaceString::validDBName(d));
- return d;
- }
- static StringData __todb( const StringData& ns ) {
- size_t i = ns.find( '.' );
- if ( i == std::string::npos ) {
- uassert( 13074 , "db name can't be empty" , ns.size() );
- return ns;
- }
- uassert( 13075 , "db name can't be empty" , i > 0 );
- return ns.substr( 0 , i );
- }
+ typedef StringMap<Database*> DBs;
+
+ mutable SimpleMutex _m;
+ DBs _dbs;
};
DatabaseHolder& dbHolder();