AsyncResultsMerger::AsyncResultsMerger(executor::TaskExecutor* executor, ClusterClientCursorParams&& params) : _executor(executor), _params(std::move(params)), _mergeQueue(MergingComparator(_remotes, _params.sort)) { for (const auto& remote : _params.remotes) { if (remote.shardId) { invariant(remote.cmdObj); invariant(!remote.cursorId); invariant(!remote.hostAndPort); _remotes.emplace_back(*remote.shardId, *remote.cmdObj); } else { invariant(!remote.cmdObj); invariant(remote.cursorId); invariant(remote.hostAndPort); _remotes.emplace_back(*remote.hostAndPort, *remote.cursorId); } } // Initialize command metadata to handle the read preference. if (_params.readPreference) { BSONObjBuilder metadataBuilder; rpc::ServerSelectionMetadata metadata( _params.readPreference->pref != ReadPreference::PrimaryOnly, boost::none); uassertStatusOK(metadata.writeToMetadata(&metadataBuilder)); _metadataObj = metadataBuilder.obj(); } }
AsyncClusterClientCursor::AsyncClusterClientCursor(executor::TaskExecutor* executor, const ClusterClientCursorParams& params, const std::vector<HostAndPort>& remotes) : _executor(executor), _params(params), _mergeQueue(MergingComparator(_remotes, _params.sort)) { for (const auto& remote : remotes) { _remotes.emplace_back(remote); } }
AsyncResultsMerger::AsyncResultsMerger(executor::TaskExecutor* executor, ClusterClientCursorParams params) : _executor(executor), _params(std::move(params)), _mergeQueue(MergingComparator(_remotes, _params.sort)) { for (const auto& remote : _params.remotes) { _remotes.emplace_back(remote); } // Initialize command metadata to handle isSecondaryOk. BSONObjBuilder metadataBuilder; rpc::ServerSelectionMetadata metadata(_params.isSecondaryOk, boost::none); uassertStatusOK(metadata.writeToMetadata(&metadataBuilder)); _metadataObj = metadataBuilder.obj(); }
AsyncResultsMerger::AsyncResultsMerger(executor::TaskExecutor* executor, ClusterClientCursorParams* params) : _executor(executor), _params(params), _mergeQueue(MergingComparator(_remotes, _params->sort)) { size_t remoteIndex = 0; for (const auto& remote : _params->remotes) { _remotes.emplace_back(remote.hostAndPort, remote.cursorResponse.getCursorId()); // We don't check the return value of addBatchToBuffer here; if there was an error, // it will be stored in the remote and the first call to ready() will return true. addBatchToBuffer(remoteIndex, remote.cursorResponse.getBatch()); ++remoteIndex; } // Initialize command metadata to handle the read preference. We do this in case the readPref // is primaryOnly, in which case if the remote host for one of the cursors changes roles, the // remote will return an error. if (_params->readPreference) { _metadataObj = _params->readPreference->toContainingBSON(); } }