summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/mmap_v1/diskloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/diskloc.h')
-rw-r--r--src/mongo/db/storage/mmap_v1/diskloc.h271
1 files changed, 149 insertions, 122 deletions
diff --git a/src/mongo/db/storage/mmap_v1/diskloc.h b/src/mongo/db/storage/mmap_v1/diskloc.h
index 9d3adc64da7..662daf074d5 100644
--- a/src/mongo/db/storage/mmap_v1/diskloc.h
+++ b/src/mongo/db/storage/mmap_v1/diskloc.h
@@ -43,149 +43,176 @@
namespace mongo {
- template< class Version > class BtreeBucket;
+template <class Version>
+class BtreeBucket;
#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 _a; // this will be volume, file #, etc. but is a logical value could be anything depending on storage engine
- int ofs;
-
- public:
-
- enum SentinelValues {
- /* note NullOfs is different. todo clean up. see refs to NullOfs in code - use is valid but outside DiskLoc context so confusing as-is. */
- NullOfs = -1,
-
- // Caps the number of files that may be allocated in a database, allowing about 32TB of
- // data per db. Note that the DiskLoc and DiskLoc56Bit types supports more files than
- // this value, as does the data storage format.
- MaxFiles=16000,
-
- // How invalid DiskLocs are represented in RecordIds.
- InvalidRepr = -2LL,
- };
-
- DiskLoc(int a, int Ofs) : _a(a), ofs(Ofs) { }
- DiskLoc() { Null(); }
-
- // Minimum allowed DiskLoc. No MmapV1RecordHeader may begin at this location because file and extent
- // headers must precede Records in a file.
- static DiskLoc min() { return DiskLoc(0, 0); }
-
- // Maximum allowed DiskLoc.
- // No MmapV1RecordHeader may begin at this location because the minimum size of a MmapV1RecordHeader is larger than
- // one byte. Also, the last bit is not able to be used because mmapv1 uses that for "used".
- static DiskLoc max() { return DiskLoc(0x7fffffff, 0x7ffffffe); }
-
- bool questionable() const {
- return ofs < -1 ||
- _a < -1 ||
- _a > 524288;
- }
+/** 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 _a; // this will be volume, file #, etc. but is a logical value could be anything depending on storage engine
+ int ofs;
+
+public:
+ enum SentinelValues {
+ /* note NullOfs is different. todo clean up. see refs to NullOfs in code - use is valid but outside DiskLoc context so confusing as-is. */
+ NullOfs = -1,
+
+ // Caps the number of files that may be allocated in a database, allowing about 32TB of
+ // data per db. Note that the DiskLoc and DiskLoc56Bit types supports more files than
+ // this value, as does the data storage format.
+ MaxFiles = 16000,
+
+ // How invalid DiskLocs are represented in RecordIds.
+ InvalidRepr = -2LL,
+ };
- bool isNull() const { return _a == -1; }
- DiskLoc& Null() {
- _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. */
- return *this;
- }
- void assertOk() const { verify(!isNull()); }
- DiskLoc& setInvalid() {
- _a = -2;
- ofs = 0;
- return *this;
- }
- bool isValid() const { return _a != -2; }
-
- std::string toString() const {
- if ( isNull() )
- return "null";
- std::stringstream ss;
- ss << _a << ':' << std::hex << ofs;
- return ss.str();
- }
+ DiskLoc(int a, int Ofs) : _a(a), ofs(Ofs) {}
+ DiskLoc() {
+ Null();
+ }
- BSONObj toBSONObj() const { return BSON( "file" << _a << "offset" << ofs ); }
+ // Minimum allowed DiskLoc. No MmapV1RecordHeader may begin at this location because file and extent
+ // headers must precede Records in a file.
+ static DiskLoc min() {
+ return DiskLoc(0, 0);
+ }
- int a() const { return _a; }
+ // Maximum allowed DiskLoc.
+ // No MmapV1RecordHeader may begin at this location because the minimum size of a MmapV1RecordHeader is larger than
+ // one byte. Also, the last bit is not able to be used because mmapv1 uses that for "used".
+ static DiskLoc max() {
+ return DiskLoc(0x7fffffff, 0x7ffffffe);
+ }
- int& GETOFS() { return ofs; }
- int getOfs() const { return ofs; }
- void set(int a, int b) {
- _a=a;
- ofs=b;
- }
+ bool questionable() const {
+ return ofs < -1 || _a < -1 || _a > 524288;
+ }
- void inc(int amt) {
- verify( !isNull() );
- ofs += amt;
- }
+ bool isNull() const {
+ return _a == -1;
+ }
+ DiskLoc& Null() {
+ _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. */
+ return *this;
+ }
+ void assertOk() const {
+ verify(!isNull());
+ }
+ DiskLoc& setInvalid() {
+ _a = -2;
+ ofs = 0;
+ return *this;
+ }
+ bool isValid() const {
+ return _a != -2;
+ }
- bool sameFile(DiskLoc b) {
- return _a== b._a;
- }
+ std::string toString() const {
+ if (isNull())
+ return "null";
+ std::stringstream ss;
+ ss << _a << ':' << std::hex << ofs;
+ return ss.str();
+ }
- bool operator==(const DiskLoc& b) const {
- return _a==b._a&& ofs == b.ofs;
- }
- bool operator!=(const DiskLoc& b) const {
- return !(*this==b);
- }
- int compare(const DiskLoc& b) const {
- int x = _a - b._a;
- if ( x )
- return x;
- return ofs - b.ofs;
- }
+ BSONObj toBSONObj() const {
+ return BSON("file" << _a << "offset" << ofs);
+ }
- static DiskLoc fromRecordId(RecordId id) {
- if (id.isNormal())
- return DiskLoc((id.repr() >> 32), uint32_t(id.repr()));
+ int a() const {
+ return _a;
+ }
- if (id.isNull())
- return DiskLoc();
+ int& GETOFS() {
+ return ofs;
+ }
+ int getOfs() const {
+ return ofs;
+ }
+ void set(int a, int b) {
+ _a = a;
+ ofs = b;
+ }
- if (id == RecordId::max())
- return DiskLoc::max();
+ void inc(int amt) {
+ verify(!isNull());
+ ofs += amt;
+ }
- if (id == RecordId::min())
- return DiskLoc::min();
+ bool sameFile(DiskLoc b) {
+ return _a == b._a;
+ }
- dassert(id.repr() == InvalidRepr);
- return DiskLoc().setInvalid();
- }
+ bool operator==(const DiskLoc& b) const {
+ return _a == b._a && ofs == b.ofs;
+ }
+ bool operator!=(const DiskLoc& b) const {
+ return !(*this == b);
+ }
+ int compare(const DiskLoc& b) const {
+ int x = _a - b._a;
+ if (x)
+ return x;
+ return ofs - b.ofs;
+ }
+
+ static DiskLoc fromRecordId(RecordId id) {
+ if (id.isNormal())
+ return DiskLoc((id.repr() >> 32), uint32_t(id.repr()));
- RecordId toRecordId() const {
- if (_a >= 0) {
- if (*this == DiskLoc::min())
- return RecordId::min();
+ if (id.isNull())
+ return DiskLoc();
- if (*this == DiskLoc::max())
- return RecordId::max();
+ if (id == RecordId::max())
+ return DiskLoc::max();
- return RecordId(uint64_t(_a) << 32 | uint32_t(ofs));
- }
+ if (id == RecordId::min())
+ return DiskLoc::min();
+
+ dassert(id.repr() == InvalidRepr);
+ return DiskLoc().setInvalid();
+ }
- if (isNull())
- return RecordId();
+ RecordId toRecordId() const {
+ if (_a >= 0) {
+ if (*this == DiskLoc::min())
+ return RecordId::min();
- dassert(!isValid());
- return RecordId(InvalidRepr);
+ if (*this == DiskLoc::max())
+ return RecordId::max();
+
+ return RecordId(uint64_t(_a) << 32 | uint32_t(ofs));
}
- };
-#pragma pack()
- inline bool operator< (const DiskLoc& rhs, const DiskLoc& lhs) { return rhs.compare(lhs) < 0; }
- inline bool operator<=(const DiskLoc& rhs, const DiskLoc& lhs) { return rhs.compare(lhs) <= 0; }
- inline bool operator> (const DiskLoc& rhs, const DiskLoc& lhs) { return rhs.compare(lhs) > 0; }
- inline bool operator>=(const DiskLoc& rhs, const DiskLoc& lhs) { return rhs.compare(lhs) >= 0; }
+ if (isNull())
+ return RecordId();
- inline std::ostream& operator<<( std::ostream &stream, const DiskLoc &loc ) {
- return stream << loc.toString();
+ dassert(!isValid());
+ return RecordId(InvalidRepr);
}
+};
+#pragma pack()
-} // namespace mongo
+inline bool operator<(const DiskLoc& rhs, const DiskLoc& lhs) {
+ return rhs.compare(lhs) < 0;
+}
+inline bool operator<=(const DiskLoc& rhs, const DiskLoc& lhs) {
+ return rhs.compare(lhs) <= 0;
+}
+inline bool operator>(const DiskLoc& rhs, const DiskLoc& lhs) {
+ return rhs.compare(lhs) > 0;
+}
+inline bool operator>=(const DiskLoc& rhs, const DiskLoc& lhs) {
+ return rhs.compare(lhs) >= 0;
+}
+
+inline std::ostream& operator<<(std::ostream& stream, const DiskLoc& loc) {
+ return stream << loc.toString();
+}
+
+} // namespace mongo