Storage Engine API
mongo::MemoryMappedFile Class Reference

#include <mmap.h>

Inheritance diagram for mongo::MemoryMappedFile:
mongo::MongoFile mongo::DurableMappedFile

Public Member Functions

 MemoryMappedFile (OperationContext *opCtx, OptionSet options=NONE)
 
virtual ~MemoryMappedFile ()
 
virtual void close (OperationContext *opCtx)
 Callers must be holding a LockMongoFilesExclusive. More...
 
voidmap (OperationContext *opCtx, const char *filename)
 uasserts if file doesn't exist. More...
 
voidcreate (OperationContext *opCtx, const std::string &filename, unsigned long long len, bool zero)
 uasserts if file exists. More...
 
void flush (bool sync)
 
virtual bool isClosed ()
 Returns true iff the file is closed. More...
 
virtual FlushableprepareFlush ()
 returns a thread safe object that you can call flush on Flushable has to fail nicely if the underlying object gets killed More...
 
long shortLength () const
 
unsigned long long length () const
 
HANDLE getFd () const
 
voidcreatePrivateMap ()
 Creates a new view with the specified properties. More...
 
virtual uint64_t getUniqueId () const
 
- Public Member Functions inherited from mongo::MongoFile
 MongoFile (OptionSet options)
 
virtual ~MongoFile ()=default
 
virtual bool isDurableMappedFile ()
 
std::string filename () const
 
void setFilename (OperationContext *opCtx, const std::string &fn)
 

Static Public Member Functions

static int totalMappedLengthInMB ()
 
- Static Public Member Functions inherited from mongo::MongoFile
template<class F >
static void forEach (OperationContext *opCtx, F fun)
 p is called from within a mutex that MongoFile uses. More...
 
static std::set< MongoFile * > & getAllFiles ()
 note: you need to be in mmmutex when using this. More...
 
static int flushAll (OperationContext *opCtx, bool sync)
 
static void closeAllFiles (OperationContext *opCtx, std::stringstream &message)
 

Protected Member Functions

virtual voidviewForFlushing ()
 
voidmap (OperationContext *opCtx, const char *filename, unsigned long long &length)
 Creates with length if DNE, otherwise validates input length. More...
 
voidremapPrivateView (OperationContext *opCtx, void *oldPrivateAddr)
 Close the current private view and open a new replacement. More...
 
- Protected Member Functions inherited from mongo::MongoFile
void created (OperationContext *opCtx)
 
void destroyed (OperationContext *opCtx)
 Implementations may assume this is called from within LockMongoFilesExclusive. More...
 
bool isOptionSet (Options option) const
 

Static Private Member Functions

static void updateLength (const char *filename, unsigned long long &length)
 

Private Attributes

HANDLE fd = 0
 
HANDLE maphandle = 0
 
std::vector< void * > views
 
unsigned long long len = 0u
 
const uint64_t _uniqueId
 

Static Private Attributes

static AtomicUInt64 totalMappedLength
 

Additional Inherited Members

- Public Types inherited from mongo::MongoFile
enum  Options { NONE = 0, SEQUENTIAL = 1 << 0, READONLY = 1 << 1 }
 
using OptionSet = std::underlying_type< Options >::type
 

Constructor & Destructor Documentation

◆ MemoryMappedFile()

mongo::MemoryMappedFile::MemoryMappedFile ( OperationContext *  opCtx,
OptionSet  options = NONE 
)

◆ ~MemoryMappedFile()

mongo::MemoryMappedFile::~MemoryMappedFile ( )
virtual

Member Function Documentation

◆ close()

void mongo::MemoryMappedFile::close ( OperationContext *  opCtx)
virtual

Callers must be holding a LockMongoFilesExclusive.

Implements mongo::MongoFile.

Reimplemented in mongo::DurableMappedFile.

◆ create()

void * mongo::MemoryMappedFile::create ( OperationContext *  opCtx,
const std::string &  filename,
unsigned long long  len,
bool  zero 
)

uasserts if file exists.

fasserts on mmap error.

Parameters
zerofill file with zeros when true

◆ createPrivateMap()

void * mongo::MemoryMappedFile::createPrivateMap ( )

Creates a new view with the specified properties.

Automatically cleaned up upon close/destruction of the MemoryMappedFile object. Returns nullptr on mmap error.

◆ flush()

void mongo::MemoryMappedFile::flush ( bool  sync)
virtual

Implements mongo::MongoFile.

◆ getFd()

HANDLE mongo::MemoryMappedFile::getFd ( ) const
inline

◆ getUniqueId()

virtual uint64_t mongo::MemoryMappedFile::getUniqueId ( ) const
inlinevirtual

Implements mongo::MongoFile.

◆ isClosed()

bool mongo::MemoryMappedFile::isClosed ( )
virtual

Returns true iff the file is closed.

Implements mongo::MongoFile.

◆ length()

unsigned long long mongo::MemoryMappedFile::length ( ) const
inlinevirtual

Implements mongo::MongoFile.

◆ map() [1/2]

void * mongo::MemoryMappedFile::map ( OperationContext *  opCtx,
const char *  filename 
)

uasserts if file doesn't exist.

fasserts on mmap error.

◆ map() [2/2]

void * mongo::MemoryMappedFile::map ( OperationContext *  opCtx,
const char *  filename,
unsigned long long &  length 
)
protected

Creates with length if DNE, otherwise validates input length.

Returns nullptr on mmap error.

◆ prepareFlush()

MemoryMappedFile::Flushable * mongo::MemoryMappedFile::prepareFlush ( )
virtual

returns a thread safe object that you can call flush on Flushable has to fail nicely if the underlying object gets killed

Implements mongo::MongoFile.

◆ remapPrivateView()

void * mongo::MemoryMappedFile::remapPrivateView ( OperationContext *  opCtx,
void oldPrivateAddr 
)
protected

Close the current private view and open a new replacement.

Returns nullptr on mmap error.

◆ shortLength()

long mongo::MemoryMappedFile::shortLength ( ) const
inline

◆ totalMappedLengthInMB()

static int mongo::MemoryMappedFile::totalMappedLengthInMB ( )
inlinestatic

◆ updateLength()

void mongo::MemoryMappedFile::updateLength ( const char *  filename,
unsigned long long &  length 
)
staticprivate

◆ viewForFlushing()

virtual void* mongo::MemoryMappedFile::viewForFlushing ( )
inlineprotectedvirtual

Reimplemented in mongo::DurableMappedFile.

Member Data Documentation

◆ _uniqueId

const uint64_t mongo::MemoryMappedFile::_uniqueId
private

◆ fd

HANDLE mongo::MemoryMappedFile::fd = 0
private

◆ len

unsigned long long mongo::MemoryMappedFile::len = 0u
private

◆ maphandle

HANDLE mongo::MemoryMappedFile::maphandle = 0
private

◆ totalMappedLength

AtomicUInt64 mongo::MemoryMappedFile::totalMappedLength
staticprivate

◆ views

std::vector<void*> mongo::MemoryMappedFile::views
private

The documentation for this class was generated from the following files: