00001 00017 /* @file diskloc.h 00018 00019 Storage subsystem management. 00020 Lays out our datafiles on disk, manages disk space. 00021 */ 00022 00023 #pragma once 00024 00025 #include "jsobj.h" 00026 00027 namespace mongo { 00028 00029 class Record; 00030 class DeletedRecord; 00031 class Extent; 00032 class BtreeBucket; 00033 class MongoDataFile; 00034 00035 #pragma pack(1) 00036 00040 class DiskLoc { 00041 int _a; // this will be volume, file #, etc. but is a logical value could be anything depending on storage engine 00042 int ofs; 00043 00044 public: 00045 00046 enum SentinelValues { 00047 NullOfs = -1, 00048 MaxFiles=16000 // thus a limit of about 32TB of data per db 00049 }; 00050 00051 DiskLoc(int a, int b) : _a(a), ofs(b) { } 00052 DiskLoc() { Null(); } 00053 DiskLoc(const DiskLoc& l) { 00054 _a=l._a; 00055 ofs=l.ofs; 00056 } 00057 00058 bool questionable() const { 00059 return ofs < -1 || 00060 _a < -1 || 00061 _a > 524288; 00062 } 00063 00064 bool isNull() const { return _a == -1; } 00065 void Null() { 00066 _a = -1; 00067 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. */ 00068 } 00069 void assertOk() { assert(!isNull()); } 00070 void setInvalid() { 00071 _a = -2; 00072 ofs = 0; 00073 } 00074 bool isValid() const { return _a != -2; } 00075 00076 string toString() const { 00077 if ( isNull() ) 00078 return "null"; 00079 stringstream ss; 00080 ss << hex << _a << ':' << ofs; 00081 return ss.str(); 00082 } 00083 00084 BSONObj toBSONObj() const { return BSON( "file" << _a << "offset" << ofs ); } 00085 00086 int a() const { return _a; } 00087 00088 int& GETOFS() { return ofs; } 00089 int getOfs() const { return ofs; } 00090 void set(int a, int b) { 00091 _a=a; 00092 ofs=b; 00093 } 00094 00095 void inc(int amt) { 00096 assert( !isNull() ); 00097 ofs += amt; 00098 } 00099 00100 bool sameFile(DiskLoc b) { 00101 return _a== b._a; 00102 } 00103 00104 bool operator==(const DiskLoc& b) const { 00105 return _a==b._a&& ofs == b.ofs; 00106 } 00107 bool operator!=(const DiskLoc& b) const { 00108 return !(*this==b); 00109 } 00110 const DiskLoc& operator=(const DiskLoc& b) { 00111 _a=b._a; 00112 ofs = b.ofs; 00113 //assert(ofs!=0); 00114 return *this; 00115 } 00116 int compare(const DiskLoc& b) const { 00117 int x = _a - b._a; 00118 if ( x ) 00119 return x; 00120 return ofs - b.ofs; 00121 } 00122 bool operator<(const DiskLoc& b) const { 00123 return compare(b) < 0; 00124 } 00125 00131 DiskLoc& writing() const; // see dur.h 00132 00133 /* Get the "thing" associated with this disk location. 00134 it is assumed the object is what you say it is -- you must assure that 00135 (think of this as an unchecked type cast) 00136 Note: set your Context first so that the database to which the diskloc applies is known. 00137 */ 00138 BSONObj obj() const; 00139 Record* rec() const; 00140 DeletedRecord* drec() const; 00141 Extent* ext() const; 00142 const BtreeBucket* btree() const; 00143 // Explicitly signals we are writing and casts away const 00144 BtreeBucket* btreemod() const; 00145 00146 /*MongoDataFile& pdf() const;*/ 00147 }; 00148 #pragma pack() 00149 00150 const DiskLoc minDiskLoc(0, 1); 00151 const DiskLoc maxDiskLoc(0x7fffffff, 0x7fffffff); 00152 00153 } // namespace mongo