| 255 | } |
| 256 | |
| 257 | int DiskAnnBuilder::build_internal(IndexThreads::Pointer threads) { |
| 258 | auto task_group = threads->make_group(); |
| 259 | if (!task_group) { |
| 260 | LOG_ERROR("Failed to create task group"); |
| 261 | return IndexError_Runtime; |
| 262 | } |
| 263 | |
| 264 | std::atomic<uint64_t> finished{0}; |
| 265 | for (size_t i = 0; i < threads->count(); ++i) { |
| 266 | task_group->submit(ailego::Closure ::New(this, &DiskAnnBuilder::do_build, i, |
| 267 | threads->count(), &finished)); |
| 268 | } |
| 269 | |
| 270 | while (!task_group->is_finished()) { |
| 271 | std::unique_lock<std::mutex> lk(mutex_); |
| 272 | cond_.wait_until(lk, std::chrono::system_clock::now() + |
| 273 | std::chrono::seconds(check_interval_secs_)); |
| 274 | if (error_.load(std::memory_order_acquire)) { |
| 275 | LOG_ERROR("Failed to build index while waiting finish"); |
| 276 | return errcode_; |
| 277 | } |
| 278 | LOG_INFO("Built cnt %zu, finished percent %.3f%%", (size_t)finished.load(), |
| 279 | finished.load() * 100.0f / entity_.doc_cnt()); |
| 280 | } |
| 281 | if (error_.load(std::memory_order_acquire)) { |
| 282 | LOG_ERROR("Failed to build index while waiting finish"); |
| 283 | return errcode_; |
| 284 | } |
| 285 | task_group->wait_finish(); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | int DiskAnnBuilder::prune_internal(IndexThreads::Pointer threads) { |
| 291 | auto task_group = threads->make_group(); |
nothing calls this directly
no test coverage detected