0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/db/storage.cpp

60 lines
1.8 KiB
C++
Raw Normal View History

2009-02-03 00:18:22 +01:00
// storage.cpp
#include "stdafx.h"
#include "pdfile.h"
#include "reccache.h"
#include "rec.h"
#include "db.h"
namespace mongo {
void writerThread();
2009-02-03 00:18:22 +01:00
static int inited;
// pick your store for indexes by setting this typedef
// this doesn't need to be an ifdef, we can make it dynamic
#if defined(_RECSTORE)
RecStoreInterface *btreeStore = new CachedBasicRecStore();
#else
RecStoreInterface *btreeStore = new MongoMemMapped_RecStore();
#endif
2009-02-03 00:18:22 +01:00
void BasicRecStore::init(const char *fn, unsigned recsize)
{
massert( "compile packing problem recstore?", sizeof(RecStoreHeader) == 8192);
filename = fn;
f.open(fn);
2009-02-03 00:18:22 +01:00
uassert( string("couldn't open file:")+fn, f.is_open() );
len = f.len();
2009-02-03 00:18:22 +01:00
if( len == 0 ) {
log() << "creating recstore file " << fn << '\n';
h.recsize = recsize;
len = sizeof(RecStoreHeader);
f.write(0, (const char *) &h, sizeof(RecStoreHeader));
2009-02-03 00:18:22 +01:00
}
else {
f.read(0, (char *) &h, sizeof(RecStoreHeader));
2009-02-06 20:33:26 +01:00
massert(string("recstore was not closed cleanly: ")+fn, h.cleanShutdown==0);
2009-02-03 00:18:22 +01:00
massert(string("recstore recsize mismatch, file:")+fn, h.recsize == recsize);
massert(string("bad recstore [1], file:")+fn, (h.leof-sizeof(RecStoreHeader)) % recsize == 0);
2009-02-04 17:26:51 +01:00
if( h.leof > len ) {
stringstream ss;
ss << "bad recstore, file:" << fn << " leof:" << h.leof << " len:" << len;
massert(ss.str(), false);
}
2009-02-03 00:18:22 +01:00
if( h.cleanShutdown )
log() << "warning: non-clean shutdown for file " << fn << '\n';
h.cleanShutdown = 2;
writeHeader();
2009-02-06 21:56:36 +01:00
f.fsync();
2009-02-03 00:18:22 +01:00
}
#if defined(_RECSTORE)
if( inited++ == 0 ) {
boost::thread t(writerThread);
}
#endif
2009-02-04 17:26:51 +01:00
}
2009-02-03 00:18:22 +01:00
}