fix: Fix panic caused by removing directory (#38622)

https://github.com/milvus-io/milvus/issues/38604

---------

Signed-off-by: sunby <sunbingyi1992@gmail.com>
pull/38984/head
Bingyi Sun 2025-01-06 10:54:54 +08:00 committed by GitHub
parent 0a2c964bb8
commit f0cddfd160
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 9 deletions

View File

@ -103,6 +103,9 @@ InvertedIndexTantivy<T>::InvertedIndexTantivy(
template <typename T>
InvertedIndexTantivy<T>::~InvertedIndexTantivy() {
if (wrapper_) {
wrapper_->free();
}
auto local_chunk_manager =
storage::LocalChunkManagerSingleton::GetInstance().GetChunkManager();
auto prefix = path_;

View File

@ -15,6 +15,8 @@
// limitations under the License.
#include "LocalChunkManager.h"
#include "boost/algorithm/string/join.hpp"
#include "boost/filesystem/directory.hpp"
#include "log/Log.h"
#include <boost/filesystem.hpp>
@ -217,10 +219,18 @@ LocalChunkManager::RemoveDir(const std::string& dir) {
boost::system::error_code err;
boost::filesystem::remove_all(dirPath, err);
if (err) {
boost::filesystem::directory_iterator it(dirPath);
std::vector<std::string> paths;
for (; it != boost::filesystem::directory_iterator(); ++it) {
paths.push_back(it->path().string());
}
std::string files = boost::algorithm::join(paths, ", ");
PanicInfo(FileWriteFailed,
fmt::format("remove local directory:{} failed, error: {}",
dir,
err.message()));
fmt::format(
"remove local directory:{} failed, error: {}, files: {}",
dir,
err.message(),
files));
}
}

View File

@ -588,23 +588,25 @@ struct TantivyIndexWrapper {
return reader_;
}
private:
void
check_search() {
// TODO
}
void
free() {
if (writer_ != nullptr) {
tantivy_free_index_writer(writer_);
writer_ = nullptr;
}
if (reader_ != nullptr) {
tantivy_free_index_reader(reader_);
reader_ = nullptr;
}
}
private:
void
check_search() {
// TODO
}
private:
bool finished_ = false;
IndexWriter writer_ = nullptr;