Storage Engine API
mongo::dur Namespace Reference

Classes

class  Already
 Bitmap to remember things we have already marked for journaling. More...
 
class  BufferGuard
 Used inside the journal writer thread to ensure that used buffers are cleaned up properly. More...
 
class  BufReaderUnitTest
 
struct  BufReaderY
 
class  CommitJob
 Tracks all write operations on the private view so they can be journaled. More...
 
class  DropDbOp
 record drop of a database More...
 
class  DurableInterface
 
class  DurOp
 DurOp - Operations we journal that aren't just basic writes. More...
 
class  FileCreatedOp
 indicates creation of a new file More...
 
struct  JDbContext
 declares "the next entry(s) are for this database / file path prefix" More...
 
struct  JEntry
 an individual write operation within a group commit section. More...
 
struct  JHeader
 beginning header for a journal/j._<n> file there is nothing important int this header at this time. More...
 
class  Journal
 the writeahead journal for durability More...
 
class  JournalSectionIterator
 read through the memory mapped data of a journal file (journal/j._<n> file) throws More...
 
class  JournalWriter
 Manages the thread and queues used for writing the journal to disk and notify parties with are waiting on the write concern. More...
 
struct  JSectFooter
 group commit section footer. More...
 
struct  JSectHeader
 "Section" header. More...
 
struct  LSNFile
 "last sequence number" More...
 
struct  ParsedJournalEntry
 
class  RecoveryJob
 call go() to execute a recovery from existing journal files. More...
 
struct  Stats
 journaling stats. More...
 
struct  WriteIntent
 Declaration of an intent to write to a region of a memory mapped view. More...
 

Typedefs

typedef std::vector< std::shared_ptr< DurOp > > DurOpsVector
 
typedef std::vector< WriteIntentWriteIntentsVector
 

Functions

void PREPLOGBUFFER (JSectHeader &outHeader, AlignedBuilder &outBuffer, ClockSource *cs, int64_t serverStartMs)
 
boost::filesystem::path getJournalDir ()
 
void preallocateFiles ()
 
static void durThread (ClockSource *cs, int64_t serverStartMs)
 The main durability thread loop. More...
 
static void remapPrivateView (OperationContext *opCtx, double fraction)
 Remaps the private view from the shared view so that it does not consume too much copy-on-write/swap space. More...
 
void startup (ClockSource *cs, int64_t serverStartMs)
 Invoked at server startup. More...
 
void setJournalListener (JournalListener *jl)
 
JournalListenergetJournalListener ()
 
MONGO_INITIALIZER() InitializeJournalingParams (InitializerContext *context)
 
 MONGO_STATIC_ASSERT (sizeof(Checksum)==16)
 
 MONGO_STATIC_ASSERT (sizeof(JHeader)==8192)
 
 MONGO_STATIC_ASSERT (sizeof(JSectHeader)==20)
 
 MONGO_STATIC_ASSERT (sizeof(JSectFooter)==32)
 
 MONGO_STATIC_ASSERT (sizeof(JEntry)==12)
 
 MONGO_STATIC_ASSERT (sizeof(LSNFile)==88)
 
void removeOldJournalFile (boost::filesystem::path p)
 
boost::filesystem::path lsnPath ()
 
void journalingFailure (const char *msg)
 this should be called when something really bad happens so that we can flag appropriately More...
 
bool haveJournalFiles (bool anyFiles)
 never throws More...
 
void removeJournalFiles ()
 throws More...
 
void journalCleanup (bool log=false)
 at termination after db files closed & fsynced also after recovery closes and removes journal files More...
 
bool _preallocateIsFaster ()
 
bool preallocateIsFaster ()
 
void preallocateFile (boost::filesystem::path p, unsigned long long len)
 
boost::filesystem::path preallocPath (int n)
 
void _preallocateFiles ()
 
void checkFreeSpace ()
 
boost::filesystem::path findPrealloced ()
 
void journalMakeDir (ClockSource *cs, int64_t serverStartMs)
 assure journal/ dir exists. More...
 
unsigned long long journalReadLSN ()
 called during recovery (the error message text below assumes that) More...
 
uint64_t generateNextSeqNumber (ClockSource *cs, int64_t serverStartMs)
 Generates the next sequence number for use in the journal, guaranteed to be greater than all prior sequence numbers. More...
 
void setLastSeqNumberWrittenToSharedView (uint64_t seqNumber)
 Informs the journaling system that all writes on or before the passed in sequence number have been written to the data files' shared mmap view. More...
 
void notifyPreDataFileFlush ()
 Call these before (pre) and after (post) the datafiles are flushed to disk by the DataFileSync thread. More...
 
void notifyPostDataFileFlush ()
 
void WRITETOJOURNAL (const JSectHeader &h, const AlignedBuilder &uncompressed)
 write (append) the buffer we have built to the journal and fsync it. More...
 
static DurableMappedFilefindMMF_inlock (void *ptr, size_t &ofs)
 
static void prepBasicWrite_inlock (AlignedBuilder &bb, const WriteIntent *i, RelativePath &lastDbPath)
 put the basic write operation into the buffer (bb) to be journaled More...
 
static void prepBasicWrites (AlignedBuilder &bb, const std::vector< WriteIntent > &intents)
 basic write ops / write intents. More...
 
static void _PREPLOGBUFFER (JSectHeader &h, AlignedBuilder &bb, ClockSource *cs, int64_t serverStartMs)
 we will build an output buffer ourself and then use O_DIRECT we could be in read lock for this caller handles locking More...
 
static void getFiles (boost::filesystem::path dir, vector< boost::filesystem::path > &files)
 Get journal filenames, in order. More...
 
static string fileName (const char *dbName, int fileNo)
 
void _recover (OperationContext *opCtx)
 
void replayJournalFilesAtStartup ()
 recover from a crash called during startup throws on error More...
 

Variables

Stats stats
 
CommitJob commitJob
 
DurableInterface *DurableInterface::_implnonDurableImpl
 
const unsigned UncommittedBytesLimit = (sizeof(void*) == 4) ? 50 * 1024 * 1024 : 512 * 1024 * 1024
 
unsigned long long DataLimitPerJournalFile
 
bool usingPreallocate = false
 
Journal j
 
const unsigned long long LsnShutdownSentinel = ~((unsigned long long)0)
 
bool okToCleanUp = false
 at clean shutdown More...
 
const int NUM_PREALLOC_FILES = 3
 
const long long ExtraKeepTimeMs = 10000
 
const unsigned Alignment = 8192
 
const RelativePath local = RelativePath::fromRelativePath("local")
 
mongo::dur::BufReaderUnitTest brunittest
 

Typedef Documentation

◆ DurOpsVector

typedef std::vector<std::shared_ptr<DurOp> > mongo::dur::DurOpsVector

◆ WriteIntentsVector

Function Documentation

◆ _preallocateFiles()

void mongo::dur::_preallocateFiles ( )

◆ _preallocateIsFaster()

bool mongo::dur::_preallocateIsFaster ( )

◆ _PREPLOGBUFFER()

static void mongo::dur::_PREPLOGBUFFER ( JSectHeader h,
AlignedBuilder bb,
ClockSource *  cs,
int64_t  serverStartMs 
)
static

we will build an output buffer ourself and then use O_DIRECT we could be in read lock for this caller handles locking

Returns
partially populated sectheader and _ab set

◆ _recover()

void mongo::dur::_recover ( OperationContext *  opCtx)

◆ checkFreeSpace()

void mongo::dur::checkFreeSpace ( )

◆ durThread()

static void mongo::dur::durThread ( ClockSource *  cs,
int64_t  serverStartMs 
)
static

The main durability thread loop.

There is a single instance of this function running.

◆ fileName()

static string mongo::dur::fileName ( const char *  dbName,
int  fileNo 
)
static

◆ findMMF_inlock()

static DurableMappedFile* mongo::dur::findMMF_inlock ( void ptr,
size_t &  ofs 
)
static

◆ findPrealloced()

