@@ -194,7 +194,7 @@ KVStorageEngine::KVStorageEngine(
194
194
会有一份对应的WiredTiger需要的元数据维护在WiredTiger.wt表中。因此,事实上这里有两份数据表的列表,
195
195
并且在某些情况下可能会存在不一致,比如,异常宕机的场景。因此MongoDB在启动过程中,会对这两份数据
196
196
进行一致性检查,如果是异常宕机启动过程,会以WiredTiger.wt表中的数据为准,对_mdb_catalog表中的记录进行修正。这个过程会需要遍历WiredTiger.wt表得到所有数据表的列表。
197
- ???? 这里说法有误,应该是以_mdb_catalog.wt为准--yangyazhou todo xxx
197
+ ???? 这里说法有误,应该是以_mdb_catalog.wt为准--yangyazhou todo xxx 感觉有点问题
198
198
199
199
综上,可以看到,在MongoDB启动过程中,有多处涉及到需要从WiredTiger.wt表中读取数据表的元数据。
200
200
对这种需求,WiredTiger专门提供了一类特殊的『metadata』类型的cursor。
@@ -240,7 +240,7 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
240
240
// Drop all idents in the storage engine that are not known to the catalog. This can happen in
241
241
// the case of a collection or index creation being rolled back.
242
242
243
- // 把WiredTiger.wt中有,但是_mdb_catalog.wt中没用的元数据信息清除
243
+ // 把WiredTiger.wt中有,但是_mdb_catalog.wt中没有的元数据信息清除
244
244
for (const auto & it : engineIdents) {
245
245
log () << " yang test ....reconcileCatalogAndIdents...... ident: " << it;
246
246
// 找到了相同的ident数据目录文件,继续下一个
@@ -256,6 +256,7 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
256
256
const auto & toRemove = it;
257
257
log () << " Dropping unknown ident: " << toRemove;
258
258
WriteUnitOfWork wuow (opCtx);
259
+ // WiredTigerKVEngine::dropIdent 删除对应ident文件
259
260
fassertStatusOK (40591 , _engine->dropIdent (opCtx, toRemove));
260
261
wuow.commit ();
261
262
}
@@ -302,6 +303,8 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
302
303
return ret;
303
304
}
304
305
306
+ // ServiceContextMongoD::shutdownGlobalStorageEngineCleanly()调用
307
+ // shutdown回收处理
305
308
void KVStorageEngine::cleanShutdown () {
306
309
for (DBMap::const_iterator it = _dbs.begin (); it != _dbs.end (); ++it) {
307
310
delete it->second ;
@@ -405,6 +408,7 @@ Status KVStorageEngine::dropDatabase(OperationContext* opCtx, StringData db) {
405
408
return Status::OK ();
406
409
}
407
410
411
+ // FSyncLockThread::run()调用 db.adminCommand( { fsync: 1, lock: true } )
408
412
int KVStorageEngine::flushAllFiles (OperationContext* opCtx, bool sync) {
409
413
return _engine->flushAllFiles (opCtx, sync );
410
414
}
@@ -444,6 +448,7 @@ SnapshotManager* KVStorageEngine::getSnapshotManager() const {
444
448
return _engine->getSnapshotManager ();
445
449
}
446
450
451
+ // //CmdRepairDatabase::errmsgRun
447
452
Status KVStorageEngine::repairRecordStore (OperationContext* opCtx, const std::string& ns) {
448
453
Status status = _engine->repairIdent (opCtx, _catalog->getCollectionIdent (ns));
449
454
if (!status.isOK ())
@@ -453,6 +458,7 @@ Status KVStorageEngine::repairRecordStore(OperationContext* opCtx, const std::st
453
458
return Status::OK ();
454
459
}
455
460
461
+ // ReplicationCoordinatorExternalStateImpl::startThreads
456
462
void KVStorageEngine::setJournalListener (JournalListener* jl) {
457
463
_engine->setJournalListener (jl);
458
464
}
0 commit comments