summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/mmap_v1/data_file_sync.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/data_file_sync.cpp')
-rw-r--r--src/mongo/db/storage/mmap_v1/data_file_sync.cpp141
1 files changed, 68 insertions, 73 deletions
diff --git a/src/mongo/db/storage/mmap_v1/data_file_sync.cpp b/src/mongo/db/storage/mmap_v1/data_file_sync.cpp
index 9579278ded1..013877cb08b 100644
--- a/src/mongo/db/storage/mmap_v1/data_file_sync.cpp
+++ b/src/mongo/db/storage/mmap_v1/data_file_sync.cpp
@@ -44,95 +44,90 @@
namespace mongo {
- using std::endl;
+using std::endl;
- DataFileSync dataFileSync;
+DataFileSync dataFileSync;
- DataFileSync::DataFileSync()
- : ServerStatusSection( "backgroundFlushing" ),
- _total_time( 0 ),
- _flushes( 0 ),
- _last() {
+DataFileSync::DataFileSync()
+ : ServerStatusSection("backgroundFlushing"), _total_time(0), _flushes(0), _last() {}
- }
-
- void DataFileSync::run() {
- Client::initThread( name().c_str() );
+void DataFileSync::run() {
+ Client::initThread(name().c_str());
+ if (storageGlobalParams.syncdelay == 0) {
+ log() << "warning: --syncdelay 0 is not recommended and can have strange performance"
+ << endl;
+ } else if (storageGlobalParams.syncdelay == 1) {
+ log() << "--syncdelay 1" << endl;
+ } else if (storageGlobalParams.syncdelay != 60) {
+ LOG(1) << "--syncdelay " << storageGlobalParams.syncdelay << endl;
+ }
+ int time_flushing = 0;
+ while (!inShutdown()) {
+ _diaglog.flush();
if (storageGlobalParams.syncdelay == 0) {
- log() << "warning: --syncdelay 0 is not recommended and can have strange performance" << endl;
- }
- else if (storageGlobalParams.syncdelay == 1) {
- log() << "--syncdelay 1" << endl;
+ // in case at some point we add an option to change at runtime
+ sleepsecs(5);
+ continue;
}
- else if (storageGlobalParams.syncdelay != 60) {
- LOG(1) << "--syncdelay " << storageGlobalParams.syncdelay << endl;
- }
- int time_flushing = 0;
- while ( ! inShutdown() ) {
- _diaglog.flush();
- if (storageGlobalParams.syncdelay == 0) {
- // in case at some point we add an option to change at runtime
- sleepsecs(5);
- continue;
- }
-
- sleepmillis((long long) std::max(0.0, (storageGlobalParams.syncdelay * 1000) - time_flushing));
-
- if ( inShutdown() ) {
- // occasional issue trying to flush during shutdown when sleep interrupted
- break;
- }
-
- Date_t start = jsTime();
- StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
- int numFiles = storageEngine->flushAllFiles( true );
- time_flushing = (jsTime() - start).count();
-
- _flushed(time_flushing);
-
- if( shouldLog(logger::LogSeverity::Debug(1)) || time_flushing >= 10000 ) {
- log() << "flushing mmaps took " << time_flushing << "ms " << " for " << numFiles << " files" << endl;
- }
- }
- }
- BSONObj DataFileSync::generateSection(OperationContext* txn,
- const BSONElement& configElement) const {
- if (!running()) {
- return BSONObj();
+ sleepmillis(
+ (long long)std::max(0.0, (storageGlobalParams.syncdelay * 1000) - time_flushing));
+
+ if (inShutdown()) {
+ // occasional issue trying to flush during shutdown when sleep interrupted
+ break;
}
- BSONObjBuilder b;
- b.appendNumber( "flushes" , _flushes );
- b.appendNumber( "total_ms" , _total_time );
- b.appendNumber( "average_ms" , (_flushes ? (_total_time / double(_flushes)) : 0.0) );
- b.appendNumber( "last_ms" , _last_time );
- b.append("last_finished", _last);
- return b.obj();
+ Date_t start = jsTime();
+ StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
+ int numFiles = storageEngine->flushAllFiles(true);
+ time_flushing = (jsTime() - start).count();
+
+ _flushed(time_flushing);
+
+ if (shouldLog(logger::LogSeverity::Debug(1)) || time_flushing >= 10000) {
+ log() << "flushing mmaps took " << time_flushing << "ms "
+ << " for " << numFiles << " files" << endl;
+ }
}
+}
- void DataFileSync::_flushed(int ms) {
- _flushes++;
- _total_time += ms;
- _last_time = ms;
- _last = jsTime();
+BSONObj DataFileSync::generateSection(OperationContext* txn,
+ const BSONElement& configElement) const {
+ if (!running()) {
+ return BSONObj();
}
+ BSONObjBuilder b;
+ b.appendNumber("flushes", _flushes);
+ b.appendNumber("total_ms", _total_time);
+ b.appendNumber("average_ms", (_flushes ? (_total_time / double(_flushes)) : 0.0));
+ b.appendNumber("last_ms", _last_time);
+ b.append("last_finished", _last);
+ return b.obj();
+}
+
+void DataFileSync::_flushed(int ms) {
+ _flushes++;
+ _total_time += ms;
+ _last_time = ms;
+ _last = jsTime();
+}
- class MemJournalServerStatusMetric : public ServerStatusMetric {
- public:
- MemJournalServerStatusMetric() : ServerStatusMetric(".mem.mapped") {}
- virtual void appendAtLeaf( BSONObjBuilder& b ) const {
- int m = static_cast<int>(MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 ));
- b.appendNumber( "mapped" , m );
- if (storageGlobalParams.dur) {
- m *= 2;
- b.appendNumber( "mappedWithJournal" , m );
- }
+class MemJournalServerStatusMetric : public ServerStatusMetric {
+public:
+ MemJournalServerStatusMetric() : ServerStatusMetric(".mem.mapped") {}
+ virtual void appendAtLeaf(BSONObjBuilder& b) const {
+ int m = static_cast<int>(MemoryMappedFile::totalMappedLength() / (1024 * 1024));
+ b.appendNumber("mapped", m);
+ if (storageGlobalParams.dur) {
+ m *= 2;
+ b.appendNumber("mappedWithJournal", m);
}
+ }
- } memJournalServerStatusMetric;
+} memJournalServerStatusMetric;
}