| 120 | } |
| 121 | |
| 122 | comm::RetCode Scheduler::InitTopicID() { |
| 123 | comm::RetCode ret; |
| 124 | |
| 125 | if (!impl_->opt.topic.empty()) { |
| 126 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetTopicIDByTopicName(impl_->opt.topic, impl_->topic_id))) { |
| 127 | QLErr("GetTopicIDByTopicName ret %d topic %s", as_integer(ret), impl_->opt.topic.c_str()); |
| 128 | } |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | QLInfo("no topic name. find toipc_id by addr(%s:%d)", impl_->addr.ip().c_str(), impl_->addr.port()); |
| 133 | |
| 134 | set<int> topic_ids; |
| 135 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetAllTopicID(topic_ids))) { |
| 136 | QLErr("GetAllTopicID ret %d", as_integer(ret)); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | for (auto &&topic_id : topic_ids) { |
| 141 | |
| 142 | QLVerb("check topic_id %d", topic_id); |
| 143 | |
| 144 | shared_ptr<const config::SchedulerConfig> scheduler_config; |
| 145 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetSchedulerConfig(topic_id, scheduler_config))) { |
| 146 | QLErr("GetSchedulerConfig ret %d", as_integer(ret)); |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | shared_ptr<const config::proto::Scheduler> scheduler; |
| 151 | if (comm::RetCode::RET_OK != (ret = scheduler_config->GetScheduler(scheduler))) { |
| 152 | QLErr("GetScheduler ret %d", as_integer(ret)); |
| 153 | } else { |
| 154 | for (int i{0}; i < scheduler->addrs_size(); ++i) { |
| 155 | auto &&addr = scheduler->addrs(i); |
| 156 | if (addr.ip() == impl_->addr.ip() && addr.port() == impl_->addr.port()) { |
| 157 | impl_->topic_id = topic_id; |
| 158 | QLInfo("found toipc_id %d addr (%s:%d)", topic_id, impl_->addr.ip().c_str(), impl_->addr.port()); |
| 159 | return comm::RetCode::RET_OK; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return comm::RetCode::RET_ERR_RANGE_ADDR; |
| 166 | } |
| 167 | |
| 168 | int Scheduler::GetTopicID() { |
| 169 | return impl_->topic_id; |
nothing calls this directly
no test coverage detected