Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for making NamespaceDetails::Extra writes durable and use…

… this durable support when dropping indexes
  • Loading branch information...
commit 3a2087ac5c736c89ac9c7a125d525bdd5417d5f2 1 parent 02d0a9c
@astaple astaple authored
View
2  db/cap.cpp
@@ -410,7 +410,7 @@ namespace mongo {
// Get a writeable reference to 'this' and reset all pertinent
// attributes.
- NamespaceDetails *t = getDur().writing( this );
+ NamespaceDetails *t = writingWithoutExtra();
t->cappedLastDelRecLastExtent() = DiskLoc();
t->cappedListOfAllDeletedRecords() = DiskLoc();
View
2  db/dbcommands.cpp
@@ -566,7 +566,7 @@ namespace mongo {
BackgroundOperation::assertNoBgOpInProgForNs(ns);
- d = getDur().writing(d);
+ d = d->writingWithExtra();
d->aboutToDeleteAnIndex();
/* there may be pointers pointing at keys in the btree(s). kill them. */
View
19 db/dur.cpp
@@ -84,8 +84,8 @@ namespace mongo {
_intervalMicros = 3000000;
}
- Stats::S * Stats::other() {
- return curr == &_a ? &_b : &_a;
+ Stats::S * Stats::other() {
+ return curr == &_a ? &_b : &_a;
}
BSONObj Stats::S::_asObj() {
@@ -104,8 +104,8 @@ namespace mongo {
);
}
- BSONObj Stats::asObj() {
- return other()->_asObj();
+ BSONObj Stats::asObj() {
+ return other()->_asObj();
}
void Stats::rotate() {
@@ -185,6 +185,17 @@ namespace mongo {
declareWriteIntent(p+ofs, len);
return p;
}
+
+ void* DurableImpl::writingRangesAtOffsets(void *buf, const vector< pair< long long, unsigned > > &ranges ) {
+ char *p = (char *) buf;
+ if( testIntent )
+ p = (char *) MongoMMF::switchToPrivateView(buf);
+ for( vector< pair< long long, unsigned > >::const_iterator i = ranges.begin();
+ i != ranges.end(); ++i ) {
+ declareWriteIntent( p + i->first, i->second );
+ }
+ return p;
+ }
void DurableImpl::commitIfNeeded() {
if (commitJob.bytes() > 50*1024*1024) // should this also fire if CmdLine::DurAlwaysCommit?
View
20 db/dur.h
@@ -7,6 +7,8 @@
namespace mongo {
+ class NamespaceDetails;
+
namespace dur {
class DurableInterface : boost::noncopyable {
@@ -53,7 +55,15 @@ namespace mongo {
@return new buffer pointer. this is modified when testIntent is true.
*/
virtual void* writingAtOffset(void *buf, unsigned ofs, unsigned len) = 0;
-
+
+ /** declare intent to write
+ @param ranges vector of pairs representing ranges. Each pair
+ comprises an offset from buf where a range begins, then the
+ range length.
+ @return new buffer pointer. this is modified when testIntent is true.
+ */
+ virtual void* writingRangesAtOffsets(void *buf, const vector< pair< long long, unsigned > > &ranges ) = 0;
+
/** Wait for acknowledgement of the next group commit.
@return true if --dur is on. There will be delay.
@return false if --dur is off.
@@ -118,7 +128,11 @@ namespace mongo {
this will override the templated version and yield an unresolved external
*/
Record* writing(Record* r);
-
+ /** Unimplemented: BtreeBuckets are allocated in buffers larger than sizeof( BtreeBucket ). */
+ BtreeBucket* writing( BtreeBucket* );
+ /** Unimplemented: NamespaceDetails may be based on references to 'Extra' objects. */
+ NamespaceDetails* writing( NamespaceDetails* );
+
/** declare our intent to write, but it doesn't have to be journaled, as this write is
something 'unimportant'. depending on our implementation, we may or may not be able
to take advantage of this versus doing the normal work we do.
@@ -149,6 +163,7 @@ namespace mongo {
void startup();
void* writingPtr(void *x, unsigned len) { return x; }
void* writingAtOffset(void *buf, unsigned ofs, unsigned len) { return buf; }
+ void* writingRangesAtOffsets(void *buf, const vector< pair< long long, unsigned > > &ranges) { return buf; }
void declareWriteIntent(void *, unsigned) { }
void createdFile(string filename, unsigned long long len) { }
void droppingDb(string db) { }
@@ -164,6 +179,7 @@ namespace mongo {
void startup();
void* writingPtr(void *x, unsigned len);
void* writingAtOffset(void *buf, unsigned ofs, unsigned len);
+ void* writingRangesAtOffsets(void *buf, const vector< pair< long long, unsigned > > &ranges);
void declareWriteIntent(void *, unsigned);
void createdFile(string filename, unsigned long long len);
void droppingDb(string db);
View
9 db/namespace.cpp
@@ -554,6 +554,15 @@ namespace mongo {
return total;
}
+ NamespaceDetails *NamespaceDetails::writingWithExtra() {
+ vector< pair< long long, unsigned > > writeRanges;
+ writeRanges.push_back( make_pair( 0, sizeof( NamespaceDetails ) ) );
+ for( Extra *e = extra(); e; e = e->next( this ) ) {
+ writeRanges.push_back( make_pair( (char*)e - (char*)this, sizeof( Extra ) ) );
+ }
+ return reinterpret_cast< NamespaceDetails* >( getDur().writingRangesAtOffsets( this, writeRanges ) );
+ }
+
/* ------------------------------------------------------------------------- */
mongo::mutex NamespaceDetailsTransient::_qcMutex("qc");
View
6 db/namespace.h
@@ -360,6 +360,12 @@ namespace mongo {
return (int) (stats.datasize / stats.nrecords);
}
+ NamespaceDetails *writingWithoutExtra() {
+ return ( NamespaceDetails* ) getDur().writingPtr( this, sizeof( NamespaceDetails ) );
+ }
+ /** Make all linked Extra objects writeable as well */
+ NamespaceDetails *writingWithExtra();
+
private:
DiskLoc _alloc(const char *ns, int len);
void maybeComplain( const char *ns, int len ) const;
View
4 db/pdfile.cpp
@@ -428,7 +428,7 @@ namespace mongo {
}
{
- NamespaceDetails *dw = getDur().writing(details);
+ NamespaceDetails *dw = details->writingWithoutExtra();
dw->lastExtentSize = e->length;
}
details->addDeletedRec(emptyLoc.drec(), emptyLoc);
@@ -1524,7 +1524,7 @@ namespace mongo {
if ( lenWHdr == 0 ) {
// old datafiles, backward compatible here.
assert( d->paddingFactor == 0 );
- d->paddingFactor = 1.0;
+ *getDur().writingNoLog(&d->paddingFactor) = 1.0;
lenWHdr = len + Record::HeaderSize;
}
View
2  dbtests/namespacetests.cpp
@@ -620,7 +620,7 @@ namespace NamespaceTests {
return ns_;
}
NamespaceDetails *nsd() const {
- return getDur().writing( nsdetails( ns() ) );
+ return nsdetails( ns() )->writingWithExtra();
}
static BSONObj bigObj() {
string as( 187, 'a' );
View
8 dbtests/pdfiletests.cpp
@@ -112,7 +112,7 @@ namespace PdfileTests {
class EmptyLooped : public Base {
virtual void prepare() {
- getDur().writing(nsd())->capFirstNewRecord = DiskLoc();
+ nsd()->writingWithExtra()->capFirstNewRecord = DiskLoc();
}
virtual int count() const {
return 0;
@@ -121,7 +121,7 @@ namespace PdfileTests {
class EmptyMultiExtentLooped : public Base {
virtual void prepare() {
- getDur().writing( nsd() ) ->capFirstNewRecord = DiskLoc();
+ nsd()->writingWithExtra()->capFirstNewRecord = DiskLoc();
}
virtual int count() const {
return 0;
@@ -133,7 +133,7 @@ namespace PdfileTests {
class Single : public Base {
virtual void prepare() {
- getDur().writing( nsd() )->capFirstNewRecord = insert( nsd()->capExtent, 0 );
+ nsd()->writingWithExtra()->capFirstNewRecord = insert( nsd()->capExtent, 0 );
}
virtual int count() const {
return 1;
@@ -143,7 +143,7 @@ namespace PdfileTests {
class NewCapFirst : public Base {
virtual void prepare() {
DiskLoc x = insert( nsd()->capExtent, 0 );
- getDur().writing( nsd() )->capFirstNewRecord = x;
+ nsd()->writingWithExtra()->capFirstNewRecord = x;
insert( nsd()->capExtent, 1 );
}
virtual int count() const {
View
2  jstests/index_many2.js
@@ -27,3 +27,5 @@ assert.eq( num - 1 , t.getIndexKeys().length , "B0" )
t.ensureIndex( { z : 1 } )
assert.eq( num , t.getIndexKeys().length , "B1" )
+t.dropIndex( "*" );
+assert.eq( 1 , t.getIndexKeys().length , "C1" )
Please sign in to comment.
Something went wrong with that request. Please try again.