0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

check if closed properly, recstore

This commit is contained in:
Dwight 2009-02-06 14:33:26 -05:00
parent b2f203cba2
commit 0b210bfa0e
3 changed files with 7 additions and 2 deletions

View File

@ -17,7 +17,7 @@ class BasicRecStore {
uint32_t recsize;
uint64_t leof; // logical eof, actual file might be prealloc'd further
uint64_t firstDeleted; // 0 = no deleted recs
uint32_t cleanShutdown; // = clean
uint32_t cleanShutdown; // 0 = clean
char reserved[8192-8-8-4-4-4]; // we want our records page-aligned in the file if they are a multiple of a page's size -- so we make this 8KB with that goal
RecStoreHeader() {
version = 65;
@ -52,8 +52,10 @@ private:
inline BasicRecStore::~BasicRecStore() {
h.cleanShutdown = 0;
if( f.is_open() )
if( f.is_open() ) {
writeHeader();
f.fsync();
}
}
inline void BasicRecStore::writeHeader() {

View File

@ -26,6 +26,7 @@ void BasicRecStore::init(const char *fn, unsigned recsize)
}
else {
f.read(0, (char *) &h, sizeof(RecStoreHeader));
massert(string("recstore was not closed cleanly: ")+fn, h.cleanShutdown==0);
massert(string("recstore recsize mismatch, file:")+fn, h.recsize == recsize);
massert(string("bad recstore [1], file:")+fn, (h.leof-sizeof(RecStoreHeader)) % recsize == 0);
if( h.leof > len ) {

View File

@ -86,6 +86,7 @@ public:
}
return li.QuadPart;
}
void fsync() { FlushFileBuffers(fd); }
};
#else
@ -129,6 +130,7 @@ public:
fileofs len() {
return lseek(fd, 0, SEEK_END);
}
void fsync() { ::fsync(fd); }
};