Open davideuler opened 1 year ago
Maybe calling IndexWriter::wait_merging_threads
already suffices?
Thanks for your help. I tried and tested the method, it didn't work as IndexWriter.close() as expected.
The method IndexWriter::wait_merging_threads could not be called in C++ through CXX bridge. CXX need to pass reference to rust function in C++.
pub fn wait_merging_threads(self) -> Result<()>
I need to change the signature as following to pass mutable reference for invoking in C++:
pub fn wait_merging_threads(& mut self) -> Result<()>
After I update the signature in Rust IndexWriter::wait_merging_threads(& mut self), I can call it in C++ by CXX, But still need to wait some milliseconds to remove the index directory.
void removeIndex() override {
index.wait_merging_threads(); // Cxx bridge for IndexWriter::wait_merging_threads(& mut self)
index.reset(); // after reset();
std::this_thread::sleep_for(std::chrono::milliseconds (300)); // the remove_all(path) works after sleep_for().
std::filesystem::remove_all(path);
}
You are on windows I assume?
I am on Mac .
ah right, the bug is about the directory being non empty... not about a file being protected for delete.
Is your feature request related to a problem? Please describe. I am calling Tantivy to create index and search in C++ project. We create indexes for each customer to provide search service. And when customer ask to delete their index by API, we will delete requested index. When deleting the index, error occurs as :
The Rust part for Searcher (by CXX).
Here is the related code in C++.
I checked the source code in Tantivy, and guess it is caused by background indexing threads.
Describe the solution you'd like
I think we need API to close tantivy index properly in such case.
[Optional] describe alternatives you've considered As a workaround, sleep some milliseconds after resetting/dropping the IndexWriter, the index directory can be removed successfully, as: