summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-05-20 14:40:14 -0400
committerEliot Horowitz <eliot@10gen.com>2014-05-20 19:28:17 -0400
commite06a94e70c25ce97628dddbb551e5669f435922e (patch)
tree6df33b89ef6dff5e88efbc7880ca0e196293cb58
parent06bf11f51421f40f8bfe9c9de9b5422673291c28 (diff)
downloadmongo-e06a94e70c25ce97628dddbb551e5669f435922e.tar.gz
SERVER-13635: add DatabaseCatalogEntry as an interface
-rw-r--r--src/mongo/db/catalog/database.cpp10
-rw-r--r--src/mongo/db/catalog/database.h5
-rw-r--r--src/mongo/db/catalog/database_catalog_entry.h59
-rw-r--r--src/mongo/db/commands/dbhash.cpp3
-rw-r--r--src/mongo/db/db.cpp3
-rw-r--r--src/mongo/db/dbcommands.cpp8
-rw-r--r--src/mongo/db/index_rebuilder.cpp3
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp22
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_engine.h6
-rw-r--r--src/mongo/tools/dump.cpp3
10 files changed, 95 insertions, 27 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index d64ad95efc8..b7ea6ce2df2 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -317,10 +317,6 @@ namespace mongo {
return true;
}
- void Database::getCollectionNamespaces( std::list<std::string>* out ) const {
- _dbEntry->namespaceIndex().getCollectionNamespaces( out );
- }
-
long long Database::getIndexSizeForCollection(Collection* coll,
BSONObjBuilder* details,
int scale ) {
@@ -355,7 +351,7 @@ namespace mongo {
list<string> collections;
if ( !empty )
- getCollectionNamespaces( &collections );
+ _dbEntry->getCollectionNamespaces( &collections );
long long ncollections = 0;
long long objects = 0;
@@ -851,4 +847,8 @@ namespace mongo {
return !_dbEntry->namespaceIndex().allocated();
}
+ const DatabaseCatalogEntry* Database::getDatabaseCatalogEntry() const {
+ return _dbEntry.get();
+ }
+
} // namespace mongo
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index 69a35a41ad0..8fc2488c1f3 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -40,6 +40,7 @@
namespace mongo {
class Collection;
+ class DatabaseCatalogEntry;
class DataFile;
class ExtentManager;
class IndexCatalog;
@@ -148,14 +149,14 @@ namespace mongo {
int getProfilingLevel() const { return _profile; }
const char* getProfilingNS() const { return _profileName.c_str(); }
- void getCollectionNamespaces( std::list<std::string>* out ) const;
-
void getStats( BSONObjBuilder* output, double scale = 1 );
long long getIndexSizeForCollection( Collection* collections,
BSONObjBuilder* details = NULL,
int scale = 1 );
+ const DatabaseCatalogEntry* getDatabaseCatalogEntry() const;
+
// TODO: do not think this method should exist, so should try and encapsulate better
MmapV1ExtentManager* getExtentManager();
const MmapV1ExtentManager* getExtentManager() const;
diff --git a/src/mongo/db/catalog/database_catalog_entry.h b/src/mongo/db/catalog/database_catalog_entry.h
new file mode 100644
index 00000000000..bef89a1ddb1
--- /dev/null
+++ b/src/mongo/db/catalog/database_catalog_entry.h
@@ -0,0 +1,59 @@
+// database_catalog_entry.h
+
+/**
+* Copyright (C) 2014 MongoDB 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/>.
+*
+* As a special exception, the copyright holders give permission to link the
+* code of portions of this program with the OpenSSL library under certain
+* conditions as described in each individual source file and distribute
+* linked combinations including the program with the OpenSSL library. You
+* must comply with the GNU Affero General Public License in all respects for
+* all of the code used other than as permitted herein. If you modify file(s)
+* with this exception, you may extend this exception to your version of the
+* file(s), but you are not obligated to do so. If you do not wish to do so,
+* delete this exception statement from your version. If you delete this
+* exception statement from all source files in the program, then also delete
+* it in the license file.
+*/
+
+#pragma once
+
+#include <list>
+#include <string>
+
+#include "mongo/base/string_data.h"
+
+namespace mongo {
+
+ class OperationContext;
+
+ class DatabaseCatalogEntry {
+ public:
+ DatabaseCatalogEntry( const StringData& name )
+ : _name( name.toString() ) {
+ }
+
+ virtual ~DatabaseCatalogEntry(){ }
+
+ const std::string& name() const { return _name; }
+
+ // ----
+
+ virtual void getCollectionNamespaces( std::list<std::string>* out ) const = 0;
+
+ private:
+ std::string _name;
+ };
+}
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 0cfa4bcc598..cddac188c94 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/catalog/database.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/util/md5.hpp"
#include "mongo/util/timer.h"
@@ -147,7 +148,7 @@ namespace mongo {
Client::ReadContext ctx(ns);
Database* db = ctx.ctx().db();
if ( db )
- db->getCollectionNamespaces( &colls );
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces( &colls );
colls.sort();
result.appendNumber( "numCollections" , (long long)colls.size() );
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 4cdc5fde00d..290c1137e8b 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_manager_global.h"
#include "mongo/db/auth/authz_manager_external_state_d.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/catalog/index_key_validate.h"
#include "mongo/db/client.h"
@@ -327,7 +328,7 @@ namespace mongo {
}
list<string> collections;
- db->getCollectionNamespaces( &collections );
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces( &collections );
// for each collection, ensure there is a $_id_ index
for (list<string>::iterator i = collections.begin(); i != collections.end(); ++i) {
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index c94ec64140f..f59c62c4cf9 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -67,10 +67,8 @@
#include "mongo/db/repair_database.h"
#include "mongo/db/repl/is_master.h"
#include "mongo/db/repl/oplog.h"
-#include "mongo/db/storage/extent_manager.h"
-#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h"
-#include "mongo/db/storage/record.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/write_concern.h"
#include "mongo/s/d_logic.h"
#include "mongo/s/d_writeback.h"
@@ -170,7 +168,7 @@ namespace mongo {
const BSONObj& cmdObj) {
invariant(db);
std::list<std::string> collections;
- db->getCollectionNamespaces(&collections);
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces(&collections);
std::vector<BSONObj> allKilledIndexes;
for (std::list<std::string>::iterator it = collections.begin();
@@ -256,7 +254,7 @@ namespace mongo {
const BSONObj& cmdObj) {
invariant(db);
std::list<std::string> collections;
- db->getCollectionNamespaces(&collections);
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces(&collections);
std::vector<BSONObj> allKilledIndexes;
for (std::list<std::string>::iterator it = collections.begin();
diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp
index 018a0cc512b..426240390e4 100644
--- a/src/mongo/db/index_rebuilder.cpp
+++ b/src/mongo/db/index_rebuilder.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/auth/user_name.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/client.h"
#include "mongo/db/instance.h"
#include "mongo/db/pdfile.h"
@@ -64,7 +65,7 @@ namespace mongo {
dbName++) {
Client::ReadContext ctx(*dbName);
Database* db = ctx.ctx().db();
- db->getCollectionNamespaces(&collNames);
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces(&collNames);
}
checkNS(collNames);
}
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
index a8edffb2642..c5ad42daa13 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
@@ -54,10 +54,10 @@ namespace mongo {
const StringData& name,
const StringData& path,
bool directoryPerDB )
- : _name( name.toString() ),
+ : DatabaseCatalogEntry( name ),
_path( path.toString() ),
_extentManager( name, path, directoryPerDB ),
- _namespaceIndex( _path, _name ) {
+ _namespaceIndex( _path, name.toString() ) {
try {
_checkDuplicateUncasedNames();
@@ -74,15 +74,15 @@ namespace mongo {
_namespaceIndex.init( txn );
// upgrade freelist
- string oldFreeList = _name + ".$freelist";
- NamespaceDetails* details = _namespaceIndex.details( oldFreeList );
+ NamespaceString oldFreeList( name, "$freelist" );
+ NamespaceDetails* details = _namespaceIndex.details( oldFreeList.ns() );
if ( details ) {
if ( !details->firstExtent.isNull() ) {
_extentManager.freeExtents(txn,
details->firstExtent,
details->lastExtent);
}
- _namespaceIndex.kill_ns( txn, oldFreeList );
+ _namespaceIndex.kill_ns( txn, oldFreeList.ns() );
}
}
}
@@ -105,12 +105,16 @@ namespace mongo {
MMAP1DatabaseCatalogEntry::~MMAP1DatabaseCatalogEntry() {
}
+ void MMAP1DatabaseCatalogEntry::getCollectionNamespaces( std::list<std::string>* tofill ) const {
+ _namespaceIndex.getCollectionNamespaces( tofill );
+ }
+
void MMAP1DatabaseCatalogEntry::_checkDuplicateUncasedNames() const {
- string duplicate = Database::duplicateUncasedName(true, _name, _path );
+ string duplicate = Database::duplicateUncasedName(true, name(), _path );
if ( !duplicate.empty() ) {
stringstream ss;
ss << "db already exists with different case already have: [" << duplicate
- << "] trying to create [" << _name << "]";
+ << "] trying to create [" << name() << "]";
uasserted( DatabaseDifferCaseCode , ss.str() );
}
}
@@ -281,7 +285,7 @@ namespace mongo {
}
RecordStoreV1Base* MMAP1DatabaseCatalogEntry::_getIndexRecordStore( OperationContext* txn ) {
- NamespaceString nss( _name, "system.indexes" );
+ NamespaceString nss( name(), "system.indexes" );
RecordStoreV1Base* rs = _getRecordStore( txn, nss.ns() );
if ( rs != NULL )
return rs;
@@ -295,7 +299,7 @@ namespace mongo {
RecordStoreV1Base* MMAP1DatabaseCatalogEntry::_getNamespaceRecordStore( OperationContext* txn,
const StringData& whosAsking) {
- NamespaceString nss( _name, "system.namespaces" );
+ NamespaceString nss( name(), "system.namespaces" );
if ( nss == whosAsking )
return NULL;
RecordStoreV1Base* rs = _getRecordStore( txn, nss.ns() );
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
index d7a2b1981c8..89498d53e2c 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
@@ -32,6 +32,7 @@
#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h"
#include "mongo/db/structure/catalog/namespace_index.h"
@@ -46,7 +47,7 @@ namespace mongo {
class RecordStoreV1Base;
class OperationContext;
- class MMAP1DatabaseCatalogEntry {
+ class MMAP1DatabaseCatalogEntry : public DatabaseCatalogEntry {
public:
MMAP1DatabaseCatalogEntry( OperationContext* txn,
const StringData& name,
@@ -62,6 +63,8 @@ namespace mongo {
const CollectionOptions& options,
bool allocateDefaultSpace );
+ void getCollectionNamespaces( std::list<std::string>* tofill ) const;
+
/*
* ownership passes to caller
* will return NULL if ns does not exist
@@ -102,7 +105,6 @@ namespace mongo {
*/
void _checkDuplicateUncasedNames() const;
- std::string _name;
std::string _path;
MmapV1ExtentManager _extentManager;
diff --git a/src/mongo/tools/dump.cpp b/src/mongo/tools/dump.cpp
index 4bf6a644aba..a7672e0b722 100644
--- a/src/mongo/tools/dump.cpp
+++ b/src/mongo/tools/dump.cpp
@@ -38,6 +38,7 @@
#include "mongo/client/auth_helpers.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/auth/authorization_manager.h"
+#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/db.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/catalog/collection.h"
@@ -334,7 +335,7 @@ public:
Database * db = cx.ctx().db();
list<string> namespaces;
- db->getCollectionNamespaces( &namespaces );
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces( &namespaces );
boost::filesystem::path root = mongoDumpGlobalParams.outputDirectory;
root /= dbname;