diff options
Diffstat (limited to 'db/diskloc.h')
-rw-r--r-- | db/diskloc.h | 101 |
1 files changed, 48 insertions, 53 deletions
diff --git a/db/diskloc.h b/db/diskloc.h index 2747abd..f356c73 100644 --- a/db/diskloc.h +++ b/db/diskloc.h @@ -14,7 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* storage.h +/* @file diskloc.h Storage subsystem management. Lays out our datafiles on disk, manages disk space. @@ -26,7 +26,6 @@ namespace mongo { - class Record; class DeletedRecord; class Extent; @@ -34,77 +33,64 @@ namespace mongo { class MongoDataFile; #pragma pack(1) + /** represents a disk location/offset on disk in a database. 64 bits. + it is assumed these will be passed around by value a lot so don't do anything to make them large + (such as adding a virtual function) + */ class DiskLoc { - int fileNo; /* this will be volume, file #, etc. */ + int _a; // this will be volume, file #, etc. but is a logical value could be anything depending on storage engine int ofs; + public: - // Note: MaxFiles imposes a limit of about 32TB of data per process - enum SentinelValues { MaxFiles=16000, NullOfs = -1 }; - int a() const { - return fileNo; - } + enum SentinelValues { + NullOfs = -1, + MaxFiles=16000 // thus a limit of about 32TB of data per db + }; - DiskLoc(int a, int b) : fileNo(a), ofs(b) { - //assert(ofs!=0); - } + DiskLoc(int a, int b) : _a(a), ofs(b) { } DiskLoc() { Null(); } DiskLoc(const DiskLoc& l) { - fileNo=l.fileNo; + _a=l._a; ofs=l.ofs; } - bool questionable() { + bool questionable() const { return ofs < -1 || - fileNo < -1 || - fileNo > 524288; + _a < -1 || + _a > 524288; } - bool isNull() const { - return fileNo == -1; - // return ofs == NullOfs; - } + bool isNull() const { return _a == -1; } void Null() { - fileNo = -1; - ofs = 0; - } - void assertOk() { - assert(!isNull()); + _a = -1; + ofs = 0; /* note NullOfs is different. todo clean up. see refs to NullOfs in code - use is valid but outside DiskLoc context so confusing as-is. */ } + void assertOk() { assert(!isNull()); } void setInvalid() { - fileNo = -2; + _a = -2; ofs = 0; } - bool isValid() const { - return fileNo != -2; - } + bool isValid() const { return _a != -2; } string toString() const { if ( isNull() ) return "null"; stringstream ss; - ss << hex << fileNo << ':' << ofs; + ss << hex << _a << ':' << ofs; return ss.str(); } - BSONObj toBSONObj() const { - return BSON( "file" << fileNo << "offset" << ofs ); - } + BSONObj toBSONObj() const { return BSON( "file" << _a << "offset" << ofs ); } - int& GETOFS() { - return ofs; - } - int getOfs() const { - return ofs; - } + int a() const { return _a; } + + int& GETOFS() { return ofs; } + int getOfs() const { return ofs; } void set(int a, int b) { - fileNo=a; + _a=a; ofs=b; } - void setOfs(int _fileNo, int _ofs) { - fileNo = _fileNo; - ofs = _ofs; - } void inc(int amt) { assert( !isNull() ); @@ -112,23 +98,23 @@ namespace mongo { } bool sameFile(DiskLoc b) { - return fileNo == b.fileNo; + return _a== b._a; } bool operator==(const DiskLoc& b) const { - return fileNo==b.fileNo && ofs == b.ofs; + return _a==b._a&& ofs == b.ofs; } bool operator!=(const DiskLoc& b) const { return !(*this==b); } const DiskLoc& operator=(const DiskLoc& b) { - fileNo=b.fileNo; + _a=b._a; ofs = b.ofs; //assert(ofs!=0); return *this; } int compare(const DiskLoc& b) const { - int x = fileNo - b.fileNo; + int x = _a - b._a; if ( x ) return x; return ofs - b.ofs; @@ -137,18 +123,27 @@ namespace mongo { return compare(b) < 0; } - /* get the "thing" associated with this disk location. - it is assumed the object is what it is -- you must asure that: - think of this as an unchecked type cast. + /** + * Marks this disk loc for writing + * @returns a non const reference to this disk loc + * This function explicitly signals we are writing and casts away const + */ + DiskLoc& writing() const; // see dur.h + + /* Get the "thing" associated with this disk location. + it is assumed the object is what you say it is -- you must assure that + (think of this as an unchecked type cast) + Note: set your Context first so that the database to which the diskloc applies is known. */ BSONObj obj() const; Record* rec() const; DeletedRecord* drec() const; Extent* ext() const; - BtreeBucket* btree() const; - BtreeBucket* btreemod() const; // marks modified / dirty + const BtreeBucket* btree() const; + // Explicitly signals we are writing and casts away const + BtreeBucket* btreemod() const; - MongoDataFile& pdf() const; + /*MongoDataFile& pdf() const;*/ }; #pragma pack() |