@@ -152,32 +152,20 @@ namespace mongo {
152152 return _recordStore->getManyIterators (txn);
153153 }
154154
155- int64_t Collection::countTableScan ( OperationContext* txn, const MatchExpression* expression ) {
156- scoped_ptr<RecordIterator> iterator ( getIterator ( txn,
157- RecordId (),
158- CollectionScanParams::FORWARD ) );
159- int64_t count = 0 ;
160- while ( !iterator->isEOF () ) {
161- RecordId loc = iterator->getNext ();
162- BSONObj obj = docFor ( txn, loc );
163- if ( expression->matchesBSON ( obj ) )
164- count++;
165- }
166-
167- return count;
168- }
169-
170- BSONObj Collection::docFor (OperationContext* txn, const RecordId& loc) const {
171- return _recordStore->dataFor ( txn, loc ).releaseToBson ();
155+ Snapshotted<BSONObj> Collection::docFor (OperationContext* txn, const RecordId& loc) const {
156+ return Snapshotted<BSONObj>(txn->recoveryUnit ()->getSnapshotId (),
157+ _recordStore->dataFor ( txn, loc ).releaseToBson ());
172158 }
173159
174- bool Collection::findDoc (OperationContext* txn, const RecordId& loc, BSONObj* out) const {
160+ bool Collection::findDoc (OperationContext* txn,
161+ const RecordId& loc,
162+ Snapshotted<BSONObj>* out) const {
175163 dassert (txn->lockState ()->isCollectionLockedForMode (ns ().toString (), MODE_IS));
176164
177165 RecordData rd;
178166 if ( !_recordStore->findRecord ( txn, loc, &rd ) )
179167 return false ;
180- *out = rd.releaseToBson ();
168+ *out = Snapshotted<BSONObj>(txn-> recoveryUnit ()-> getSnapshotId (), rd.releaseToBson () );
181169 return true ;
182170 }
183171
@@ -200,7 +188,7 @@ namespace mongo {
200188 const BSONObj& docToInsert,
201189 bool enforceQuota ) {
202190
203- uint64_t txnId = txn->recoveryUnit ()->getMyTransactionCount ();
191+ const SnapshotId sid = txn->recoveryUnit ()->getSnapshotId ();
204192
205193 if ( _indexCatalog.findIdIndex ( txn ) ) {
206194 if ( docToInsert[" _id" ].eoo () ) {
@@ -211,7 +199,7 @@ namespace mongo {
211199 }
212200
213201 StatusWith<RecordId> res = _insertDocument ( txn, docToInsert, enforceQuota );
214- invariant ( txnId == txn->recoveryUnit ()->getMyTransactionCount () );
202+ invariant ( sid == txn->recoveryUnit ()->getSnapshotId () );
215203 return res;
216204 }
217205
@@ -294,21 +282,21 @@ namespace mongo {
294282 return ;
295283 }
296284
297- BSONObj doc = docFor ( txn, loc );
285+ Snapshotted< BSONObj> doc = docFor (txn, loc);
298286
299- if ( deletedId ) {
300- BSONElement e = doc[" _id" ];
301- if ( e.type () ) {
287+ if (deletedId) {
288+ BSONElement e = doc. value () [" _id" ];
289+ if (e.type ()) {
302290 *deletedId = e.wrap ();
303291 }
304292 }
305293
306294 /* check if any cursors point to us. if so, advance them. */
307295 _cursorManager.invalidateDocument (txn, loc, INVALIDATION_DELETION);
308296
309- _indexCatalog.unindexRecord (txn, doc, loc, noWarn);
297+ _indexCatalog.unindexRecord (txn, doc. value () , loc, noWarn);
310298
311- _recordStore->deleteRecord ( txn, loc );
299+ _recordStore->deleteRecord (txn, loc);
312300
313301 _infoCache.notifyOfWriteOp ();
314302 }
@@ -318,16 +306,17 @@ namespace mongo {
318306
319307 StatusWith<RecordId> Collection::updateDocument ( OperationContext* txn,
320308 const RecordId& oldLocation,
321- const BSONObj& objOld,
309+ const Snapshotted< BSONObj> & objOld,
322310 const BSONObj& objNew,
323311 bool enforceQuota,
324312 bool indexesAffected,
325313 OpDebug* debug ) {
326314 dassert (txn->lockState ()->isCollectionLockedForMode (ns ().toString (), MODE_IX));
315+ invariant (objOld.snapshotId () == txn->recoveryUnit ()->getSnapshotId ());
327316
328- uint64_t txnId = txn->recoveryUnit ()->getMyTransactionCount ();
317+ SnapshotId sid = txn->recoveryUnit ()->getSnapshotId ();
329318
330- BSONElement oldId = objOld[" _id" ];
319+ BSONElement oldId = objOld. value () [" _id" ];
331320 if ( !oldId.eoo () && ( oldId != objNew[" _id" ] ) )
332321 return StatusWith<RecordId>( ErrorCodes::InternalError,
333322 " in Collection::updateDocument _id mismatch" ,
@@ -350,8 +339,12 @@ namespace mongo {
350339 || repl::getGlobalReplicationCoordinator ()->shouldIgnoreUniqueIndex (descriptor);
351340 UpdateTicket* updateTicket = new UpdateTicket ();
352341 updateTickets.mutableMap ()[descriptor] = updateTicket;
353- Status ret = iam->validateUpdate (
354- txn, objOld, objNew, oldLocation, options, updateTicket );
342+ Status ret = iam->validateUpdate (txn,
343+ objOld.value (),
344+ objNew,
345+ oldLocation,
346+ options,
347+ updateTicket);
355348 if ( !ret.isOK () ) {
356349 return StatusWith<RecordId>( ret );
357350 }
@@ -389,7 +382,7 @@ namespace mongo {
389382 Status s = _indexCatalog.indexRecord (txn, objNew, newLocation.getValue ());
390383 if (!s.isOK ())
391384 return StatusWith<RecordId>(s);
392- invariant ( txnId == txn->recoveryUnit ()->getMyTransactionCount () );
385+ invariant ( sid == txn->recoveryUnit ()->getSnapshotId () );
393386 return newLocation;
394387 }
395388
@@ -414,7 +407,7 @@ namespace mongo {
414407 }
415408 }
416409
417- invariant ( txnId == txn->recoveryUnit ()->getMyTransactionCount () );
410+ invariant ( sid == txn->recoveryUnit ()->getSnapshotId () );
418411 return newLocation;
419412 }
420413
@@ -438,15 +431,16 @@ namespace mongo {
438431
439432 Status Collection::updateDocumentWithDamages ( OperationContext* txn,
440433 const RecordId& loc,
441- const RecordData& oldRec,
434+ const Snapshotted< RecordData> & oldRec,
442435 const char * damageSource,
443436 const mutablebson::DamageVector& damages ) {
444437 dassert (txn->lockState ()->isCollectionLockedForMode (ns ().toString (), MODE_IX));
438+ invariant (oldRec.snapshotId () == txn->recoveryUnit ()->getSnapshotId ());
445439
446440 // Broadcast the mutation so that query results stay correct.
447441 _cursorManager.invalidateDocument (txn, loc, INVALIDATION_MUTATION);
448442
449- return _recordStore->updateWithDamages ( txn, loc, oldRec, damageSource, damages );
443+ return _recordStore->updateWithDamages (txn, loc, oldRec. value () , damageSource, damages);
450444 }
451445
452446 bool Collection::_enforceQuota ( bool userEnforeQuota ) const {
0 commit comments