summaryrefslogtreecommitdiff
path: root/db/storage.cpp
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-02-04 11:26:51 -0500
committerDwight <dmerriman@gmail.com>2009-02-04 11:26:51 -0500
commitc01b4a773a45d7b7562db2334218cd64944b7396 (patch)
treeb91d433cf3ec588034611d58f0ebde10306f4b05 /db/storage.cpp
parentf570edca68b342e389e154dd7efd2f68001da8eb (diff)
downloadmongo-c01b4a773a45d7b7562db2334218cd64944b7396.tar.gz
reccache bug fix
Diffstat (limited to 'db/storage.cpp')
-rw-r--r--db/storage.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/db/storage.cpp b/db/storage.cpp
index a1158f32b2a..8793f7b6090 100644
--- a/db/storage.cpp
+++ b/db/storage.cpp
@@ -49,7 +49,11 @@ void BasicRecStore::init(const char *fn, unsigned recsize)
f.read((char *) &h, sizeof(RecStoreHeader));
massert(string("recstore recsize mismatch, file:")+fn, h.recsize == recsize);
massert(string("bad recstore [1], file:")+fn, (h.leof-sizeof(RecStoreHeader)) % recsize == 0);
- massert(string("bad recstore [2], file:")+fn, h.leof <= len);
+ if( h.leof > len ) {
+ stringstream ss;
+ ss << "bad recstore, file:" << fn << " leof:" << h.leof << " len:" << len;
+ massert(ss.str(), false);
+ }
if( h.cleanShutdown )
log() << "warning: non-clean shutdown for file " << fn << '\n';
h.cleanShutdown = 2;
@@ -59,6 +63,8 @@ void BasicRecStore::init(const char *fn, unsigned recsize)
// boost::thread t(storeThread);
}
+/* -------------------------------------------------------- */
+
inline void RecCache::writeIfDirty(Node *n) {
if( n->dirty ) {
n->dirty = false;
@@ -83,20 +89,22 @@ void RecCache::writeDirty() {
// 100k * 8KB = 800MB
const unsigned RECCACHELIMIT = 150000;
+//const unsigned RECCACHELIMIT = 25;
inline void RecCache::ejectOld() {
if( nnodes <= RECCACHELIMIT )
return;
Node *n = oldest;
while( 1 ) {
- if( nnodes <= RECCACHELIMIT ) {
+ if( nnodes <= RECCACHELIMIT - 4 ) {
n->older = 0;
oldest = n;
+ assert( oldest ) ;
break;
}
nnodes--;
- Node *nxt = n->newer;
assert(n);
+ Node *nxt = n->newer;
writeIfDirty(n);
m.erase(n->loc);
delete n;
@@ -104,7 +112,21 @@ inline void RecCache::ejectOld() {
}
}
-void dbunlocked() {
+void RecCache::dump() {
+ Node *n = oldest;
+ Node *last = 0;
+ while( n ) {
+ assert( n->older == last );
+ last = n;
+// cout << n << ' ' << n->older << ' ' << n->newer << '\n';
+ n=n->newer;
+ }
+ assert( newest == last );
+// cout << endl;
+}
+
+void dbunlocking() {
+ assert( dbMutexInfo.isLocked() );
BasicCached_RecStore::rc.ejectOld();
}