Skip to content

Commit 2fc9bb1

Browse files
committed
SERVER-13638: RecordStore uses smaller ExtentManager api
1 parent 1442068 commit 2fc9bb1

File tree

10 files changed

+114
-33
lines changed

10 files changed

+114
-33
lines changed

src/mongo/db/catalog/collection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace mongo {
151151
}
152152

153153
BSONObj Collection::docFor( const DiskLoc& loc ) {
154-
Record* rec = getExtentManager()->recordFor( loc );
154+
Record* rec = _recordStore->recordFor( loc );
155155
return BSONObj( rec->accessed()->data() );
156156
}
157157

@@ -281,7 +281,7 @@ namespace mongo {
281281
bool enforceQuota,
282282
OpDebug* debug ) {
283283

284-
Record* oldRecord = getExtentManager()->recordFor( oldLocation );
284+
Record* oldRecord = _recordStore->recordFor( oldLocation );
285285
BSONObj objOld( oldRecord->accessed()->data() );
286286

287287
if ( objOld.hasElement( "_id" ) ) {

src/mongo/db/storage/extent_manager.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ namespace mongo {
199199
}
200200
}
201201

202-
Record* ExtentManager::recordFor( const DiskLoc& loc ) const {
202+
Record* ExtentManager::recordForV1( const DiskLoc& loc ) const {
203203
loc.assertOk();
204204
const DataFile* df = _getOpenFile( loc.a() );
205205

@@ -211,13 +211,13 @@ namespace mongo {
211211
return reinterpret_cast<Record*>( df->p() + ofs );
212212
}
213213

214-
DiskLoc ExtentManager::extentLocFor( const DiskLoc& loc ) const {
215-
Record* record = recordFor( loc );
214+
DiskLoc ExtentManager::extentLocForV1( const DiskLoc& loc ) const {
215+
Record* record = recordForV1( loc );
216216
return DiskLoc( loc.a(), record->extentOfs() );
217217
}
218218

219-
Extent* ExtentManager::extentFor( const DiskLoc& loc ) const {
220-
DiskLoc extentLoc = extentLocFor( loc );
219+
Extent* ExtentManager::extentForV1( const DiskLoc& loc ) const {
220+
DiskLoc extentLoc = extentLocForV1( loc );
221221
return getExtent( extentLoc );
222222
}
223223

@@ -231,7 +231,7 @@ namespace mongo {
231231

232232

233233
DiskLoc ExtentManager::getNextRecordInExtent( const DiskLoc& loc ) const {
234-
int nextOffset = recordFor( loc )->nextOfs();
234+
int nextOffset = recordForV1( loc )->nextOfs();
235235

236236
if ( nextOffset == DiskLoc::NullOfs )
237237
return DiskLoc();
@@ -247,7 +247,7 @@ namespace mongo {
247247

248248
// now traverse extents
249249

250-
Extent *e = extentFor(loc);
250+
Extent *e = extentForV1(loc);
251251
while ( 1 ) {
252252
if ( e->xnext.isNull() )
253253
return DiskLoc(); // end of collection
@@ -260,7 +260,7 @@ namespace mongo {
260260
}
261261

262262
DiskLoc ExtentManager::getPrevRecordInExtent( const DiskLoc& loc ) const {
263-
int prevOffset = recordFor( loc )->prevOfs();
263+
int prevOffset = recordForV1( loc )->prevOfs();
264264

265265
if ( prevOffset == DiskLoc::NullOfs )
266266
return DiskLoc();
@@ -276,7 +276,7 @@ namespace mongo {
276276

277277
// now traverse extents
278278

279-
Extent *e = extentFor(loc);
279+
Extent *e = extentForV1(loc);
280280
while ( 1 ) {
281281
if ( e->xprev.isNull() )
282282
return DiskLoc(); // end of collection

src/mongo/db/storage/extent_manager.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,24 @@ namespace mongo {
109109

110110
/**
111111
* @param loc - has to be for a specific Record
112-
* TODO(ERH): remove this - only RecordStore can do this
112+
* Note(erh): this sadly cannot be removed.
113+
* A Record DiskLoc has an offset from a file, while a RecordStore really wants an offset
114+
* from an extent. This intrinsically links an original record store to the original extent
115+
* manager.
113116
*/
114-
Record* recordFor( const DiskLoc& loc ) const;
117+
Record* recordForV1( const DiskLoc& loc ) const;
115118

116119
/**
117120
* @param loc - has to be for a specific Record (not an Extent)
118-
* TODO(ERH): remove this - only RecordStore can do this
121+
* Note(erh) see comment on recordFor
119122
*/
120-
Extent* extentFor( const DiskLoc& loc ) const;
123+
Extent* extentForV1( const DiskLoc& loc ) const;
121124

122125
/**
123126
* @param loc - has to be for a specific Record (not an Extent)
124-
* TODO(ERH): remove this - only RecordStore can do this
127+
* Note(erh) see comment on recordFor
125128
*/
126-
DiskLoc extentLocFor( const DiskLoc& loc ) const;
129+
DiskLoc extentLocForV1( const DiskLoc& loc ) const;
127130

128131
/**
129132
* @param loc - has to be for a specific Extent

src/mongo/db/storage/record.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ namespace mongo {
526526
Record* DiskLoc::rec() const {
527527
// XXX-ERH
528528
verify(a() != -1);
529-
return cc().getContext()->db()->getExtentManager().recordFor( *this );
529+
return cc().getContext()->db()->getExtentManager().recordForV1( *this );
530530
}
531531

532532
Extent* DiskLoc::ext() const {

src/mongo/db/structure/record_store_v1_base.cpp

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace mongo {
5555
}
5656

5757
Record* RecordStoreV1Base::recordFor( const DiskLoc& loc ) const {
58-
return _extentManager->recordFor( loc );
58+
return _extentManager->recordForV1( loc );
5959
}
6060

6161
const DeletedRecord* RecordStoreV1Base::deletedRecordFor( const DiskLoc& loc ) const {
@@ -72,6 +72,72 @@ namespace mongo {
7272
return _extentManager->getExtent( loc );
7373
}
7474

75+
DiskLoc RecordStoreV1Base::_getExtentLocForRecord( const DiskLoc& loc ) const {
76+
return _extentManager->extentLocForV1( loc );
77+
}
78+
79+
80+
DiskLoc RecordStoreV1Base::getNextRecord( const DiskLoc& loc ) const {
81+
DiskLoc next = getNextRecordInExtent( loc );
82+
if ( !next.isNull() )
83+
return next;
84+
85+
// now traverse extents
86+
87+
Extent* e = _getExtent( _getExtentLocForRecord(loc) );
88+
while ( 1 ) {
89+
if ( e->xnext.isNull() )
90+
return DiskLoc(); // end of collection
91+
e = _getExtent( e->xnext );
92+
if ( !e->firstRecord.isNull() )
93+
break;
94+
// entire extent could be empty, keep looking
95+
}
96+
return e->firstRecord;
97+
}
98+
99+
DiskLoc RecordStoreV1Base::getPrevRecord( const DiskLoc& loc ) const {
100+
DiskLoc prev = getPrevRecordInExtent( loc );
101+
if ( !prev.isNull() )
102+
return prev;
103+
104+
// now traverse extents
105+
106+
Extent *e = _getExtent(_getExtentLocForRecord(loc));
107+
while ( 1 ) {
108+
if ( e->xprev.isNull() )
109+
return DiskLoc(); // end of collection
110+
e = _getExtent( e->xprev );
111+
if ( !e->firstRecord.isNull() )
112+
break;
113+
// entire extent could be empty, keep looking
114+
}
115+
return e->lastRecord;
116+
117+
}
118+
119+
DiskLoc RecordStoreV1Base::getNextRecordInExtent( const DiskLoc& loc ) const {
120+
int nextOffset = recordFor( loc )->nextOfs();
121+
122+
if ( nextOffset == DiskLoc::NullOfs )
123+
return DiskLoc();
124+
125+
fassert( 17441, abs(nextOffset) >= 8 ); // defensive
126+
return DiskLoc( loc.a(), nextOffset );
127+
}
128+
129+
DiskLoc RecordStoreV1Base::getPrevRecordInExtent( const DiskLoc& loc ) const {
130+
int prevOffset = recordFor( loc )->prevOfs();
131+
132+
if ( prevOffset == DiskLoc::NullOfs )
133+
return DiskLoc();
134+
135+
fassert( 17442, abs(prevOffset) >= 8 ); // defensive
136+
return DiskLoc( loc.a(), prevOffset );
137+
138+
}
139+
140+
75141
StatusWith<DiskLoc> RecordStoreV1Base::insertRecord( const DocWriter* doc, int quotaMax ) {
76142
int lenWHdr = doc->documentSize() + Record::HeaderSize;
77143
if ( doc->addPadding() )
@@ -124,21 +190,21 @@ namespace mongo {
124190
/* remove ourself from the record next/prev chain */
125191
{
126192
if ( todelete->prevOfs() != DiskLoc::NullOfs ) {
127-
DiskLoc prev = _extentManager->getPrevRecordInExtent( dl );
193+
DiskLoc prev = getPrevRecordInExtent( dl );
128194
Record* prevRecord = recordFor( prev );
129195
getDur().writingInt( prevRecord->nextOfs() ) = todelete->nextOfs();
130196
}
131197

132198
if ( todelete->nextOfs() != DiskLoc::NullOfs ) {
133-
DiskLoc next = _extentManager->getNextRecord( dl );
199+
DiskLoc next = getNextRecord( dl );
134200
Record* nextRecord = recordFor( next );
135201
getDur().writingInt( nextRecord->prevOfs() ) = todelete->prevOfs();
136202
}
137203
}
138204

139205
/* remove ourself from extent pointers */
140206
{
141-
Extent *e = getDur().writing( _extentManager->extentFor( dl ) );
207+
Extent *e = getDur().writing( _getExtent( _getExtentLocForRecord( dl ) ) );
142208
if ( e->firstRecord == dl ) {
143209
if ( todelete->nextOfs() == DiskLoc::NullOfs )
144210
e->firstRecord.Null();
@@ -179,7 +245,7 @@ namespace mongo {
179245

180246
void RecordStoreV1Base::_addRecordToRecListInExtent(Record *r, DiskLoc loc) {
181247
dassert( recordFor(loc) == r );
182-
Extent *e = _extentManager->extentFor( loc );
248+
Extent *e = _getExtent( _getExtentLocForRecord( loc ) );
183249
if ( e->lastRecord.isNull() ) {
184250
Extent::FL *fl = getDur().writing(e->fl());
185251
fl->firstRecord = fl->lastRecord = loc;

src/mongo/db/structure/record_store_v1_base.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ namespace mongo {
7676
*/
7777
int getRecordAllocationSize( int minRecordSize ) const;
7878

79+
DiskLoc getExtentLocForRecord( const DiskLoc& loc ) const;
80+
81+
DiskLoc getNextRecord( const DiskLoc& loc ) const;
82+
DiskLoc getPrevRecord( const DiskLoc& loc ) const;
83+
84+
DiskLoc getNextRecordInExtent( const DiskLoc& loc ) const;
85+
DiskLoc getPrevRecordInExtent( const DiskLoc& loc ) const;
86+
7987
protected:
8088

8189
virtual bool isCapped() const = 0;
@@ -91,6 +99,14 @@ namespace mongo {
9199
// just a haper for _extentManager->getExtent( loc );
92100
Extent* _getExtent( const DiskLoc& loc ) const;
93101

102+
DiskLoc _getExtentLocForRecord( const DiskLoc& loc ) const;
103+
104+
DiskLoc _getNextRecord( const DiskLoc& loc ) const;
105+
DiskLoc _getPrevRecord( const DiskLoc& loc ) const;
106+
107+
DiskLoc _getNextRecordInExtent( const DiskLoc& loc ) const;
108+
DiskLoc _getPrevRecordInExtent( const DiskLoc& loc ) const;
109+
94110
/** add a record to the end of the linked list chain within this extent.
95111
require: you must have already declared write intent for the record header.
96112
*/

src/mongo/db/structure/record_store_v1_capped.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,13 @@ namespace mongo {
210210
}
211211

212212
Status CappedRecordStoreV1::truncate() {
213-
fassert( 17439, _details->getTotalIndexCount() == 0 );
214-
215213
getDur().writingDiskLoc(cappedLastDelRecLastExtent()) = DiskLoc();
216214
getDur().writingDiskLoc(cappedListOfAllDeletedRecords()) = DiskLoc();
217215

218216
// preserve firstExtent/lastExtent
219217
getDur().writingDiskLoc(_details->capExtent()) = _details->firstExtent();
220218
_details->setStats( 0, 0 );
221-
// lastExtentSize preserve
219+
// preserve lastExtentSize
222220
// nIndexes preserve 0
223221
// capped preserve true
224222
// max preserve
@@ -229,8 +227,6 @@ namespace mongo {
229227
getDur().writingDiskLoc(cappedLastDelRecLastExtent()).setInvalid();
230228
// dataFileVersion preserve
231229
// indexFileVersion preserve
232-
for ( int i = 0; i < NamespaceDetails::NIndexesMax; i++ )
233-
_details->setIndexIsMultikey( i, false );
234230

235231
// Reset all existing extents and recreate the deleted list.
236232
for( DiskLoc ext = _details->firstExtent();

src/mongo/db/structure/record_store_v1_capped_iterator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ namespace mongo {
227227
}
228228

229229
DiskLoc CappedRecordStoreV1Iterator::_getNextRecord( const DiskLoc& loc ) {
230-
return _recordStore->_extentManager->getNextRecord( loc );
230+
return _recordStore->getNextRecord( loc );
231231
}
232232

233233
DiskLoc CappedRecordStoreV1Iterator::_getPrevRecord( const DiskLoc& loc ) {
234-
return _recordStore->_extentManager->getPrevRecord( loc );
234+
return _recordStore->getPrevRecord( loc );
235235
}
236236

237237
} // namespace mongo

src/mongo/db/structure/record_store_v1_simple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ namespace mongo {
346346
if( !L.isNull() ) {
347347
while( 1 ) {
348348
Record *recOld = recordFor(L);
349-
L = _extentManager->getNextRecordInExtent(L);
349+
L = getNextRecordInExtent(L);
350350

351351
if ( compactOptions->validateDocuments && !adaptor->isDataValid(recOld) ) {
352352
// object is corrupt!

src/mongo/db/structure/record_store_v1_simple_iterator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ namespace mongo {
9696
// Move to the next thing.
9797
if (!isEOF()) {
9898
if (CollectionScanParams::FORWARD == _direction) {
99-
_curr = _recordStore->_extentManager->getNextRecord( _curr );
99+
_curr = _recordStore->getNextRecord( _curr );
100100
}
101101
else {
102-
_curr = _recordStore->_extentManager->getPrevRecord( _curr );
102+
_curr = _recordStore->getPrevRecord( _curr );
103103
}
104104
}
105105

0 commit comments

Comments
 (0)