Storage Engine API
mongo::MmapV1ExtentManager Class Reference

ExtentManager basics. More...

#include <mmap_v1_extent_manager.h>

Inheritance diagram for mongo::MmapV1ExtentManager:
mongo::ExtentManager

Detailed Description

ExtentManager basics.

  • one per database
  • responsible for managing <db>.# files
  • NOT responsible for .ns file
  • gives out extents
  • responsible for figuring out how to get a new extent
  • can use any method it wants to do so
  • this structure is NOT stored on disk
  • this class is thread safe, except as indicated below

Implementation:

  • ExtentManager holds a preallocated list of DataFile
  • files will not be removed from the EM, so _files access can be lock-free
  • extent size and loc are immutable
  • Any non-const public operations on an ExtentManager will acquire an MODE_X lock on its RESOURCE_MMAPv1_EXTENT_MANAGER resource from the lock-manager, which will extend life to during WriteUnitOfWorks that might need rollback. Private methods will only be called from public ones.

Classes

class  Factory
 
class  FilesArray
 Simple wrapper around an array object to allow append-only modification of the array, as well as concurrent read-accesses. More...
 

Public Member Functions

 MmapV1ExtentManager (StringData dbname, StringData path, bool directoryPerDB)
 
void close (OperationContext *opCtx)
 Must be called before destruction. More...
 
Status init (OperationContext *opCtx)
 opens all current files, not thread safe More...
 
int numFiles () const
 
long long fileSize () const
 
DiskLoc allocateExtent (OperationContext *opCtx, bool capped, int size, bool enforceQuota)
 
void freeExtents (OperationContext *opCtx, DiskLoc firstExt, DiskLoc lastExt)
 firstExt has to be == lastExt or a chain More...
 
void freeExtent (OperationContext *opCtx, DiskLoc extent)
 frees a single extent ignores all fields in the Extent except: magic, myLoc, length More...
 
void freeListStats (OperationContext *opCtx, int *numExtents, int64_t *totalFreeSizeBytes) const
 Retrieve statistics on the the free list managed by this ExtentManger. More...
 
MmapV1RecordHeaderrecordForV1 (const DiskLoc &loc) const
 
std::unique_ptr< RecordFetcherrecordNeedsFetch (const DiskLoc &loc) const
 The extent manager tracks accesses to DiskLocs. More...
 
ExtentextentForV1 (const DiskLoc &loc) const
 
DiskLoc extentLocForV1 (const DiskLoc &loc) const
 
ExtentgetExtent (const DiskLoc &loc, bool doSanityCheck=true) const
 
DataFileVersion getFileFormat (OperationContext *opCtx) const final
 Not thread safe, requires a database exclusive lock. More...
 
void setFileFormat (OperationContext *opCtx, DataFileVersion newVersion) final
 
const DataFilegetOpenFile (int n) const final
 
virtual int maxSize () const
 
virtual CacheHintcacheHint (const DiskLoc &extentLoc, const HintType &hint)
 Tell the system that for this extent, it will have this kind of disk access. More...
 
- Public Member Functions inherited from mongo::ExtentManager
 ExtentManager ()
 
virtual ~ExtentManager ()
 
virtual int minSize () const
 
virtual int followupSize (int recordLen, int lastExtentLen) const
 
virtual int initialSize (int recordLen) const
 get a suggested size for the first extent in a namespace More...
 
virtual int quantizeExtentSize (int size) const
 quantizes extent size to >= min + page boundary More...
 

Private Member Functions

 MONGO_DISALLOW_COPYING (MmapV1ExtentManager)
 
DiskLoc _allocFromFreeList (OperationContext *opCtx, int approxSize, bool capped)
 will return NULL if nothing suitable in free list More...
 
DiskLoc _createExtent (OperationContext *opCtx, int approxSize, bool enforceQuota)
 
DataFile_addAFile (OperationContext *opCtx, int sizeNeeded, bool preallocateNextFile)
 
MmapV1RecordHeader_recordForV1 (const DiskLoc &loc) const
 Shared record retrieval logic used by the public recordForV1() and likelyInPhysicalMem() above. More...
 
DiskLoc _getFreeListStart () const
 
DiskLoc _getFreeListEnd () const
 
void _setFreeListStart (OperationContext *opCtx, DiskLoc loc)
 
void _setFreeListEnd (OperationContext *opCtx, DiskLoc loc)
 
