From 4778a2c4add21e0696877c884ba4fd88c52cedf6 Mon Sep 17 00:00:00 2001 From: Dwight Date: Wed, 31 Mar 2010 15:08:40 -0400 Subject: [PATCH] mmf abstraction 2 --- db/database.h | 4 ++-- db/db.cpp | 4 ++-- db/pdfile.cpp | 5 +++-- db/pdfile.h | 16 ++++++++-------- dbtests/namespacetests.cpp | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/db/database.h b/db/database.h index 868af0bab26..f6160e9a90e 100644 --- a/db/database.h +++ b/db/database.h @@ -137,8 +137,8 @@ namespace mongo { int minSize = 0; if ( n != 0 && files[ n - 1 ] ) minSize = files[ n - 1 ]->getHeader()->fileLength; - if ( sizeNeeded + MDFHeader::headerSize() > minSize ) - minSize = sizeNeeded + MDFHeader::headerSize(); + if ( sizeNeeded + DataFileHeader::headerSize() > minSize ) + minSize = sizeNeeded + DataFileHeader::headerSize(); try { p->open( fullNameString.c_str(), minSize, preallocateOnly ); } diff --git a/db/db.cpp b/db/db.cpp index 218dd608d5f..981fdf7433b 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -316,7 +316,7 @@ namespace mongo { bool shouldRepairDatabases = 0; bool forceRepair = 0; - bool doDBUpgrade( const string& dbName , string errmsg , MDFHeader * h ){ + bool doDBUpgrade( const string& dbName , string errmsg , DataFileHeader * h ){ static DBDirectClient db; if ( h->version == 4 && h->versionMinor == 4 ){ @@ -361,7 +361,7 @@ namespace mongo { log(1) << "\t" << dbName << endl; Client::Context ctx( dbName ); MongoDataFile *p = cc().database()->getFile( 0 ); - MDFHeader *h = p->getHeader(); + DataFileHeader *h = p->getHeader(); if ( !h->currentVersion() || forceRepair ) { log() << "****" << endl; log() << "****" << endl; diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 51f179fc902..897b748e191 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -199,7 +199,7 @@ namespace mongo { } } else { while ( size > 0 ) { - int max = MongoDataFile::maxSize() - MDFHeader::headerSize(); + int max = MongoDataFile::maxSize() - DataFileHeader::headerSize(); int desiredExtentSize = (int) (size > max ? max : size); Extent *e = database->allocExtent( ns, desiredExtentSize, newCapped ); size -= e->length; @@ -325,7 +325,8 @@ namespace mongo { return; } - header = (MDFHeader *) mmf.map(filename, size); + _p = mmf.map(filename, size); + header = (DataFileHeader *) _p.at(0); if( sizeof(char *) == 4 ) uassert( 10084 , "can't map file memory - mongo requires 64 bit build for larger datasets", header); else diff --git a/db/pdfile.h b/db/pdfile.h index 85dc191f167..c5d91452aa2 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -34,7 +34,7 @@ namespace mongo { - class MDFHeader; + class DataFileHeader; class Extent; class Record; class Cursor; @@ -56,7 +56,6 @@ namespace mongo { /*---------------------------------------------------------------------*/ - class MDFHeader; class MongoDataFile { friend class DataFileMgr; friend class BasicCursor; @@ -70,7 +69,7 @@ namespace mongo { */ Extent* createExtent(const char *ns, int approxSize, bool capped = false, int loops = 0); - MDFHeader *getHeader() { + DataFileHeader *getHeader() { return header; } @@ -84,8 +83,10 @@ namespace mongo { Extent* _getExtent(DiskLoc loc); Record* recordAt(DiskLoc dl); - MemoryMappedFile mmf; - MDFHeader *header; + typedef MemoryMappedFile MMF; + MMF mmf; + MMF::Pointer _p; + DataFileHeader *header; int fileNo; }; @@ -254,8 +255,7 @@ namespace mongo { ---------------------- */ - /* data file header */ - class MDFHeader { + class DataFileHeader { public: int version; int versionMinor; @@ -267,7 +267,7 @@ namespace mongo { char data[4]; static int headerSize() { - return sizeof(MDFHeader) - 4; + return sizeof(DataFileHeader) - 4; } bool currentVersion() const { diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp index 205c5d24223..0a0e52b6e0c 100644 --- a/dbtests/namespacetests.cpp +++ b/dbtests/namespacetests.cpp @@ -741,7 +741,7 @@ namespace NamespaceTests { // private: // virtual string spec() const { // // NOTE 256 added to size in _userCreateNS() - // long long big = MongoDataFile::maxSize() - MDFHeader::headerSize(); + // long long big = MongoDataFile::maxSize() - DataFileHeader::headerSize(); // stringstream ss; // ss << "{\"capped\":true,\"size\":" << big << "}"; // return ss.str();