Status initializeGlobalShardingStateForMongod(OperationContext* txn, const ConnectionString& configCS, StringData distLockProcessId) { auto targeterFactory = stdx::make_unique<RemoteCommandTargeterFactoryImpl>(); auto targeterFactoryPtr = targeterFactory.get(); ShardFactory::BuilderCallable setBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable masterBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable localBuilder = [](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardLocal>(shardId); }; ShardFactory::BuildersMap buildersMap{ {ConnectionString::SET, std::move(setBuilder)}, {ConnectionString::MASTER, std::move(masterBuilder)}, {ConnectionString::LOCAL, std::move(localBuilder)}, }; auto shardFactory = stdx::make_unique<ShardFactory>(std::move(buildersMap), std::move(targeterFactory)); return initializeGlobalShardingState( txn, configCS, distLockProcessId, std::move(shardFactory), []() { return stdx::make_unique<rpc::ShardingEgressMetadataHookForMongod>(); }, [](ShardingCatalogClient* catalogClient, std::unique_ptr<executor::TaskExecutor> executor) -> std::unique_ptr<ShardingCatalogManager> { if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { return stdx::make_unique<ShardingCatalogManagerImpl>(catalogClient, std::move(executor)); } else { return nullptr; // Only config servers get a real ShardingCatalogManager } }); }
Status initializeGlobalShardingStateForMongod(const ConnectionString& configCS) { auto targeterFactory = stdx::make_unique<RemoteCommandTargeterFactoryImpl>(); auto targeterFactoryPtr = targeterFactory.get(); ShardFactory::BuilderCallable setBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable masterBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable localBuilder = [](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardLocal>(shardId); }; ShardFactory::BuildersMap buildersMap{ {ConnectionString::SET, std::move(setBuilder)}, {ConnectionString::MASTER, std::move(masterBuilder)}, {ConnectionString::LOCAL, std::move(localBuilder)}, }; auto shardFactory = stdx::make_unique<ShardFactory>(std::move(buildersMap), std::move(targeterFactory)); return initializeGlobalShardingState( configCS, ChunkSizeSettingsType::kDefaultMaxChunkSizeBytes, std::move(shardFactory), []() { return stdx::make_unique<rpc::ShardingEgressMetadataHookForMongod>(); }); }
void initializeGlobalShardingStateForMongoD(OperationContext* opCtx, const ConnectionString& configCS, StringData distLockProcessId) { auto targeterFactory = stdx::make_unique<RemoteCommandTargeterFactoryImpl>(); auto targeterFactoryPtr = targeterFactory.get(); ShardFactory::BuilderCallable setBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable masterBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable localBuilder = [](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardLocal>(shardId); }; ShardFactory::BuildersMap buildersMap{ {ConnectionString::SET, std::move(setBuilder)}, {ConnectionString::MASTER, std::move(masterBuilder)}, {ConnectionString::LOCAL, std::move(localBuilder)}, }; auto shardFactory = stdx::make_unique<ShardFactory>(std::move(buildersMap), std::move(targeterFactory)); auto const service = opCtx->getServiceContext(); if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { if (storageGlobalParams.readOnly) { CatalogCacheLoader::set(service, stdx::make_unique<ReadOnlyCatalogCacheLoader>()); } else { CatalogCacheLoader::set(service, stdx::make_unique<ShardServerCatalogCacheLoader>( stdx::make_unique<ConfigServerCatalogCacheLoader>())); } } else { CatalogCacheLoader::set(service, stdx::make_unique<ConfigServerCatalogCacheLoader>()); } auto validator = LogicalTimeValidator::get(service); if (validator) { // The keyManager may be existing if the node was a part of a standalone RS. validator->stopKeyManager(); } globalConnPool.addHook(new ShardingConnectionHook(false, makeEgressHooksList(service))); shardConnectionPool.addHook(new ShardingConnectionHook(true, makeEgressHooksList(service))); uassertStatusOK(initializeGlobalShardingState( opCtx, configCS, distLockProcessId, std::move(shardFactory), stdx::make_unique<CatalogCache>(CatalogCacheLoader::get(opCtx)), [service] { return makeEgressHooksList(service); }, // We only need one task executor here because sharding task executors aren't used for user // queries in mongod. 1)); auto const replCoord = repl::ReplicationCoordinator::get(service); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer && replCoord->getMemberState().primary()) { LogicalTimeValidator::get(opCtx)->enableKeyGenerator(opCtx, true); } }
Status initializeGlobalShardingStateForMongod(const ConnectionString& configCS) { return initializeGlobalShardingState( configCS, ChunkSizeSettingsType::kDefaultMaxChunkSizeBytes, false); }
Status initializeGlobalShardingStateForMongos(const ConnectionString& configCS, uint64_t maxChunkSizeBytes) { return initializeGlobalShardingState(configCS, maxChunkSizeBytes, true); }
Status initializeGlobalShardingStateForMongod(OperationContext* txn, const ConnectionString& configCS) { return initializeGlobalShardingState(txn, configCS, false); }
Status initializeSharding(OperationContext* opCtx) { auto targeterFactory = stdx::make_unique<RemoteCommandTargeterFactoryImpl>(); auto targeterFactoryPtr = targeterFactory.get(); ShardFactory::BuilderCallable setBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuilderCallable masterBuilder = [targeterFactoryPtr](const ShardId& shardId, const ConnectionString& connStr) { return stdx::make_unique<ShardRemote>( shardId, connStr, targeterFactoryPtr->create(connStr)); }; ShardFactory::BuildersMap buildersMap{ {ConnectionString::SET, std::move(setBuilder)}, {ConnectionString::MASTER, std::move(masterBuilder)}, }; auto shardFactory = stdx::make_unique<ShardFactory>(std::move(buildersMap), std::move(targeterFactory)); CatalogCacheLoader::set(opCtx->getServiceContext(), stdx::make_unique<ConfigServerCatalogCacheLoader>()); Status status = initializeGlobalShardingState( opCtx, mongosGlobalParams.configdbs, generateDistLockProcessId(opCtx), std::move(shardFactory), stdx::make_unique<CatalogCache>(CatalogCacheLoader::get(opCtx)), [opCtx]() { auto hookList = stdx::make_unique<rpc::EgressMetadataHookList>(); hookList->addHook( stdx::make_unique<rpc::LogicalTimeMetadataHook>(opCtx->getServiceContext())); hookList->addHook( stdx::make_unique<rpc::CommittedOpTimeMetadataHook>(opCtx->getServiceContext())); hookList->addHook(stdx::make_unique<rpc::ShardingEgressMetadataHookForMongos>( opCtx->getServiceContext())); return hookList; }, boost::none); if (!status.isOK()) { return status; } status = waitForShardRegistryReload(opCtx); if (!status.isOK()) { return status; } status = waitForSigningKeys(opCtx); if (!status.isOK()) { return status; } Grid::get(opCtx)->setShardingInitialized(); return Status::OK(); }
Status initializeGlobalShardingStateForMongod(OperationContext* txn, const ConnectionString& configCS) { return initializeGlobalShardingState( txn, configCS, BalancerConfiguration::kDefaultMaxChunkSizeBytes, false); }