boost::filesystem::path mongo::dur::findPrealloced ( )

◆ generateNextSeqNumber()

uint64_t mongo::dur::generateNextSeqNumber ( ClockSource *  cs,
int64_t  serverStartMs 
)

Generates the next sequence number for use in the journal, guaranteed to be greater than all prior sequence numbers.

◆ getFiles()

static void mongo::dur::getFiles ( boost::filesystem::path  dir,
vector< boost::filesystem::path > &  files 
)
static

Get journal filenames, in order.

Throws if unexpected content found.

◆ getJournalDir()

boost::filesystem::path mongo::dur::getJournalDir ( )

◆ getJournalListener()

JournalListener * mongo::dur::getJournalListener ( )

◆ haveJournalFiles()

bool mongo::dur::haveJournalFiles ( bool  anyFiles)

never throws

never throws.

Parameters
anyFilesby default we only look at j._* files. If anyFiles is true, return true if there are any files in the journal directory. checkForUncleanShutdown() uses this to make sure that the journal directory is mounted.
Returns
true if journal dir is not empty
Parameters
anyFilesby default we only look at j._* files. If anyFiles is true, return true if there are any files in the journal directory. checkForUncleanShutdown() uses this to make sure that the journal directory is mounted.
Returns
true if there are any journal files in the journal dir.

◆ InitializeJournalingParams()

MONGO_INITIALIZER() mongo::dur::InitializeJournalingParams ( InitializerContext *  context)

◆ journalCleanup()

void mongo::dur::journalCleanup ( bool  log = false)

at termination after db files closed & fsynced also after recovery closes and removes journal files

Parameters
logreport in log that we are cleaning up if we actually do any work

◆ journalingFailure()

void mongo::dur::journalingFailure ( const char *  msg)

this should be called when something really bad happens so that we can flag appropriately

flag that something has gone wrong during writing to the journal (not for recovery mode)

todo: (1) don't log too much (2) make an indicator in the journal dir that something bad happened. (2b) refuse to do a recovery startup if that is there without manual override.

◆ journalMakeDir()

void mongo::dur::journalMakeDir ( ClockSource *  cs,
int64_t  serverStartMs 
)

assure journal/ dir exists.

throws. call during startup.

throws

◆ journalReadLSN()

unsigned long long mongo::dur::journalReadLSN ( )

called during recovery (the error message text below assumes that)

read lsn from disk from the last run before doing recovery

◆ lsnPath()

boost::filesystem::path mongo::dur::lsnPath ( )

◆ MONGO_STATIC_ASSERT() [1/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(Checksum)  = =16)

