fix: querynode hang when failing to allocate disk space for mmap(#35184) (#35187)

related: #35184

Signed-off-by: MrPresent-Han <chun.han@gmail.com>
Co-authored-by: MrPresent-Han <chun.han@gmail.com>
pull/35383/head^2
Chun Han 2024-08-19 15:30:55 +08:00 committed by GitHub
parent 14ef88f423
commit 337e065902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 7 deletions

View File

@ -53,18 +53,37 @@ ChunkCache::Read(const std::string& filepath,
// release lock and perform download and decode
// other thread request same path shall get the future.
auto field_data = DownloadAndDecodeRemoteFile(cm_.get(), filepath);
auto column = Mmap(field_data->GetFieldData(), descriptor);
// set promise value to notify the future
lck.lock();
std::unique_ptr<DataCodec> field_data;
std::shared_ptr<ColumnBase> column;
bool allocate_success = false;
ErrorCode err_code = Success;
std::string err_msg = "";
try {
field_data = DownloadAndDecodeRemoteFile(cm_.get(), filepath);
column = Mmap(field_data->GetFieldData(), descriptor);
allocate_success = true;
} catch (const SegcoreError& e) {
err_code = e.get_error_code();
err_msg = fmt::format("failed to read for chunkCache, seg_core_err:{}",
e.what());
}
std::unique_lock mmap_lck(mutex_);
it = columns_.find(filepath);
if (it != columns_.end()) {
// check pair exists then set value
it->second.first.set_value(column);
if (allocate_success) {
AssertInfo(column, "unexpected null column, file={}", filepath);
}
} else {
PanicInfo(UnexpectedError,
"Wrong code, the thread to download for cache should get the "
"target entry");
}
if (err_code != Success) {
columns_.erase(filepath);
throw SegcoreError(err_code, err_msg);
}
lck.unlock();
AssertInfo(column, "unexpected null column, file={}", filepath);
return column;
}