From 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 Mon Sep 17 00:00:00 2001 From: Mark Benvenuto Date: Sat, 20 Jun 2015 00:22:50 -0400 Subject: SERVER-18579: Clang-Format - reformat code, no comment reflow --- .../db/storage/mmap_v1/record_store_v1_base.h | 471 +++++++++++---------- 1 file changed, 239 insertions(+), 232 deletions(-) (limited to 'src/mongo/db/storage/mmap_v1/record_store_v1_base.h') diff --git a/src/mongo/db/storage/mmap_v1/record_store_v1_base.h b/src/mongo/db/storage/mmap_v1/record_store_v1_base.h index 4e1aa8de338..5c0437cce56 100644 --- a/src/mongo/db/storage/mmap_v1/record_store_v1_base.h +++ b/src/mongo/db/storage/mmap_v1/record_store_v1_base.h @@ -38,312 +38,319 @@ namespace mongo { - class DeletedRecord; - class DocWriter; - class ExtentManager; - class MmapV1RecordHeader; - class OperationContext; +class DeletedRecord; +class DocWriter; +class ExtentManager; +class MmapV1RecordHeader; +class OperationContext; - struct Extent; +struct Extent; - class RecordStoreV1MetaData { - public: - virtual ~RecordStoreV1MetaData(){} +class RecordStoreV1MetaData { +public: + virtual ~RecordStoreV1MetaData() {} - virtual const DiskLoc& capExtent() const = 0; - virtual void setCapExtent( OperationContext* txn, const DiskLoc& loc ) = 0; + virtual const DiskLoc& capExtent() const = 0; + virtual void setCapExtent(OperationContext* txn, const DiskLoc& loc) = 0; - virtual const DiskLoc& capFirstNewRecord() const = 0; - virtual void setCapFirstNewRecord( OperationContext* txn, const DiskLoc& loc ) = 0; + virtual const DiskLoc& capFirstNewRecord() const = 0; + virtual void setCapFirstNewRecord(OperationContext* txn, const DiskLoc& loc) = 0; - bool capLooped() const { return capFirstNewRecord().isValid(); } + bool capLooped() const { + return capFirstNewRecord().isValid(); + } - virtual long long dataSize() const = 0; - virtual long long numRecords() const = 0; + virtual long long dataSize() const = 0; + virtual long long numRecords() const = 0; - virtual void incrementStats( OperationContext* txn, - long long dataSizeIncrement, - long long numRecordsIncrement ) = 0; + virtual void incrementStats(OperationContext* txn, + long long dataSizeIncrement, + long long numRecordsIncrement) = 0; - virtual void setStats( OperationContext* txn, - long long dataSize, - long long numRecords ) = 0; + virtual void setStats(OperationContext* txn, long long dataSize, long long numRecords) = 0; - virtual DiskLoc deletedListEntry( int bucket ) const = 0; - virtual void setDeletedListEntry( OperationContext* txn, - int bucket, - const DiskLoc& loc ) = 0; + virtual DiskLoc deletedListEntry(int bucket) const = 0; + virtual void setDeletedListEntry(OperationContext* txn, int bucket, const DiskLoc& loc) = 0; - virtual DiskLoc deletedListLegacyGrabBag() const = 0; - virtual void setDeletedListLegacyGrabBag(OperationContext* txn, const DiskLoc& loc) = 0; + virtual DiskLoc deletedListLegacyGrabBag() const = 0; + virtual void setDeletedListLegacyGrabBag(OperationContext* txn, const DiskLoc& loc) = 0; - virtual void orphanDeletedList(OperationContext* txn) = 0; + virtual void orphanDeletedList(OperationContext* txn) = 0; - virtual const DiskLoc& firstExtent( OperationContext* txn ) const = 0; - virtual void setFirstExtent( OperationContext* txn, const DiskLoc& loc ) = 0; + virtual const DiskLoc& firstExtent(OperationContext* txn) const = 0; + virtual void setFirstExtent(OperationContext* txn, const DiskLoc& loc) = 0; - virtual const DiskLoc& lastExtent( OperationContext* txn ) const = 0; - virtual void setLastExtent( OperationContext* txn, const DiskLoc& loc ) = 0; + virtual const DiskLoc& lastExtent(OperationContext* txn) const = 0; + virtual void setLastExtent(OperationContext* txn, const DiskLoc& loc) = 0; - virtual bool isCapped() const = 0; + virtual bool isCapped() const = 0; - virtual bool isUserFlagSet( int flag ) const = 0; - virtual int userFlags() const = 0; - virtual bool setUserFlag( OperationContext* txn, int flag ) = 0; - virtual bool clearUserFlag( OperationContext* txn, int flag ) = 0; - virtual bool replaceUserFlags( OperationContext* txn, int flags ) = 0; + virtual bool isUserFlagSet(int flag) const = 0; + virtual int userFlags() const = 0; + virtual bool setUserFlag(OperationContext* txn, int flag) = 0; + virtual bool clearUserFlag(OperationContext* txn, int flag) = 0; + virtual bool replaceUserFlags(OperationContext* txn, int flags) = 0; - virtual int lastExtentSize( OperationContext* txn) const = 0; - virtual void setLastExtentSize( OperationContext* txn, int newMax ) = 0; + virtual int lastExtentSize(OperationContext* txn) const = 0; + virtual void setLastExtentSize(OperationContext* txn, int newMax) = 0; - virtual long long maxCappedDocs() const = 0; - - }; + virtual long long maxCappedDocs() const = 0; +}; +/** + * Class that stores active cursors that have been saved (as part of yielding) to + * allow them to be invalidated if the thing they pointed at goes away. The registry is + * thread-safe, as readers may concurrently register and remove their cursors. Contention is + * expected to be very low, as yielding is infrequent. This logically belongs to the + * RecordStore, but is not contained in it to facilitate unit testing. + */ +class SavedCursorRegistry { +public: /** - * Class that stores active cursors that have been saved (as part of yielding) to - * allow them to be invalidated if the thing they pointed at goes away. The registry is - * thread-safe, as readers may concurrently register and remove their cursors. Contention is - * expected to be very low, as yielding is infrequent. This logically belongs to the - * RecordStore, but is not contained in it to facilitate unit testing. + * The destructor ensures the cursor is unregistered when an exception is thrown. + * Note that the SavedCursor may outlive the registry it was saved in. */ - class SavedCursorRegistry { - public: - /** - * The destructor ensures the cursor is unregistered when an exception is thrown. - * Note that the SavedCursor may outlive the registry it was saved in. - */ - struct SavedCursor { - SavedCursor() : _registry(NULL) { } - virtual ~SavedCursor() { if (_registry) _registry->unregisterCursor(this); } - DiskLoc bucket; - BSONObj key; - DiskLoc loc; - - private: - friend class SavedCursorRegistry; - // Non-null iff registered. Accessed by owner or writer with MODE_X collection lock - SavedCursorRegistry* _registry; - }; - - ~SavedCursorRegistry(); - - /** - * Adds given saved cursor to SavedCursorRegistry. Doesn't take ownership. - */ - void registerCursor(SavedCursor* cursor); - - /** - * Removes given saved cursor. Returns true if the cursor was still present, and false - * if it had already been removed due to invalidation. Doesn't take ownership. - */ - bool unregisterCursor(SavedCursor* cursor); - - /** - * When a btree-bucket disappears due to merge/split or similar, this invalidates all - * cursors that point at the same bucket by removing them from the registry. - */ - void invalidateCursorsForBucket(DiskLoc bucket); + struct SavedCursor { + SavedCursor() : _registry(NULL) {} + virtual ~SavedCursor() { + if (_registry) + _registry->unregisterCursor(this); + } + DiskLoc bucket; + BSONObj key; + DiskLoc loc; private: - SpinLock _mutex; - typedef unordered_set SavedCursorSet; // SavedCursor pointers not owned here - SavedCursorSet _cursors; + friend class SavedCursorRegistry; + // Non-null iff registered. Accessed by owner or writer with MODE_X collection lock + SavedCursorRegistry* _registry; }; - class RecordStoreV1Base : public RecordStore { - public: - - static const int Buckets = 26; - static const int MaxAllowedAllocation = 16*1024*1024 + 512*1024; + ~SavedCursorRegistry(); - static const int bucketSizes[]; + /** + * Adds given saved cursor to SavedCursorRegistry. Doesn't take ownership. + */ + void registerCursor(SavedCursor* cursor); - // ------------ + /** + * Removes given saved cursor. Returns true if the cursor was still present, and false + * if it had already been removed due to invalidation. Doesn't take ownership. + */ + bool unregisterCursor(SavedCursor* cursor); - class IntraExtentIterator; + /** + * When a btree-bucket disappears due to merge/split or similar, this invalidates all + * cursors that point at the same bucket by removing them from the registry. + */ + void invalidateCursorsForBucket(DiskLoc bucket); - /** - * @param details - takes ownership - * @param em - does NOT take ownership - */ - RecordStoreV1Base(StringData ns, - RecordStoreV1MetaData* details, - ExtentManager* em, - bool isSystemIndexes); +private: + SpinLock _mutex; + typedef unordered_set SavedCursorSet; // SavedCursor pointers not owned here + SavedCursorSet _cursors; +}; - virtual ~RecordStoreV1Base(); +class RecordStoreV1Base : public RecordStore { +public: + static const int Buckets = 26; + static const int MaxAllowedAllocation = 16 * 1024 * 1024 + 512 * 1024; - virtual long long dataSize( OperationContext* txn ) const { return _details->dataSize(); } - virtual long long numRecords( OperationContext* txn ) const { return _details->numRecords(); } + static const int bucketSizes[]; - virtual int64_t storageSize( OperationContext* txn, - BSONObjBuilder* extraInfo = NULL, - int level = 0 ) const; + // ------------ - virtual RecordData dataFor( OperationContext* txn, const RecordId& loc ) const; + class IntraExtentIterator; - virtual bool findRecord( OperationContext* txn, const RecordId& loc, RecordData* rd ) const; + /** + * @param details - takes ownership + * @param em - does NOT take ownership + */ + RecordStoreV1Base(StringData ns, + RecordStoreV1MetaData* details, + ExtentManager* em, + bool isSystemIndexes); - void deleteRecord( OperationContext* txn, - const RecordId& dl ); + virtual ~RecordStoreV1Base(); - StatusWith insertRecord( OperationContext* txn, - const char* data, - int len, - bool enforceQuota ); + virtual long long dataSize(OperationContext* txn) const { + return _details->dataSize(); + } + virtual long long numRecords(OperationContext* txn) const { + return _details->numRecords(); + } - StatusWith insertRecord( OperationContext* txn, - const DocWriter* doc, - bool enforceQuota ); + virtual int64_t storageSize(OperationContext* txn, + BSONObjBuilder* extraInfo = NULL, + int level = 0) const; - virtual StatusWith updateRecord( OperationContext* txn, - const RecordId& oldLocation, - const char* data, - int len, - bool enforceQuota, - UpdateNotifier* notifier ); + virtual RecordData dataFor(OperationContext* txn, const RecordId& loc) const; - virtual bool updateWithDamagesSupported() const; + virtual bool findRecord(OperationContext* txn, const RecordId& loc, RecordData* rd) const; - virtual Status updateWithDamages( OperationContext* txn, - const RecordId& loc, - const RecordData& oldRec, - const char* damageSource, - const mutablebson::DamageVector& damages ); + void deleteRecord(OperationContext* txn, const RecordId& dl); - virtual std::unique_ptr getCursorForRepair( OperationContext* txn ) const; + StatusWith insertRecord(OperationContext* txn, + const char* data, + int len, + bool enforceQuota); - void increaseStorageSize( OperationContext* txn, int size, bool enforceQuota ); + StatusWith insertRecord(OperationContext* txn, + const DocWriter* doc, + bool enforceQuota); - virtual Status validate( OperationContext* txn, - bool full, bool scanData, - ValidateAdaptor* adaptor, - ValidateResults* results, BSONObjBuilder* output ); + virtual StatusWith updateRecord(OperationContext* txn, + const RecordId& oldLocation, + const char* data, + int len, + bool enforceQuota, + UpdateNotifier* notifier); - virtual void appendCustomStats( OperationContext* txn, - BSONObjBuilder* result, - double scale ) const; + virtual bool updateWithDamagesSupported() const; - virtual Status touch( OperationContext* txn, BSONObjBuilder* output ) const; + virtual Status updateWithDamages(OperationContext* txn, + const RecordId& loc, + const RecordData& oldRec, + const char* damageSource, + const mutablebson::DamageVector& damages); - const RecordStoreV1MetaData* details() const { return _details.get(); } + virtual std::unique_ptr getCursorForRepair(OperationContext* txn) const; - // This keeps track of cursors saved during yielding, for invalidation purposes. - SavedCursorRegistry savedCursors; + void increaseStorageSize(OperationContext* txn, int size, bool enforceQuota); - DiskLoc getExtentLocForRecord( OperationContext* txn, const DiskLoc& loc ) const; + virtual Status validate(OperationContext* txn, + bool full, + bool scanData, + ValidateAdaptor* adaptor, + ValidateResults* results, + BSONObjBuilder* output); - DiskLoc getNextRecord( OperationContext* txn, const DiskLoc& loc ) const; - DiskLoc getPrevRecord( OperationContext* txn, const DiskLoc& loc ) const; + virtual void appendCustomStats(OperationContext* txn, + BSONObjBuilder* result, + double scale) const; - DiskLoc getNextRecordInExtent( OperationContext* txn, const DiskLoc& loc ) const; - DiskLoc getPrevRecordInExtent( OperationContext* txn, const DiskLoc& loc ) const; + virtual Status touch(OperationContext* txn, BSONObjBuilder* output) const; - /** - * Quantize 'minSize' to the nearest allocation size. - */ - static int quantizeAllocationSpace(int minSize); + const RecordStoreV1MetaData* details() const { + return _details.get(); + } - static bool isQuantized(int recordSize); + // This keeps track of cursors saved during yielding, for invalidation purposes. + SavedCursorRegistry savedCursors; - /* return which "deleted bucket" for this size object */ - static int bucket(int size); + DiskLoc getExtentLocForRecord(OperationContext* txn, const DiskLoc& loc) const; - virtual void updateStatsAfterRepair(OperationContext* txn, - long long numRecords, - long long dataSize) { - invariant(false); // MMAPv1 has its own repair which doesn't call this. - } - protected: + DiskLoc getNextRecord(OperationContext* txn, const DiskLoc& loc) const; + DiskLoc getPrevRecord(OperationContext* txn, const DiskLoc& loc) const; - virtual MmapV1RecordHeader* recordFor( const DiskLoc& loc ) const; + DiskLoc getNextRecordInExtent(OperationContext* txn, const DiskLoc& loc) const; + DiskLoc getPrevRecordInExtent(OperationContext* txn, const DiskLoc& loc) const; - const DeletedRecord* deletedRecordFor( const DiskLoc& loc ) const; + /** + * Quantize 'minSize' to the nearest allocation size. + */ + static int quantizeAllocationSpace(int minSize); - virtual bool isCapped() const = 0; + static bool isQuantized(int recordSize); - virtual bool shouldPadInserts() const = 0; + /* return which "deleted bucket" for this size object */ + static int bucket(int size); - virtual StatusWith allocRecord( OperationContext* txn, - int lengthWithHeaders, - bool enforceQuota ) = 0; + virtual void updateStatsAfterRepair(OperationContext* txn, + long long numRecords, + long long dataSize) { + invariant(false); // MMAPv1 has its own repair which doesn't call this. + } - // TODO: document, remove, what have you - virtual void addDeletedRec( OperationContext* txn, const DiskLoc& dloc) = 0; +protected: + virtual MmapV1RecordHeader* recordFor(const DiskLoc& loc) const; - // TODO: another sad one - virtual DeletedRecord* drec( const DiskLoc& loc ) const; + const DeletedRecord* deletedRecordFor(const DiskLoc& loc) const; - // just a wrapper for _extentManager->getExtent( loc ); - Extent* _getExtent( OperationContext* txn, const DiskLoc& loc ) const; + virtual bool isCapped() const = 0; - DiskLoc _getExtentLocForRecord( OperationContext* txn, const DiskLoc& loc ) const; + virtual bool shouldPadInserts() const = 0; - DiskLoc _getNextRecord( OperationContext* txn, const DiskLoc& loc ) const; - DiskLoc _getPrevRecord( OperationContext* txn, const DiskLoc& loc ) const; + virtual StatusWith allocRecord(OperationContext* txn, + int lengthWithHeaders, + bool enforceQuota) = 0; - DiskLoc _getNextRecordInExtent( OperationContext* txn, const DiskLoc& loc ) const; - DiskLoc _getPrevRecordInExtent( OperationContext* txn, const DiskLoc& loc ) const; + // TODO: document, remove, what have you + virtual void addDeletedRec(OperationContext* txn, const DiskLoc& dloc) = 0; - /** - * finds the first suitable DiskLoc for data - * will return the DiskLoc of a newly created DeletedRecord - */ - DiskLoc _findFirstSpot( OperationContext* txn, const DiskLoc& extDiskLoc, Extent* e ); + // TODO: another sad one + virtual DeletedRecord* drec(const DiskLoc& loc) const; - /** add a record to the end of the linked list chain within this extent. - require: you must have already declared write intent for the record header. - */ - void _addRecordToRecListInExtent(OperationContext* txn, MmapV1RecordHeader* r, DiskLoc loc); + // just a wrapper for _extentManager->getExtent( loc ); + Extent* _getExtent(OperationContext* txn, const DiskLoc& loc) const; - /** - * internal - * doesn't check inputs or change padding - */ - StatusWith _insertRecord( OperationContext* txn, - const char* data, - int len, - bool enforceQuota ); + DiskLoc _getExtentLocForRecord(OperationContext* txn, const DiskLoc& loc) const; - std::unique_ptr _details; - ExtentManager* _extentManager; - bool _isSystemIndexes; + DiskLoc _getNextRecord(OperationContext* txn, const DiskLoc& loc) const; + DiskLoc _getPrevRecord(OperationContext* txn, const DiskLoc& loc) const; - friend class RecordStoreV1RepairCursor; - }; + DiskLoc _getNextRecordInExtent(OperationContext* txn, const DiskLoc& loc) const; + DiskLoc _getPrevRecordInExtent(OperationContext* txn, const DiskLoc& loc) const; /** - * Iterates over all records within a single extent. - * - * EOF at end of extent, even if there are more extents. + * finds the first suitable DiskLoc for data + * will return the DiskLoc of a newly created DeletedRecord */ - class RecordStoreV1Base::IntraExtentIterator final : public RecordCursor { - public: - IntraExtentIterator(OperationContext* txn, - DiskLoc start, - const RecordStoreV1Base* rs, - bool forward = true) - : _txn(txn), _curr(start), _rs(rs), _forward(forward) {} - - boost::optional next() final; - boost::optional seekExact(const RecordId& id) final; - void invalidate(const RecordId& dl) final; - void savePositioned() final {} - bool restore(OperationContext* txn) final { return true; } - std::unique_ptr fetcherForNext() const final; + DiskLoc _findFirstSpot(OperationContext* txn, const DiskLoc& extDiskLoc, Extent* e); - private: - virtual const MmapV1RecordHeader* recordFor( const DiskLoc& loc ) const { - return _rs->recordFor(loc); - } + /** add a record to the end of the linked list chain within this extent. + require: you must have already declared write intent for the record header. + */ + void _addRecordToRecListInExtent(OperationContext* txn, MmapV1RecordHeader* r, DiskLoc loc); + + /** + * internal + * doesn't check inputs or change padding + */ + StatusWith _insertRecord(OperationContext* txn, + const char* data, + int len, + bool enforceQuota); - void advance(); + std::unique_ptr _details; + ExtentManager* _extentManager; + bool _isSystemIndexes; - OperationContext* _txn; - DiskLoc _curr; - const RecordStoreV1Base* _rs; - bool _forward; - }; + friend class RecordStoreV1RepairCursor; +}; +/** + * Iterates over all records within a single extent. + * + * EOF at end of extent, even if there are more extents. + */ +class RecordStoreV1Base::IntraExtentIterator final : public RecordCursor { +public: + IntraExtentIterator(OperationContext* txn, + DiskLoc start, + const RecordStoreV1Base* rs, + bool forward = true) + : _txn(txn), _curr(start), _rs(rs), _forward(forward) {} + + boost::optional next() final; + boost::optional seekExact(const RecordId& id) final; + void invalidate(const RecordId& dl) final; + void savePositioned() final {} + bool restore(OperationContext* txn) final { + return true; + } + std::unique_ptr fetcherForNext() const final; + +private: + virtual const MmapV1RecordHeader* recordFor(const DiskLoc& loc) const { + return _rs->recordFor(loc); + } + + void advance(); + + OperationContext* _txn; + DiskLoc _curr; + const RecordStoreV1Base* _rs; + bool _forward; +}; } -- cgit v1.2.1