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

Expose IndexWriter::wait_merging_threads() #100

Merged
merged 3 commits into from
Jul 22, 2023

Conversation

GodTamIt
Copy link
Contributor

This can be useful if certain clients wants to wait for the merging to finish before issuing further commits.

@cjrh
Copy link
Collaborator

cjrh commented Jul 22, 2023

Looks good. Can you add a test (in python) that calls the new wait method? Like a python version of one of these in the tantivy tests, e.g.

    #[test]
    fn test_with_merges() -> crate::Result<()> {
        let mut schema_builder = schema::Schema::builder();
        let text_field = schema_builder.add_text_field("text", TEXT);
        let index = Index::create_in_ram(schema_builder.build());
        let reader = index
            .reader_builder()
            .reload_policy(ReloadPolicy::Manual)
            .try_into()?;
        let num_docs_containing = |s: &str| {
            let term_a = Term::from_field_text(text_field, s);
            reader.searcher().doc_freq(&term_a).unwrap()
        };
        // writing the segment
        let mut index_writer = index.writer(12_000_000).unwrap();
        // create 8 segments with 100 tiny docs
        for _doc in 0..100 {
            index_writer.add_document(doc!(text_field=>"a"))?;
        }
        index_writer.commit()?;
        for _doc in 0..100 {
            index_writer.add_document(doc!(text_field=>"a"))?;
        }
        //  this should create 8 segments and trigger a merge.
        index_writer.commit()?;
        index_writer.wait_merging_threads()?;
        reader.reload()?;
        assert_eq!(num_docs_containing("a"), 200);
        assert!(index.searchable_segments()?.len() < 8);
        Ok(())
    }

Or if you have a simpler idea for a test that's fine too.

src/index.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@adamreichold adamreichold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really not sure about which way to go with the exception, otherwise looks fine to me.

@GodTamIt
Copy link
Contributor Author

GodTamIt commented Jul 22, 2023

I went with a RuntimeError there. Nothing fits perfectly here, but based on the documentation, RuntimeError seems to be the appropriate catch-all.

This change can be squash-merged

@cjrh cjrh merged commit 35ed22e into quickwit-oss:master Jul 22, 2023
10 checks passed
@GodTamIt GodTamIt deleted the godtamit-wait-upstream branch September 27, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants