@@ -479,6 +479,7 @@ void KVCatalog::init(OperationContext* opCtx) {
479
479
}
480
480
481
481
// No rollback since this is just loading already committed data.
482
+ // 表及其对应的ident信息
482
483
string ns = obj[" ns" ].String ();
483
484
string ident = obj[" ident" ].String ();
484
485
_idents[ns] = Entry (ident, record->id );
@@ -571,6 +572,10 @@ Status KVCatalog::newCollection(OperationContext* opCtx,
571
572
572
573
// 更新_idents,记录下集合对应元数据信息,也就是集合路径 集合uuid 集合索引,以及在元数据_mdb_catalog.wt中的位置
573
574
old = Entry (ident, res.getValue ());
575
+ // 2021-05-01T11:12:42.394+0800 D STORAGE [conn-1] stored meta data for test.mycol @ RecordId(6)
576
+ // obj:{ ns: "test.mycol", ident: "test/collection/1--6948813758302814892", md: { ns: "test.mycol",
577
+ // options: { uuid: UUID("75591c22-bd0f-4a56-ac95-ef90224cf3df"), capped: true, size: 6142976, max: 10000, autoIndexId: true },
578
+ // indexes: [], prefix: -1 } }
574
579
// 集合元数据信息存入_mdb_catalog.wt
575
580
LOG (1 ) << " stored meta data for " << ns << " @ " << res.getValue () << " obj:" << redact (obj);;
576
581
return Status::OK ();
@@ -594,7 +599,7 @@ std::string KVCatalog::getIndexIdent(OperationContext* opCtx,
594
599
return idxIdent[idxName].String ();
595
600
}
596
601
597
- // _mdb_catalog.wt中查找 KVCatalog ::getMetaData中执行
602
+ // _mdb_catalog.wt中查找 下面的KVCatalog ::getMetaData中执行
598
603
BSONObj KVCatalog::_findEntry (OperationContext* opCtx, StringData ns, RecordId* out) const {
599
604
RecordId dl;
600
605
{
@@ -626,6 +631,7 @@ BSONObj KVCatalog::_findEntry(OperationContext* opCtx, StringData ns, RecordId*
626
631
// KVStorageEngine::reconcileCatalogAndIdents KVStorageEngine::KVStorageEngine
627
632
628
633
// 获取MetaData信息,KVCollectionCatalogEntry::_getMetaData调用
634
+ // 获取表ns的元数据信息
629
635
const BSONCollectionCatalogEntry::MetaData KVCatalog::getMetaData (OperationContext* opCtx,
630
636
StringData ns) {
631
637
BSONObj obj = _findEntry (opCtx, ns);
@@ -645,6 +651,8 @@ const BSONCollectionCatalogEntry::MetaData KVCatalog::getMetaData(OperationConte
645
651
646
652
// KVCollectionCatalogEntry类的如下相关接口完成对MetaData的更新:updateValidator updateFlags setIsTemp removeUUID addUUID updateTTLSetting indexBuildSuccess
647
653
// KVCollectionCatalogEntry类的相关接口调用,完成MetaData相关成员更新
654
+
655
+ // 更新某个表的元数据信息 KVCollectionCatalogEntry类的相关接口调用,完成MetaData相关成员更新
648
656
void KVCatalog::putMetaData (OperationContext* opCtx,
649
657
StringData ns,
650
658
BSONCollectionCatalogEntry::MetaData& md) {
@@ -685,11 +693,18 @@ void KVCatalog::putMetaData(OperationContext* opCtx,
685
693
// { _id: BinData(0, 00) }, head: 0, prefix: -1 } ], prefix: -1 }, idxIdent: { _id_: "admin/index/1--9034870482849730886" },
686
694
// ns: "admin.system.version", ident: "admin/collection/0--9034870482849730886" }
687
695
696
+ // 建一个新表的元数据打印:db.createCollection("mycol", { capped : true, autoIndexId : true, size : 6142800, max : 10000 } )
697
+ // { md: { ns: "test.mycol", options: { uuid: UUID("75591c22-bd0f-4a56-ac95-ef90224cf3df"), capped: true, size: 6142976, max: 10000, autoIndexId: true },
698
+ // indexes: [ { spec: { v: 2, key: { _id: 1 }, name: "_id_", ns: "test.mycol" }, ready: false, multikey: false,
699
+ // multikeyPaths: { _id: BinData(0, 00) }, head: 0, prefix: -1 } ], prefix: -1 }, idxIdent: { _id_: "test/index/2--6948813758302814892" },
700
+ // ns: "test.mycol", ident: "test/collection/1--6948813758302814892" }
701
+
688
702
LOG (3 ) << " recording new metadata: " << obj;
689
703
Status status = _rs->updateRecord (opCtx, loc, obj.objdata (), obj.objsize (), false , NULL );
690
704
fassert (28521 , status.isOK ());
691
705
}
692
706
707
+ // 表重命名后元数据也要更新
693
708
Status KVCatalog::renameCollection (OperationContext* opCtx,
694
709
StringData fromNS,
695
710
StringData toNS,
@@ -732,6 +747,7 @@ Status KVCatalog::renameCollection(OperationContext* opCtx,
732
747
// drop删表CmdDrop::errmsgRun->dropCollection->DatabaseImpl::dropCollectionEvenIfSystem->DatabaseImpl::_finishDropCollection
733
748
// ->DatabaseImpl::_finishDropCollection->KVDatabaseCatalogEntryBase::dropCollection->KVCatalog::dropCollection
734
749
// 配合KVDatabaseCatalogEntryBase::createCollection->KVCatalog::newCollection阅读
750
+ // 删除表后需要从元数据中删除该表
735
751
Status KVCatalog::dropCollection (OperationContext* opCtx, StringData ns) {
736
752
invariant (opCtx->lockState ()->isDbLockedForMode (nsToDatabaseSubstring (ns), MODE_X));
737
753
stdx::lock_guard<stdx::mutex> lk (_identsLock);
0 commit comments