| 367 | } |
| 368 | |
| 369 | comm::RetCode SchedulerMgr::ReloadTopicConfig() { |
| 370 | set<int> topic_ids; |
| 371 | comm::RetCode ret{config::GlobalConfig::GetThreadInstance()->GetAllTopicID(topic_ids)}; |
| 372 | if (comm::RetCode::RET_OK != ret) { |
| 373 | QLErr("GetAllTopic err %d", ret); |
| 374 | |
| 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | QLVerb("nr_topic %zu", topic_ids.size()); |
| 379 | |
| 380 | // check map update |
| 381 | bool modified{false}; |
| 382 | { |
| 383 | comm::utils::RWLock rwlock_read(impl_->rwlock, comm::utils::RWLock::LockMode::READ); |
| 384 | if (impl_->topic_id2data_map.size() != topic_ids.size()) { |
| 385 | modified = true; |
| 386 | } else { |
| 387 | for (const int topic_id : topic_ids) { |
| 388 | if (impl_->topic_id2data_map.end() == impl_->topic_id2data_map.find(topic_id)) { |
| 389 | modified = true; |
| 390 | |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // map updated |
| 398 | if (modified) { |
| 399 | comm::utils::RWLock rwlock_write(impl_->rwlock, comm::utils::RWLock::LockMode::WRITE); |
| 400 | |
| 401 | // add |
| 402 | for (const int topic_id : topic_ids) { |
| 403 | if (impl_->topic_id2data_map.end() == impl_->topic_id2data_map.find(topic_id)) { |
| 404 | impl_->topic_id2lock_map.emplace(topic_id, move(TopicLock())); |
| 405 | impl_->topic_id2data_map.emplace(topic_id, move(TopicData())); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // remove |
| 410 | if (topic_ids.size() != impl_->topic_id2data_map.size()) { |
| 411 | set<int> topic_id_set; |
| 412 | for (const auto &topic_id : topic_ids) { |
| 413 | topic_id_set.emplace(topic_id); |
| 414 | } |
| 415 | for (auto it(impl_->topic_id2data_map.begin()); |
| 416 | impl_->topic_id2data_map.end() != it; ++it) { |
| 417 | if (topic_id_set.end() == topic_id_set.find(it->first)) { |
| 418 | const int topic_id{it->first}; |
| 419 | auto topic_id2lock_it(impl_->topic_id2lock_map.find(topic_id)); |
| 420 | if (impl_->topic_id2lock_map.end() == topic_id2lock_it) { |
| 421 | QLErr("topic %d lock lost", it->first); |
| 422 | |
| 423 | continue; |
| 424 | } |
| 425 | // TODO: check if deadlock |
| 426 | comm::utils::RWLock rwlock_write(topic_id2lock_it->second.rwlock, |
nothing calls this directly
no test coverage detected