Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix panic caused by removing directory #38622

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/core/src/index/InvertedIndexTantivy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
16 changes: 13 additions & 3 deletions internal/core/src/storage/LocalChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -217,10 +219,18 @@
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());

Check warning on line 225 in internal/core/src/storage/LocalChunkManager.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/storage/LocalChunkManager.cpp#L222-L225

Added lines #L222 - L225 were not covered by tests
}
std::string files = boost::algorithm::join(paths, ", ");

Check warning on line 227 in internal/core/src/storage/LocalChunkManager.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/storage/LocalChunkManager.cpp#L227

Added line #L227 was not covered by tests
PanicInfo(FileWriteFailed,
fmt::format("remove local directory:{} failed, error: {}",
dir,
err.message()));
fmt::format(
"remove local directory:{} failed, error: {}, files: {}",
dir,
err.message(),
files));
}
}

Expand Down
14 changes: 8 additions & 6 deletions internal/core/thirdparty/tantivy/tantivy-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading