Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the initialization steps of MongoDB and what is its cache refresh mechanism?

Shulou Source: shulou.com Published: 2022-05-31 17:28:44 12月04日 Update

What are the initialization steps of MongoDB and what is its cache refresh mechanism? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

When you run out of memory and start brushing dirty pages on disk, performance fluctuates so much that even if you adjust the syncdelay, it doesn't improve much. There was also an inexplicable situation in the test: MongoDB intermittently freed the cache of the file system. What are the initialization steps of MongoDB? what is the refresh mechanism of MongoDB data cache?

What are the initialization steps of MongoDB

Intmain (intargc,char*argv [], char*envp [])

{

...

Module::configAll (params)

DataFileSync.go ()

...

InitAndListen (cmdLine.port,appsrvPath)

...

}

Obviously, dataFileSync is the class we are interested in. The dataFileSync class is derived from the BackgroundJob class, and the main function of BackgroundJob is to generate a background thread and assign tasks. Data refresh is an ongoing background task. You can find the relevant code for brushing data in dataFileSync.run ():

What is the refresh mechanism of MongoDB data cache?

Voidrun ()

{

...

Date_tstart=jsTime ()

IntnumFiles=MemoryMappedFile::flushAll (true)

Time_flushing= (int) (jsTime ()-start)

GlobalFlushCounters.flushed (time_flushing)

...

}

Judging from this code, MongoDB will refresh all dirty data synchronously within the period set by syncdelay. Take another look at how flushAll refreshes all the data:

IntMongoFile::flushAll (boolsync)

{

...

Setseen

While (true) {

Auto_ptrf

{

Rwlocklk (mmmutex,false)

For (set::iteratori=mmfiles.begin (); iTunes. End (); iTunes +) {

MongoFile*mmf=*i

If (! mmf)

Continue

If (seen.count (mmf))

Continue

F.reset (mmf- > prepareFlush ())

Seen.insert (mmf)

Break

}

}

If (! f.get ()

Break

F-> flush ()

}

Returnseen.size ()

}

What the above code does is simply flush () all the objects referenced by the MongoFile pointer in mmfiles. However, before executing the flush () function, you need to execute prepareFlush () to ensure that the object can execute the flush () function. Here is the last code that actually performs the refresh operation:

VoidMemoryMappedFile::flush (boolsync)

{

If (view==0 | | fd==0)

Return

If (msync (view,len,sync?MS_SYNC:MS_ASYNC))

Problem ()

Tags: Data mechanisms steps caching code that is questions tasks functions functions background objects more help solutions easy inexplicable easy continuous interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Apple Shulou Tech Info Huawei