const DataFile_getOpenFile (int fileId) const
 
DataFile_getOpenFile (int fileId)
 
DiskLoc _createExtentInFile (OperationContext *opCtx, int fileNo, DataFile *f, int size, bool enforceQuota)
 
boost::filesystem::path _fileName (int n) const
 

Private Attributes

const std::string _dbname
 
const std::string _path
 
const bool _directoryPerDB
 
const ResourceId _rid
 
RecordAccessTracker_recordAccessTracker
 
FilesArray _files
 

Additional Inherited Members

- Public Types inherited from mongo::ExtentManager
enum  HintType { Sequential, Random }
 

Constructor & Destructor Documentation

◆ MmapV1ExtentManager()

mongo::MmapV1ExtentManager::MmapV1ExtentManager ( StringData  dbname,
StringData  path,
bool  directoryPerDB 
)
Parameters
freeListDetailsthis is a reference into the .ns file while a bit odd, this is not a layer violation as extents are a peer to the .ns file, without any layering

Member Function Documentation

◆ _addAFile()

DataFile * mongo::MmapV1ExtentManager::_addAFile ( OperationContext *  opCtx,
int  sizeNeeded,
bool  preallocateNextFile 
)
private

◆ _allocFromFreeList()

DiskLoc mongo::MmapV1ExtentManager::_allocFromFreeList ( OperationContext *  opCtx,
int  approxSize,
bool  capped 
)
private

will return NULL if nothing suitable in free list

◆ _createExtent()

DiskLoc mongo::MmapV1ExtentManager::_createExtent ( OperationContext *  opCtx,
int  approxSize,
bool  enforceQuota 
)
private

◆ _createExtentInFile()

DiskLoc mongo::MmapV1ExtentManager::_createExtentInFile ( OperationContext *  opCtx,
int  fileNo,
DataFile f,
int  size,
bool  enforceQuota 
)
private

◆ _fileName()

boost::filesystem::path mongo::MmapV1ExtentManager::_fileName ( int  n) const
private

◆ _getFreeListEnd()

DiskLoc mongo::MmapV1ExtentManager::_getFreeListEnd ( ) const
private

◆ _getFreeListStart()

DiskLoc mongo::MmapV1ExtentManager::_getFreeListStart ( ) const
private

◆ _getOpenFile() [1/2]

const DataFile * mongo::MmapV1ExtentManager::_getOpenFile ( int  fileId) const
private

◆ _getOpenFile() [2/2]

DataFile * mongo::MmapV1ExtentManager::_getOpenFile ( int  fileId)
private

◆ _recordForV1()

MmapV1RecordHeader * mongo::MmapV1ExtentManager::_recordForV1 ( const DiskLoc loc) const
private

Shared record retrieval logic used by the public recordForV1() and likelyInPhysicalMem() above.

◆ _setFreeListEnd()

void mongo::MmapV1ExtentManager::_setFreeListEnd ( OperationContext *  opCtx,
DiskLoc  loc 
)
private

◆ _setFreeListStart()

void mongo::MmapV1ExtentManager::_setFreeListStart ( OperationContext *  opCtx,
DiskLoc  loc 
)
private

◆ allocateExtent()

DiskLoc mongo::MmapV1ExtentManager::allocateExtent ( OperationContext *  opCtx,
bool  capped,
int  size,
bool  enforceQuota 
)
virtual

Implements mongo::ExtentManager.

◆ cacheHint()

ExtentManager::CacheHint * mongo::MmapV1ExtentManager::cacheHint ( const DiskLoc extentLoc,
const HintType hint 
)
virtual

Tell the system that for this extent, it will have this kind of disk access.

Caller takes owernship of CacheHint

Implements mongo::ExtentManager.

◆ close()

void mongo::MmapV1ExtentManager::close ( OperationContext *  opCtx)
inlinevirtual

Must be called before destruction.

Implements mongo::ExtentManager.

◆ extentForV1()

Extent * mongo::MmapV1ExtentManager::extentForV1 ( const DiskLoc loc) const
virtual
Parameters
loc- has to be for a specific MmapV1RecordHeader (not an Extent) Note(erh) see comment on recordFor

Implements mongo::ExtentManager.

◆ extentLocForV1()

DiskLoc mongo::MmapV1ExtentManager::extentLocForV1 ( const DiskLoc loc) const
virtual
Parameters
loc- has to be for a specific MmapV1RecordHeader (not an Extent) Note(erh) see comment on recordFor

