|
1 | | -// storage.cpp |
2 | | - |
3 | | -#include "stdafx.h" |
4 | | -#include "pdfile.h" |
5 | | -#include "reccache.h" |
6 | | -#include "rec.h" |
7 | | -#include "db.h" |
8 | | - |
9 | | -namespace mongo { |
10 | | - |
11 | | -void writerThread(); |
12 | | - |
13 | | -static int inited; |
14 | | - |
| 1 | +// storage.cpp |
| 2 | + |
| 3 | +#include "stdafx.h" |
| 4 | +#include "pdfile.h" |
| 5 | +#include "reccache.h" |
| 6 | +#include "rec.h" |
| 7 | +#include "db.h" |
| 8 | + |
| 9 | +namespace mongo { |
| 10 | + |
| 11 | +void writerThread(); |
| 12 | + |
| 13 | +#if defined(_RECSTORE) |
| 14 | + static int inited; |
| 15 | +#endif |
| 16 | + |
15 | 17 | // pick your store for indexes by setting this typedef |
16 | 18 | // this doesn't need to be an ifdef, we can make it dynamic |
17 | 19 | #if defined(_RECSTORE) |
18 | 20 | RecStoreInterface *btreeStore = new CachedBasicRecStore(); |
19 | 21 | #else |
20 | 22 | RecStoreInterface *btreeStore = new MongoMemMapped_RecStore(); |
21 | 23 | #endif |
22 | | - |
23 | | -void BasicRecStore::init(const char *fn, unsigned recsize) |
24 | | -{ |
25 | | - massert( "compile packing problem recstore?", sizeof(RecStoreHeader) == 8192); |
26 | | - filename = fn; |
27 | | - f.open(fn); |
28 | | - uassert( string("couldn't open file:")+fn, f.is_open() ); |
29 | | - len = f.len(); |
30 | | - if( len == 0 ) { |
31 | | - log() << "creating recstore file " << fn << '\n'; |
32 | | - h.recsize = recsize; |
33 | | - len = sizeof(RecStoreHeader); |
34 | | - f.write(0, (const char *) &h, sizeof(RecStoreHeader)); |
35 | | - } |
36 | | - else { |
37 | | - f.read(0, (char *) &h, sizeof(RecStoreHeader)); |
38 | | - massert(string("recstore was not closed cleanly: ")+fn, h.cleanShutdown==0); |
39 | | - massert(string("recstore recsize mismatch, file:")+fn, h.recsize == recsize); |
40 | | - massert(string("bad recstore [1], file:")+fn, (h.leof-sizeof(RecStoreHeader)) % recsize == 0); |
41 | | - if( h.leof > len ) { |
42 | | - stringstream ss; |
43 | | - ss << "bad recstore, file:" << fn << " leof:" << h.leof << " len:" << len; |
44 | | - massert(ss.str(), false); |
45 | | - } |
46 | | - if( h.cleanShutdown ) |
47 | | - log() << "warning: non-clean shutdown for file " << fn << '\n'; |
48 | | - h.cleanShutdown = 2; |
49 | | - writeHeader(); |
50 | | - f.fsync(); |
51 | | - } |
52 | | -#if defined(_RECSTORE) |
53 | | - if( inited++ == 0 ) { |
54 | | - boost::thread t(writerThread); |
55 | | - } |
56 | | -#endif |
57 | | -} |
58 | | - |
59 | | -} |
| 24 | + |
| 25 | +void BasicRecStore::init(const char *fn, unsigned recsize) |
| 26 | +{ |
| 27 | + massert( "compile packing problem recstore?", sizeof(RecStoreHeader) == 8192); |
| 28 | + filename = fn; |
| 29 | + f.open(fn); |
| 30 | + uassert( string("couldn't open file:")+fn, f.is_open() ); |
| 31 | + len = f.len(); |
| 32 | + if( len == 0 ) { |
| 33 | + log() << "creating recstore file " << fn << '\n'; |
| 34 | + h.recsize = recsize; |
| 35 | + len = sizeof(RecStoreHeader); |
| 36 | + f.write(0, (const char *) &h, sizeof(RecStoreHeader)); |
| 37 | + } |
| 38 | + else { |
| 39 | + f.read(0, (char *) &h, sizeof(RecStoreHeader)); |
| 40 | + massert(string("recstore was not closed cleanly: ")+fn, h.cleanShutdown==0); |
| 41 | + massert(string("recstore recsize mismatch, file:")+fn, h.recsize == recsize); |
| 42 | + massert(string("bad recstore [1], file:")+fn, (h.leof-sizeof(RecStoreHeader)) % recsize == 0); |
| 43 | + if( h.leof > len ) { |
| 44 | + stringstream ss; |
| 45 | + ss << "bad recstore, file:" << fn << " leof:" << h.leof << " len:" << len; |
| 46 | + massert(ss.str(), false); |
| 47 | + } |
| 48 | + if( h.cleanShutdown ) |
| 49 | + log() << "warning: non-clean shutdown for file " << fn << '\n'; |
| 50 | + h.cleanShutdown = 2; |
| 51 | + writeHeader(); |
| 52 | + f.fsync(); |
| 53 | + } |
| 54 | +#if defined(_RECSTORE) |
| 55 | + if( inited++ == 0 ) { |
| 56 | + boost::thread t(writerThread); |
| 57 | + } |
| 58 | +#endif |
| 59 | +} |
| 60 | + |
| 61 | +} |
0 commit comments