diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1c536ac1f1a1f8ea9d669256d097c337d4b69b..141536e3c4112d310eb31996c637d563a0f86590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Please mark all change in change log and use the issue from GitHub ## Bug - \#2367 Fix inconsistent reading and writing when using mishards +- \#2373 Build index for small segment waste time on waiting background index thread finish - \#2394 Drop collection timeout if too many partitions created on collection ## Feature diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index c7a9c47826b34a61c2bbd18018afaeb5d0530726..314423f70ea4a5cd3595a0525647c10c77a7cc95 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -2377,17 +2377,16 @@ DBImpl::WaitCollectionIndexRecursively(const std::shared_ptr& c } } - index_req_swn_.Wait_For(std::chrono::seconds(1)); - + auto ret = index_req_swn_.Wait_For(std::chrono::seconds(1)); // client break the connection, no need to block, check every 1 second if (context && context->IsConnectionBroken()) { LOG_ENGINE_DEBUG_ << "Client connection broken, build index in background"; break; // just break, not return, continue to update partitions files to to_index } - // check to_index files every 5 seconds + // check to_index files every 5 seconds or background index thread finished repeat++; - if (repeat % WAIT_BUILD_INDEX_INTERVAL == 0) { + if ((ret == std::cv_status::no_timeout) || (repeat % WAIT_BUILD_INDEX_INTERVAL == 0)) { GetFilesToBuildIndex(collection_id, file_types, files_holder); ++times; } diff --git a/core/src/db/DBImpl.h b/core/src/db/DBImpl.h index 39c07912daa1bed2e48080c7be4bf0fde8e47075..f81df01d86f8c1f4785ef7ddecc31a0e7fb031b3 100644 --- a/core/src/db/DBImpl.h +++ b/core/src/db/DBImpl.h @@ -310,22 +310,26 @@ class DBImpl : public DB, public server::CacheConfigHandler, public server::Engi notified_ = false; } - void + std::cv_status Wait_Until(const std::chrono::system_clock::time_point& tm_pint) { std::unique_lock lck(mutex_); + std::cv_status ret = std::cv_status::timeout; if (!notified_) { - cv_.wait_until(lck, tm_pint); + ret = cv_.wait_until(lck, tm_pint); } notified_ = false; + return ret; } - void + std::cv_status Wait_For(const std::chrono::system_clock::duration& tm_dur) { std::unique_lock lck(mutex_); + std::cv_status ret = std::cv_status::timeout; if (!notified_) { - cv_.wait_for(lck, tm_dur); + ret = cv_.wait_for(lck, tm_dur); } notified_ = false; + return ret; } void