Implements mongo::ExtentManager.

◆ fileSize()

long long mongo::MmapV1ExtentManager::fileSize ( ) const
virtual

Implements mongo::ExtentManager.

◆ freeExtent()

void mongo::MmapV1ExtentManager::freeExtent ( OperationContext *  opCtx,
DiskLoc  extent 
)
virtual

frees a single extent ignores all fields in the Extent except: magic, myLoc, length

Implements mongo::ExtentManager.

◆ freeExtents()

void mongo::MmapV1ExtentManager::freeExtents ( OperationContext *  opCtx,
DiskLoc  firstExt,
DiskLoc  lastExt 
)
virtual

firstExt has to be == lastExt or a chain

Implements mongo::ExtentManager.

◆ freeListStats()

void mongo::MmapV1ExtentManager::freeListStats ( OperationContext *  opCtx,
int *  numExtents,
int64_t *  totalFreeSizeBytes 
) const
virtual

Retrieve statistics on the the free list managed by this ExtentManger.

Parameters
numExtents- non-null pointer to an int that will receive the number of extents
totalFreeSizeBytes- non-null pointer to an int64_t receiving the total free space in the free list.

Implements mongo::ExtentManager.

◆ getExtent()

Extent * mongo::MmapV1ExtentManager::getExtent ( const DiskLoc loc,
bool  doSanityCheck = true 
) const
virtual
Parameters
loc- has to be for a specific Extent

Implements mongo::ExtentManager.

◆ getFileFormat()

DataFileVersion mongo::MmapV1ExtentManager::getFileFormat ( OperationContext *  opCtx) const
finalvirtual

Not thread safe, requires a database exclusive lock.

Implements mongo::ExtentManager.

◆ getOpenFile()

const DataFile* mongo::MmapV1ExtentManager::getOpenFile ( int  n) const
inlinefinalvirtual

Implements mongo::ExtentManager.

◆ init()

Status mongo::MmapV1ExtentManager::init ( OperationContext *  opCtx)
virtual

opens all current files, not thread safe

Implements mongo::ExtentManager.

◆ maxSize()

int mongo::MmapV1ExtentManager::maxSize ( ) const
virtual
Returns
maximum size of an Extent

Implements mongo::ExtentManager.

◆ MONGO_DISALLOW_COPYING()

mongo::MmapV1ExtentManager::MONGO_DISALLOW_COPYING ( MmapV1ExtentManager  )
private

◆ numFiles()

int mongo::MmapV1ExtentManager::numFiles ( ) const
virtual

Implements mongo::ExtentManager.

◆ recordForV1()

MmapV1RecordHeader * mongo::MmapV1ExtentManager::recordForV1 ( const DiskLoc loc) const
virtual
Parameters
loc- has to be for a specific MmapV1RecordHeader Note(erh): this sadly cannot be removed. A MmapV1RecordHeader DiskLoc has an offset from a file, while a RecordStore really wants an offset from an extent. This intrinsically links an original record store to the original extent manager.

Implements mongo::ExtentManager.

◆ recordNeedsFetch()

std::unique_ptr< RecordFetcher > mongo::MmapV1ExtentManager::recordNeedsFetch ( const DiskLoc loc) const
virtual

The extent manager tracks accesses to DiskLocs.

This returns non-NULL if the DiskLoc has been recently accessed, and therefore has likely been paged into physical memory. Returns nullptr if the DiskLoc is Null.

Implements mongo::ExtentManager.

◆ setFileFormat()

void mongo::MmapV1ExtentManager::setFileFormat ( OperationContext *  opCtx,
DataFileVersion  newVersion 
)
finalvirtual

Implements mongo::ExtentManager.

Member Data Documentation

◆ _dbname

const std::string mongo::MmapV1ExtentManager::_dbname
private

◆ _directoryPerDB

const bool mongo::MmapV1ExtentManager::_directoryPerDB
private

◆ _files

FilesArray mongo::MmapV1ExtentManager::_files
private

◆ _path

const std::string mongo::MmapV1ExtentManager::_path
private

◆ _recordAccessTracker

RecordAccessTracker* mongo::MmapV1ExtentManager::_recordAccessTracker
private

◆ _rid

const ResourceId mongo::MmapV1ExtentManager::_rid
private

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