◆ MONGO_STATIC_ASSERT() [2/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(JHeader = =8192)

◆ MONGO_STATIC_ASSERT() [3/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(JSectHeader = =20)

◆ MONGO_STATIC_ASSERT() [4/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(JSectFooter = =32)

◆ MONGO_STATIC_ASSERT() [5/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(JEntry = =12)

◆ MONGO_STATIC_ASSERT() [6/6]

mongo::dur::MONGO_STATIC_ASSERT ( sizeof(LSNFile = =88)

◆ notifyPostDataFileFlush()

void mongo::dur::notifyPostDataFileFlush ( )

◆ notifyPreDataFileFlush()

void mongo::dur::notifyPreDataFileFlush ( )

Call these before (pre) and after (post) the datafiles are flushed to disk by the DataFileSync thread.

These should not be called for any other flushes.

◆ preallocateFile()

void mongo::dur::preallocateFile ( boost::filesystem::path  p,
unsigned long long  len 
)

◆ preallocateFiles()

void mongo::dur::preallocateFiles ( )

◆ preallocateIsFaster()

bool mongo::dur::preallocateIsFaster ( )

◆ preallocPath()

boost::filesystem::path mongo::dur::preallocPath ( int  n)
inline

◆ prepBasicWrite_inlock()

static void mongo::dur::prepBasicWrite_inlock ( AlignedBuilder bb,
const WriteIntent i,
RelativePath lastDbPath 
)
static

put the basic write operation into the buffer (bb) to be journaled

◆ prepBasicWrites()

static void mongo::dur::prepBasicWrites ( AlignedBuilder bb,
const std::vector< WriteIntent > &  intents 
)
static

basic write ops / write intents.

note there is no particular order to these : if we have two writes to the same location during the group commit interval, it is likely (although not assured) that it is journaled here once.

◆ PREPLOGBUFFER()

void mongo::dur::PREPLOGBUFFER ( JSectHeader outHeader,
AlignedBuilder outBuffer,
ClockSource *  cs,
int64_t  serverStartMs 
)

◆ remapPrivateView()

static void mongo::dur::remapPrivateView ( OperationContext *  opCtx,
double  fraction 
)
static

Remaps the private view from the shared view so that it does not consume too much copy-on-write/swap space.

Must only be called after the in-memory journal has been flushed to disk and applied on top of the shared view.

Parameters
fractionValue between (0, 1] indicating what fraction of the memory to remap. Remapping too much or too frequently incurs copy-on-write page fault cost.

◆ removeJournalFiles()

void mongo::dur::removeJournalFiles ( )

throws

◆ removeOldJournalFile()

void mongo::dur::removeOldJournalFile ( boost::filesystem::path  p)

◆ replayJournalFilesAtStartup()

void mongo::dur::replayJournalFilesAtStartup ( )

recover from a crash called during startup throws on error

◆ setJournalListener()

void mongo::dur::setJournalListener ( JournalListener jl)

◆ setLastSeqNumberWrittenToSharedView()

void mongo::dur::setLastSeqNumberWrittenToSharedView ( uint64_t  seqNumber)

Informs the journaling system that all writes on or before the passed in sequence number have been written to the data files' shared mmap view.

◆ startup()

void mongo::dur::startup ( ClockSource *  cs,
int64_t  serverStartMs 
)

Invoked at server startup.

Called during startup to startup the durability module.

Recovers the database by replaying journal files and then starts the durability thread.

Does nothing if storageGlobalParams.dur is false

◆ WRITETOJOURNAL()

void mongo::dur::WRITETOJOURNAL ( const JSectHeader h,
const AlignedBuilder uncompressed 
)

write (append) the buffer we have built to the journal and fsync it.

Writes the specified uncompressed buffer to the journal.

outside of dbMutex lock as this could be slow.

Parameters
uncompressed- a buffer that will be written to the journal after compression will not return until on disk

Variable Documentation

◆ Alignment

const unsigned mongo::dur::Alignment = 8192

◆ brunittest

mongo::dur::BufReaderUnitTest mongo::dur::brunittest

◆ commitJob

CommitJob mongo::dur::commitJob

◆ DataLimitPerJournalFile

unsigned long long mongo::dur::DataLimitPerJournalFile
Initial value:
=
(sizeof(void*) == 4) ? 256 * 1024 * 1024 : 1 * 1024 * 1024 * 1024

◆ ExtraKeepTimeMs

const long long mongo::dur::ExtraKeepTimeMs = 10000

◆ j

Journal mongo::dur::j

◆ local

const RelativePath mongo::dur::local = RelativePath::fromRelativePath("local")

◆ LsnShutdownSentinel

const unsigned long long mongo::dur::LsnShutdownSentinel = ~((unsigned long long)0)

◆ nonDurableImpl

DurableInterface* DurableInterface::_impl& mongo::dur::nonDurableImpl

◆ NUM_PREALLOC_FILES

const int mongo::dur::NUM_PREALLOC_FILES = 3

◆ okToCleanUp

bool mongo::dur::okToCleanUp = false

at clean shutdown

true if ok to cleanup journal files at termination.

otherwise, files journal will be retained.

◆ stats

Stats mongo::dur::stats

◆ UncommittedBytesLimit

const unsigned mongo::dur::UncommittedBytesLimit = (sizeof(void*) == 4) ? 50 * 1024 * 1024 : 512 * 1024 * 1024

◆ usingPreallocate

bool mongo::dur::usingPreallocate = false