diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-04-10 11:27:44 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-04-10 14:09:36 -0400 |
commit | 8ea68f28c358558779f73930e3f637519f0eeb27 (patch) | |
tree | 1b487855fa3cdd9ab92986ebb32493378fc47360 /src/mongo/db/index.cpp | |
parent | 6097787b1f3c7f9b4f8dca68f66d474eaa60b1d1 (diff) | |
download | mongo-8ea68f28c358558779f73930e3f637519f0eeb27.tar.gz |
SERVER-5531: Make index insertion continuation information local to the function updating the index.
Reenable jstests/basicc.js .
Diffstat (limited to 'src/mongo/db/index.cpp')
-rw-r--r-- | src/mongo/db/index.cpp | 78 |
1 files changed, 32 insertions, 46 deletions
diff --git a/src/mongo/db/index.cpp b/src/mongo/db/index.cpp index 2781b07e592..f5644067fb0 100644 --- a/src/mongo/db/index.cpp +++ b/src/mongo/db/index.cpp @@ -16,6 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <boost/checked_delete.hpp> + #include "pch.h" #include "namespace-inl.h" #include "index.h" @@ -23,56 +25,49 @@ #include "background.h" #include "repl/rs.h" #include "ops/delete.h" +#include "mongo/util/scopeguard.h" namespace mongo { + IndexInterface::IndexInserter::IndexInserter() {} + IndexInterface::IndexInserter::~IndexInserter() { + for (size_t i = 0; i < _continuations.size(); ++i) + delete _continuations[i]; + } + + void IndexInterface::IndexInserter::addInsertionContinuation(IndexInsertionContinuation *c) { + _continuations.push_back(c); + } + + void IndexInterface::IndexInserter::finishAllInsertions() { + for (size_t i = 0; i < _continuations.size(); ++i) { + _continuations[i]->doIndexInsertionWrites(); + } + } + + template< class V > class IndexInterfaceImpl : public IndexInterface { public: typedef typename V::KeyOwned KeyOwned; - typedef Continuation<V> Cont; virtual int keyCompare(const BSONObj& l,const BSONObj& r, const Ordering &ordering); - Cont *c[NamespaceDetails::NIndexesMax]; - int n; - public: - IndexInterfaceImpl() { n = 0; } - - /* lacking CONCURRENCY WRITE this supports only one writer */ - void _phasedBegin() { - // we do this here as phasedFinish can throw exceptions (we could catch there, but just as easy to do here) - for( int i = 0; i < n; i++ ) { - delete c[i]; - c[i] = 0; // defensive - } - n = 0; - } - void phasedQueueItemToInsert( - int idxNo, - DiskLoc thisLoc, DiskLoc _recordLoc, const BSONObj &_key, - const Ordering& _order, IndexDetails& _idx, bool dupsAllowed) - { - if( idxNo >= n ) - n = idxNo + 1; - Cont *C = c[idxNo] = new Cont(thisLoc, _recordLoc, _key, _order, _idx); - thisLoc.btree<V>()->twoStepInsert(thisLoc, *C, dupsAllowed); - } - void _phasedFinish() { - for( int i = 0; i < n; i++ ) { - // if mixing v0 and v1 indexes, in that case (only) there could be nulls in the list - if( c[i] ) { - c[i]->stepTwo(); - } - } - } + IndexInsertionContinuation *beginInsertIntoIndex( + int idxNo, IndexDetails &_idx, + DiskLoc _recordLoc, const BSONObj &_key, + const Ordering& _order, bool dupsAllowed) { -/* virtual DiskLoc locate(const IndexDetails &idx , const DiskLoc& thisLoc, const BSONObj& key, const Ordering &order, - int& pos, bool& found, const DiskLoc &recordLoc, int direction) { - return thisLoc.btree<V>()->locate(idx, thisLoc, key, order, pos, found, recordLoc, direction); + IndexInsertionContinuationImpl<V> *continuation = new IndexInsertionContinuationImpl<V>( + _idx.head, _recordLoc, _key, _order, _idx); + ScopeGuard allocGuard = MakeGuard(boost::checked_delete<IndexInsertionContinuation>, + continuation); + _idx.head.btree<V>()->twoStepInsert(_idx.head, *continuation, dupsAllowed); + allocGuard.Dismiss(); + return continuation; } - */ + virtual long long fullValidate(const DiskLoc& thisLoc, const BSONObj &order) { return thisLoc.btree<V>()->fullValidate(thisLoc, order); } @@ -144,15 +139,6 @@ namespace mongo { IndexInterface *IndexDetails::iis[] = { &iii_v0, &iii_v1 }; - void IndexInterface::phasedBegin() { - iii_v0._phasedBegin(); - iii_v1._phasedBegin(); - } - void IndexInterface::phasedFinish() { - iii_v0._phasedFinish(); - iii_v1._phasedFinish(); - } - int removeFromSysIndexes(const char *ns, const char *idxName) { string system_indexes = cc().database()->name + ".system.indexes"; BSONObjBuilder b; |