MongoDB sharding 隐式创建collection -- ImplicitCollection

2020-07-31 13:21:15

1. mongos节点 收到用户 insert 请求

mongos 收到一个 insert 请求后,会经过如下流程处理将请求发送给 shard 节点:

ServiceEntryPointMongos::handleRequest() --> Strategy::clientCommand() --> runCommand() --> execCommandClient() --> ClusterWriteCmd::InvocationBase::run() --> ClusterWriteCmd::InvocationBase::runImpl() --> ClusterWriter::write() --> BatchWriteExec::executeBatch() --> MultiStatementTransactionRequestsSender()

在发送给 shard 节点的请求中,会通过 allowImplicitCollectionCreation 字段来控制是否允许 shard 节点隐式创建collection。sharding状态下,该字段基本为 false,即不允许 shard 节点隐式创建collection

  • 对于 insert / update / delete 这三类请求,会在 ClusterWriteCmd::InvocationBase::runImpl() 中进行 batchedRequest.setAllowImplicitCreate(false);
  • src/mongo/s/cluster_commands_helpers.cpp 中也提供了 scatterGatherVersionedTargetByRoutingTable / scatterGatherUnversionedTargetAllShards / scatterGatherOnlyVersionIfUnsharded / executeCommandAgainstDatabasePrimary 函数。如果请求包中不显式声明 allowImplicitCollectionCreation ,则默认为 false
    • 但是 renameCollectioncovertToCapped 会将 appendAllowImplicitCreate 声明为 true(可以隐式创建collection)

shard节点可以直接创建collection,即为隐式创建collection(rs实例均采用这种方式)。否则需要和 config 交互来完成 collection 的创建,即为显式创建collection

2. shard节点 收到 mongos节点 转发过来携带 allowImplicitCollectionCreation=false的 insert 请求

正常情况下, shard节点 按照如下流程处理 insert 请求:

ServiceEntryPointMongod::handleRequest() --> ServiceEntryPointCommon::handleRequest() --> receivedCommands() --> execCommandDatabase() --> runCommandImpl() --> WriteCommand::InvocationBase::run() --> CmdInsert::Invocation::runImpl() --> performInserts() --> insertBatchAndHandleErrors() --> acquireCollecti
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值