@@ -194,7 +194,7 @@ KVStorageEngine::KVStorageEngine(
194194会有一份对应的WiredTiger需要的元数据维护在WiredTiger.wt表中。因此,事实上这里有两份数据表的列表,
195195并且在某些情况下可能会存在不一致,比如,异常宕机的场景。因此MongoDB在启动过程中,会对这两份数据
196196进行一致性检查,如果是异常宕机启动过程,会以WiredTiger.wt表中的数据为准,对_mdb_catalog表中的记录进行修正。这个过程会需要遍历WiredTiger.wt表得到所有数据表的列表。
197- ???? 这里说法有误,应该是以_mdb_catalog.wt为准--yangyazhou todo xxx
197+ ???? 这里说法有误,应该是以_mdb_catalog.wt为准--yangyazhou todo xxx 感觉有点问题
198198
199199综上,可以看到,在MongoDB启动过程中,有多处涉及到需要从WiredTiger.wt表中读取数据表的元数据。
200200对这种需求,WiredTiger专门提供了一类特殊的『metadata』类型的cursor。
@@ -240,7 +240,7 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
240240 // Drop all idents in the storage engine that are not known to the catalog. This can happen in
241241 // the case of a collection or index creation being rolled back.
242242
243- // 把WiredTiger.wt中有,但是_mdb_catalog.wt中没用的元数据信息清除
243+ // 把WiredTiger.wt中有,但是_mdb_catalog.wt中没有的元数据信息清除
244244 for (const auto & it : engineIdents) {
245245 log () << " yang test ....reconcileCatalogAndIdents...... ident: " << it;
246246 // 找到了相同的ident数据目录文件,继续下一个
@@ -256,6 +256,7 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
256256 const auto & toRemove = it;
257257 log () << " Dropping unknown ident: " << toRemove;
258258 WriteUnitOfWork wuow (opCtx);
259+ // WiredTigerKVEngine::dropIdent 删除对应ident文件
259260 fassertStatusOK (40591 , _engine->dropIdent (opCtx, toRemove));
260261 wuow.commit ();
261262 }
@@ -302,6 +303,8 @@ StatusWith<std::vector<StorageEngine::CollectionIndexNamePair>>
302303 return ret;
303304}
304305
306+ // ServiceContextMongoD::shutdownGlobalStorageEngineCleanly()调用
307+ // shutdown回收处理
305308void KVStorageEngine::cleanShutdown () {
306309 for (DBMap::const_iterator it = _dbs.begin (); it != _dbs.end (); ++it) {
307310 delete it->second ;
@@ -405,6 +408,7 @@ Status KVStorageEngine::dropDatabase(OperationContext* opCtx, StringData db) {
405408 return Status::OK ();
406409}
407410
411+ // FSyncLockThread::run()调用 db.adminCommand( { fsync: 1, lock: true } )
408412int KVStorageEngine::flushAllFiles (OperationContext* opCtx, bool sync) {
409413 return _engine->flushAllFiles (opCtx, sync);
410414}
@@ -444,6 +448,7 @@ SnapshotManager* KVStorageEngine::getSnapshotManager() const {
444448 return _engine->getSnapshotManager ();
445449}
446450
451+ // //CmdRepairDatabase::errmsgRun
447452Status KVStorageEngine::repairRecordStore (OperationContext* opCtx, const std::string& ns) {
448453 Status status = _engine->repairIdent (opCtx, _catalog->getCollectionIdent (ns));
449454 if (!status.isOK ())
@@ -453,6 +458,7 @@ Status KVStorageEngine::repairRecordStore(OperationContext* opCtx, const std::st
453458 return Status::OK ();
454459}
455460
461+ // ReplicationCoordinatorExternalStateImpl::startThreads
456462void KVStorageEngine::setJournalListener (JournalListener* jl) {
457463 _engine->setJournalListener (jl);
458464}
0 commit comments