Storage Engine API
record.h
Go to the documentation of this file.
1 // database.h
2 
31 #pragma once
32 
33 #include "mongo/base/static_assert.h"
34 #include "mongo/bson/bsonobjbuilder.h"
37 #include "mongo/platform/atomic_word.h"
38 
39 namespace mongo {
40 
41 class DeletedRecord;
42 
43 /* MmapV1RecordHeader is a record in a datafile. DeletedRecord is similar but for deleted space.
44 
45 *11:03:20 AM) dm10gen: regarding extentOfs...
46 (11:03:42 AM) dm10gen: an extent is a continugous disk area, which contains many Records and
47  DeleteRecords
48 (11:03:56 AM) dm10gen: a DiskLoc has two pieces, the fileno and ofs. (64 bit total)
49 (11:04:16 AM) dm10gen: to keep the headesr small, instead of storing a 64 bit ptr to the full extent
50  address, we keep just the offset
51 (11:04:29 AM) dm10gen: we can do this as we know the record's address, and it has the same fileNo
52 (11:04:33 AM) dm10gen: see class DiskLoc for more info
53 (11:04:43 AM) dm10gen: so that is how MmapV1RecordHeader::myExtent() works
54 (11:04:53 AM) dm10gen: on an alloc(), when we build a new MmapV1RecordHeader, we must populate its
55  extentOfs then
56 */
57 #pragma pack(1)
59 public:
60  enum HeaderSizeValue { HeaderSize = 16 };
61 
62  int lengthWithHeaders() const {
63  return _lengthWithHeaders;
64  }
66  return _lengthWithHeaders;
67  }
68 
69  int extentOfs() const {
70  return _extentOfs;
71  }
72  int& extentOfs() {
73  return _extentOfs;
74  }
75 
76  int nextOfs() const {
77  return _nextOfs;
78  }
79  int& nextOfs() {
80  return _nextOfs;
81  }
82 
83  int prevOfs() const {
84  return _prevOfs;
85  }
86  int& prevOfs() {
87  return _prevOfs;
88  }
89 
90  const char* data() const {
91  return _data;
92  }
93  char* data() {
94  return _data;
95  }
96 
97  // XXX remove
98  const char* dataNoThrowing() const {
99  return _data;
100  }
101  char* dataNoThrowing() {
102  return _data;
103  }
104 
105  int netLength() const {
106  return _netLength();
107  }
108 
109  /* use this when a record is deleted. basically a union with next/prev fields */
111  return *((DeletedRecord*)this);
112  }
113 
114  DiskLoc myExtentLoc(const DiskLoc& myLoc) const {
115  return DiskLoc(myLoc.a(), extentOfs());
116  }
117 
118  struct NP {
119  int nextOfs;
120  int prevOfs;
121  };
122 
123  NP* np() {
124  return (NP*)&_nextOfs;
125  }
126 
128  return RecordData(_data, _netLength());
129  }
130 
131 private:
132  int _netLength() const {
134  }
135 
138  int _nextOfs;
139  int _prevOfs;
140 
142  char _data[4];
143 
144 public:
146 };
147 #pragma pack()
148 
149 // TODO: this probably moves to record_store.h
151 public:
152  int lengthWithHeaders() const {
153  return _lengthWithHeaders;
154  }
156  return _lengthWithHeaders;
157  }
158 
159  int extentOfs() const {
160  return _extentOfs;
161  }
162  int& extentOfs() {
163  return _extentOfs;
164  }
165 
166  // TODO: we need to not const_cast here but problem is DiskLoc::writing
167  DiskLoc& nextDeleted() const {
168  return const_cast<DiskLoc&>(_nextDeleted);
169  }
170 
171 private:
173 
175 
177 };
178 
179 MONGO_STATIC_ASSERT(16 == sizeof(DeletedRecord));
180 
181 } // namespace mongo
int & lengthWithHeaders()
Definition: record.h:65
int & extentOfs()
Definition: record.h:162
int prevOfs
Definition: record.h:120
char * dataNoThrowing()
Definition: record.h:101
const char * dataNoThrowing() const
Definition: record.h:98
DiskLoc & nextDeleted() const
Definition: record.h:167
int lengthWithHeaders() const
Definition: record.h:62
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
A replacement for the Record class.
Definition: record_data.h:43
int extentOfs() const
Definition: record.h:159
RecordData toRecordData() const
Definition: record.h:127
int netLength() const
Definition: record.h:105
int & nextOfs()
Definition: record.h:79
DeletedRecord & asDeleted()
Definition: record.h:110
int _extentOfs
Definition: record.h:137
int _lengthWithHeaders
Definition: record.h:172
int extentOfs() const
Definition: record.h:69
NP * np()
Definition: record.h:123
char _data[4]
be careful when referencing this that your write intent was correct
Definition: record.h:142
MONGO_STATIC_ASSERT(sizeof(void *)==sizeof(size_t))
represents a disk location/offset on disk in a database.
Definition: diskloc.h:53
int & lengthWithHeaders()
Definition: record.h:155
int _prevOfs
Definition: record.h:139
HeaderSizeValue
Definition: record.h:60
static bool MemoryTrackingEnabled
Definition: record.h:145
Definition: record.h:58
Definition: record.h:150
int _netLength() const
Definition: record.h:132
Definition: record.h:118
char * data()
Definition: record.h:93
const char * data() const
Definition: record.h:90
int & extentOfs()
Definition: record.h:72
int prevOfs() const
Definition: record.h:83
int _nextOfs
Definition: record.h:138
int nextOfs() const
Definition: record.h:76
DiskLoc _nextDeleted
Definition: record.h:176
int _lengthWithHeaders
Definition: record.h:136
DiskLoc myExtentLoc(const DiskLoc &myLoc) const
Definition: record.h:114
int a() const
Definition: diskloc.h:131
int lengthWithHeaders() const
Definition: record.h:152
int nextOfs
Definition: record.h:119
int _extentOfs
Definition: record.h:174
int & prevOfs()
Definition: record.h:86