summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-06-26 15:30:54 -0400
committerDwight <dmerriman@gmail.com>2008-06-26 15:30:54 -0400
commit58d84f51f2ecf26d3926bb648b88b4e97d410244 (patch)
treeb71b3e73ce8fbdb66f53c3732a676a10add49a61
parent9dbbf6065e0e1305388fc7eb2a9822ccea3ec7e4 (diff)
downloadmongo-58d84f51f2ecf26d3926bb648b88b4e97d410244.tar.gz
close datafiles on any sort of termination (including seg fault)
-rw-r--r--db/db.cpp7
-rw-r--r--util/mmap.cpp24
-rw-r--r--util/mmap.h4
3 files changed, 29 insertions, 6 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 6f826c3ee9d..7986980ec72 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -679,8 +679,10 @@ void pipeSigHandler( int signal ) {
}
void segvhandler(int x) {
- cout << "got SIGSEGV " << x << ", terminating :-(" << endl;
problem() << "got SIGSEGV " << x << ", terminating :-(" << endl;
+ sayDbContext();
+ MemoryMappedFile::closeAllFiles();
+ flushOpLog();
}
void mysighandler(int x) {
@@ -885,6 +887,9 @@ int main(int argc, char* argv[], char *envp[] )
#undef exit
void dbexit(int rc) {
+ cout << " dbexit: flushing op log and files" << endl;
flushOpLog();
+ MemoryMappedFile::closeAllFiles();
+ cout << " dbexit: really exiting now" << endl;
exit(rc);
}
diff --git a/util/mmap.cpp b/util/mmap.cpp
index 542e8c714ae..ad628473e48 100644
--- a/util/mmap.cpp
+++ b/util/mmap.cpp
@@ -3,15 +3,30 @@
#include "stdafx.h"
#include "mmap.h"
+set<MemoryMappedFile*> mmfiles;
+
+MemoryMappedFile::~MemoryMappedFile() {
+ close();
+ mmfiles.erase(this);
+}
+
+/*static*/
+void MemoryMappedFile::closeAllFiles() {
+ for( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ )
+ (*i)->close();
+ cout << " closeAllFiles() finished" << endl;
+}
+
#if defined(_WIN32)
#include "windows.h"
MemoryMappedFile::MemoryMappedFile() {
fd = 0; maphandle = 0; view = 0;
+ mmfiles.insert(this);
}
-MemoryMappedFile::~MemoryMappedFile() {
+void MemoryMappedFile::close() {
if( view )
UnmapViewOfFile(view);
view = 0;
@@ -24,7 +39,6 @@ MemoryMappedFile::~MemoryMappedFile() {
}
std::wstring toWideString(const char *s) {
- //const std::basic_string<TCHAR> s) {
std::basic_ostringstream<TCHAR> buf;
buf << s;
return buf.str();
@@ -78,15 +92,17 @@ void MemoryMappedFile::flush(bool) {
MemoryMappedFile::MemoryMappedFile() {
fd = 0; maphandle = 0; view = 0; len = 0;
+ mmfiles.insert(this);
}
-MemoryMappedFile::~MemoryMappedFile() {
+void MemoryMappedFile::close() {
+ mmfiles.erase(this);
if( view )
munmap(view, len);
view = 0;
if( fd )
- close(fd);
+ ::close(fd);
fd = 0;
}
diff --git a/util/mmap.h b/util/mmap.h
index 15f638787d8..c09eaa14d85 100644
--- a/util/mmap.h
+++ b/util/mmap.h
@@ -4,8 +4,10 @@
class MemoryMappedFile {
public:
+ static void closeAllFiles();
MemoryMappedFile();
- ~MemoryMappedFile();
+ ~MemoryMappedFile(); /* closes the file if open */
+ void close();
/* only smart enough right now to deal with files of a fixed length.
creates if DNE