Storage Engine API
mongo::RecordStoreV1RepairCursor Class Referencefinal

This iterator will go over the collection twice - once going forward (first extent -> last extent) and once backwards in an attempt to salvage potentially corrupted or unreachable records. More...

#include <record_store_v1_repair_iterator.h>

Inheritance diagram for mongo::RecordStoreV1RepairCursor:
mongo::RecordCursor

Detailed Description

This iterator will go over the collection twice - once going forward (first extent -> last extent) and once backwards in an attempt to salvage potentially corrupted or unreachable records.

It is used by the mongodump –repair option.

Public Member Functions

 RecordStoreV1RepairCursor (OperationContext *opCtx, const RecordStoreV1Base *recordStore)
 
boost::optional< Recordnext () final
 Moves forward and returns the new data or boost::none if there is no more data. More...
 
void invalidate (OperationContext *opCtx, const RecordId &dl)
 Inform the cursor that this id is being invalidated. More...
 
void save () final
 Prepares for state changes in underlying data in a way that allows the cursor's current position to be restored. More...
 
bool restore () final
 Recovers from potential state changes in underlying data. More...
 
void detachFromOperationContext () final
 Detaches from the OperationContext and releases any storage-engine state. More...
 
void reattachToOperationContext (OperationContext *opCtx) final
 Reattaches to the OperationContext and reacquires any storage-engine state. More...
 
- Public Member Functions inherited from mongo::RecordCursor
virtual ~RecordCursor ()=default
 
virtual std::unique_ptr< RecordFetcherfetcherForNext () const
 Returns a RecordFetcher if needed for a call to next() or none if unneeded. More...
 

Private Types

enum  Stage { FORWARD_SCAN = 0, BACKWARD_SCAN = 1, DONE = 2 }
 

Private Member Functions

void advance ()
 
bool _advanceToNextValidExtent ()
 Based on the direction of scan, finds the next valid (un-corrupted) extent in the chain and sets _currExtent to point to that. More...
 

Private Attributes

OperationContext * _opCtx
 
const RecordStoreV1Base_recordStore
 
DiskLoc _currExtent
 
DiskLoc _currRecord
 
Stage _stage
 
std::set< DiskLoc_seenInCurrentExtent
 

Member Enumeration Documentation

◆ Stage

Enumerator
FORWARD_SCAN 
BACKWARD_SCAN 
DONE 

Constructor & Destructor Documentation

◆ RecordStoreV1RepairCursor()

mongo::RecordStoreV1RepairCursor::RecordStoreV1RepairCursor ( OperationContext *  opCtx,
const RecordStoreV1Base recordStore 
)

Member Function Documentation

◆ _advanceToNextValidExtent()

bool mongo::RecordStoreV1RepairCursor::_advanceToNextValidExtent ( )
private

Based on the direction of scan, finds the next valid (un-corrupted) extent in the chain and sets _currExtent to point to that.

Returns
true if valid extent was found (_currExtent will not be null) false otherwise and _currExtent will be null

◆ advance()

void mongo::RecordStoreV1RepairCursor::advance ( )
private

◆ detachFromOperationContext()

void mongo::RecordStoreV1RepairCursor::detachFromOperationContext ( )
inlinefinalvirtual

Detaches from the OperationContext and releases any storage-engine state.

It is only legal to call this when in a "saved" state. While in the "detached" state, it is only legal to call reattachToOperationContext or the destructor. It is not legal to call detachFromOperationContext() while already in the detached state.

Implements mongo::RecordCursor.

◆ invalidate()

void mongo::RecordStoreV1RepairCursor::invalidate ( OperationContext *  opCtx,
const RecordId &  id 
)
virtual

Inform the cursor that this id is being invalidated.

Must be called between save and restore. The opCtx is that of the operation causing the invalidation, not the opCtx using the cursor.

WARNING: Storage engines other than MMAPv1 should use the default implementation, and not depend on this being called.

Reimplemented from mongo::RecordCursor.

◆ next()

boost::optional< Record > mongo::RecordStoreV1RepairCursor::next ( )
finalvirtual

Moves forward and returns the new data or boost::none if there is no more data.

Continues returning boost::none once it reaches EOF.

Implements mongo::RecordCursor.

◆ reattachToOperationContext()

void mongo::RecordStoreV1RepairCursor::reattachToOperationContext ( OperationContext *  opCtx)
inlinefinalvirtual

Reattaches to the OperationContext and reacquires any storage-engine state.

It is only legal to call this in the "detached" state. On return, the cursor is left in a "saved" state, so callers must still call restoreState to use this object.

Implements mongo::RecordCursor.

◆ restore()

bool mongo::RecordStoreV1RepairCursor::restore ( )
inlinefinalvirtual

Recovers from potential state changes in underlying data.

Returns false if it is invalid to continue using this iterator. This usually means that capped deletes have caught up to the position of this iterator and continuing could result in missed data.

If the former position no longer exists, but it is safe to continue iterating, the following call to next() will return the next closest position in the direction of the scan, if any.

This handles restoring after either save() or SeekableRecordCursor::saveUnpositioned().

Implements mongo::RecordCursor.

◆ save()

void mongo::RecordStoreV1RepairCursor::save ( )
inlinefinalvirtual

Prepares for state changes in underlying data in a way that allows the cursor's current position to be restored.

It is safe to call save multiple times in a row. No other method (excluding destructor) may be called until successfully restored.

Implements mongo::RecordCursor.

Member Data Documentation

◆ _currExtent

DiskLoc mongo::RecordStoreV1RepairCursor::_currExtent
private

◆ _currRecord

DiskLoc mongo::RecordStoreV1RepairCursor::_currRecord
private

◆ _opCtx

OperationContext* mongo::RecordStoreV1RepairCursor::_opCtx
private

◆ _recordStore

const RecordStoreV1Base* mongo::RecordStoreV1RepairCursor::_recordStore
private

◆ _seenInCurrentExtent

std::set<DiskLoc> mongo::RecordStoreV1RepairCursor::_seenInCurrentExtent
private

◆ _stage

Stage mongo::RecordStoreV1RepairCursor::_stage
private

The documentation for this class was generated from the following files: