diff options
author | Dwight <dwight@10gen.com> | 2010-09-28 17:18:36 -0400 |
---|---|---|
committer | Dwight <dwight@10gen.com> | 2010-09-28 17:18:36 -0400 |
commit | dbd32482a6ef5b4e305126bd30a329c63aa973b9 (patch) | |
tree | a0fbf9c6652ef5c20a36345622cc740ecfc5d55f /db | |
parent | c9885b8d8b30f72e268076c1f8a366baa23bd4a6 (diff) | |
download | mongo-dbd32482a6ef5b4e305126bd30a329c63aa973b9.tar.gz |
durability more work on declaring intent to write in the code
Diffstat (limited to 'db')
-rw-r--r-- | db/btree.cpp | 20 | ||||
-rw-r--r-- | db/btree.h | 5 | ||||
-rw-r--r-- | db/db.h | 3 | ||||
-rw-r--r-- | db/dbcommands.cpp | 1 | ||||
-rw-r--r-- | db/diskloc.h | 10 | ||||
-rw-r--r-- | db/namespace.cpp | 3 | ||||
-rw-r--r-- | db/pdfile.cpp | 19 | ||||
-rw-r--r-- | db/pdfile.h | 14 |
8 files changed, 36 insertions, 39 deletions
diff --git a/db/btree.cpp b/db/btree.cpp index 43b155aa16d..86982c7468b 100644 --- a/db/btree.cpp +++ b/db/btree.cpp @@ -37,6 +37,10 @@ namespace mongo { return dur::writing(b); } + _KeyNode& _KeyNode::writing() { + return *dur::writing(this); + } + KeyNode::KeyNode(const BucketBasics& bb, const _KeyNode &k) : prevChildBucket(k.prevChildBucket), recordLoc(k.recordLoc), key(bb.data+k.keyDataOfs()) @@ -773,7 +777,7 @@ found: p->pushBack(splitkey.recordLoc, splitkey.key, order, thisLoc); p->nextChild = rLoc; p->assertValid( order ); - parent = idx.head = L; + parent = idx.head.writing() = L; if ( split_debug ) out() << " we were root, making new root:" << hex << parent.getOfs() << dec << endl; rLoc.btreemod()->parent = parent; @@ -1071,17 +1075,17 @@ found: log(4) << "btree _insert: reusing unused key" << endl; massert( 10285 , "_insert: reuse key but lchild is not null", lChild.isNull()); massert( 10286 , "_insert: reuse key but rchild is not null", rChild.isNull()); - kn.setUsed(); + kn.writing().setUsed(); return 0; } DEV { - out() << "_insert(): key already exists in index (ok for background:true)\n"; - out() << " " << idx.indexNamespace().c_str() << " thisLoc:" << thisLoc.toString() << '\n'; - out() << " " << key.toString() << '\n'; - out() << " " << "recordLoc:" << recordLoc.toString() << " pos:" << pos << endl; - out() << " old l r: " << childForPos(pos).toString() << ' ' << childForPos(pos+1).toString() << endl; - out() << " new l r: " << lChild.toString() << ' ' << rChild.toString() << endl; + log() << "_insert(): key already exists in index (ok for background:true)\n"; + log() << " " << idx.indexNamespace().c_str() << " thisLoc:" << thisLoc.toString() << '\n'; + log() << " " << key.toString() << '\n'; + log() << " " << "recordLoc:" << recordLoc.toString() << " pos:" << pos << endl; + log() << " old l r: " << childForPos(pos).toString() << ' ' << childForPos(pos+1).toString() << endl; + log() << " new l r: " << lChild.toString() << ' ' << rChild.toString() << endl; } alreadyInIndex(); } diff --git a/db/btree.h b/db/btree.h index 63b1b1aa148..689e62a2ec2 100644 --- a/db/btree.h +++ b/db/btree.h @@ -27,6 +27,7 @@ namespace mongo { #pragma pack(1) struct _KeyNode { + _KeyNode& writing(); DiskLoc prevChildBucket; // the lchild DiskLoc recordLoc; // location of the record associated with the key short keyDataOfs() const { @@ -41,9 +42,7 @@ namespace mongo { _kdo = s; assert(s>=0); } - void setUsed() { - recordLoc.GETOFS() &= ~1; - } + void setUsed() { recordLoc.GETOFS() &= ~1; } void setUnused() { /* Setting ofs to odd is the sentinel for unused, as real recordLoc's are always even numbers. @@ -48,8 +48,7 @@ namespace mongo { typedef map<string,Database*> DBs; typedef map<string,DBs> Paths; - DatabaseHolder() : _size(0){ - } + DatabaseHolder() : _size(0) { } bool isLoaded( const string& ns , const string& path ) const { dbMutex.assertAtLeastReadLocked(); diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 28f0ebb6705..e80802a8f52 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -501,6 +501,7 @@ namespace mongo { BackgroundOperation::assertNoBgOpInProgForNs(ns); + d = dur::writing(d); d->aboutToDeleteAnIndex(); /* there may be pointers pointing at keys in the btree(s). kill them. */ diff --git a/db/diskloc.h b/db/diskloc.h index 0f675c25d90..55a6c677026 100644 --- a/db/diskloc.h +++ b/db/diskloc.h @@ -71,9 +71,7 @@ namespace mongo { _a = -2; ofs = 0; } - bool isValid() const { - return _a != -2; - } + bool isValid() const { return _a != -2; } string toString() const { if ( isNull() ) @@ -83,11 +81,9 @@ namespace mongo { return ss.str(); } - BSONObj toBSONObj() const { - return BSON( "file" << _a << "offset" << ofs ); - } + BSONObj toBSONObj() const { return BSON( "file" << _a << "offset" << ofs ); } - int a() const { return _a; } + int a() const { return _a; } int& GETOFS() { return ofs; } int getOfs() const { return ofs; } diff --git a/db/namespace.cpp b/db/namespace.cpp index 0e183680fea..c6130f5ca99 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -448,7 +448,10 @@ namespace mongo { /* you MUST call when adding an index. see pdfile.cpp */ IndexDetails& NamespaceDetails::addIndex(const char *thisns, bool resetTransient) { +#if !defined(_DEBUG) || !defined(_DURABLE) + // in debug durable mode the write view could be "this" not the nsdetails returned view... assert( nsdetails(thisns) == this ); +#endif IndexDetails *id; try { diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 8e75ce41925..848ae4e38d4 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -492,13 +492,13 @@ namespace mongo { Extent *e = best; // remove from the free list if( !e->xprev.isNull() ) - e->xprev.ext()->xnext = e->xnext; + e->xprev.ext()->xnext.writing() = e->xnext; if( !e->xnext.isNull() ) - e->xnext.ext()->xprev = e->xprev; + e->xnext.ext()->xprev.writing() = e->xprev; if( f->firstExtent == e->myLoc ) - f->firstExtent = e->xnext; + f->firstExtent.writing() = e->xnext; if( f->lastExtent == e->myLoc ) - f->lastExtent = e->xprev; + f->lastExtent.writing() = e->xprev; // use it OCCASIONALLY if( n > 512 ) log() << "warning: newExtent " << n << " scanned\n"; @@ -515,7 +515,9 @@ namespace mongo { /*---------------------------------------------------------------------*/ DiskLoc Extent::reuse(const char *nsname) { - /*TODOMMF - work to do when extent is freed. */ + return dur::writing(this)->_reuse(nsname); + } + DiskLoc Extent::_reuse(const char *nsname) { log(3) << "reset extent was:" << nsDiagnostic.toString() << " now:" << nsname << '\n'; massert( 10360 , "Extent::reset bad magic value", magic == 0x41424344 ); xnext.Null(); @@ -528,12 +530,9 @@ namespace mongo { emptyLoc.inc( (int) (_extentData-(char*)this) ); int delRecLength = length - (_extentData - (char *) this); - //DeletedRecord *empty1 = (DeletedRecord *) extentData; - DeletedRecord *empty = DataFileMgr::makeDeletedRecord(emptyLoc, delRecLength);//(DeletedRecord *) getRecord(emptyLoc); - //assert( empty == empty1 ); - - // do we want to zero the record? memset(empty, ...) + DeletedRecord *empty = DataFileMgr::makeDeletedRecord(emptyLoc, delRecLength);//(DeletedRecord *) getRecord(emptyLoc); + empty = dur::writing(empty); empty->lengthWithHeaders = delRecLength; empty->extentOfs = myLoc.getOfs(); empty->nextDeleted.Null(); diff --git a/db/pdfile.h b/db/pdfile.h index 1d4001658b8..78af6711e0e 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -236,9 +236,7 @@ namespace mongo { /* like init(), but for a reuse case */ DiskLoc reuse(const char *nsname); - void assertOk() { - assert(magic == 0x41424344); - } + void assertOk() { assert(magic == 0x41424344); } Record* newRecord(int len); @@ -250,14 +248,12 @@ namespace mongo { return (Record *) (((char *) this) + x); } - Extent* getNextExtent() { - return xnext.isNull() ? 0 : DataFileMgr::getExtent(xnext); - } - Extent* getPrevExtent() { - return xprev.isNull() ? 0 : DataFileMgr::getExtent(xprev); - } + Extent* getNextExtent() { return xnext.isNull() ? 0 : DataFileMgr::getExtent(xnext); } + Extent* getPrevExtent() { return xprev.isNull() ? 0 : DataFileMgr::getExtent(xprev); } static int maxSize(); + private: + DiskLoc _reuse(const char *nsname); }; /* |