mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 01:02:55 +00:00
* add checksum check in ManagedDirectory fix #400 * flush after writing checksum * don't checksum atomic file access and clone managed_paths * implement a footer storing metadata about a file this is more of a poc, it require some refactoring into multiple files `terminate(self)` is implemented, but not used anywhere yet * address comments and simplify things with new contract use BitOrder for integer to raw byte conversion consider atomic write imply atomic read, which might not actually be true use some indirection to have a boxable terminating writer * implement TerminatingWrite and make terminate() be called where it should add dependancy to drop_bomb to help find where terminate() should be called implement TerminatingWrite for wrapper writers make tests pass /!\ some tests seems to pass where they shouldn't * remove usage of drop_bomb * fmt * add test for checksum * address some review comments * update changelog * fmt
68 lines
2.3 KiB
Rust
68 lines
2.3 KiB
Rust
use fail;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
use tantivy::directory::{Directory, ManagedDirectory, RAMDirectory, TerminatingWrite};
|
|
use tantivy::doc;
|
|
use tantivy::schema::{Schema, TEXT};
|
|
use tantivy::{Index, Term};
|
|
|
|
#[test]
|
|
fn test_failpoints_managed_directory_gc_if_delete_fails() {
|
|
let _scenario = fail::FailScenario::setup();
|
|
|
|
let test_path: &'static Path = Path::new("some_path_for_test");
|
|
|
|
let ram_directory = RAMDirectory::create();
|
|
let mut managed_directory = ManagedDirectory::wrap(ram_directory).unwrap();
|
|
managed_directory
|
|
.open_write(test_path)
|
|
.unwrap()
|
|
.terminate()
|
|
.unwrap();
|
|
assert!(managed_directory.exists(test_path));
|
|
// triggering gc and setting the delete operation to fail.
|
|
//
|
|
// We are checking that the gc operation is not removing the
|
|
// file from managed.json to ensure that the file will be removed
|
|
// in the next gc.
|
|
//
|
|
// The initial 1*off is there to allow for the removal of the
|
|
// lock file.
|
|
fail::cfg("RAMDirectory::delete", "1*off->1*return").unwrap();
|
|
managed_directory.garbage_collect(Default::default);
|
|
assert!(managed_directory.exists(test_path));
|
|
|
|
// running the gc a second time should remove the file.
|
|
managed_directory.garbage_collect(Default::default);
|
|
assert!(
|
|
!managed_directory.exists(test_path),
|
|
"The file should have been deleted"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_write_commit_fails() {
|
|
let _fail_scenario_guard = fail::FailScenario::setup();
|
|
let mut schema_builder = Schema::builder();
|
|
let text_field = schema_builder.add_text_field("text", TEXT);
|
|
let index = Index::create_in_ram(schema_builder.build());
|
|
|
|
let mut index_writer = index.writer_with_num_threads(1, 3_000_000).unwrap();
|
|
for _ in 0..100 {
|
|
index_writer.add_document(doc!(text_field => "a"));
|
|
}
|
|
index_writer.commit().unwrap();
|
|
fail::cfg("RAMDirectory::atomic_write", "return(error_write_failed)").unwrap();
|
|
for _ in 0..100 {
|
|
index_writer.add_document(doc!(text_field => "b"));
|
|
}
|
|
assert!(index_writer.commit().is_err());
|
|
|
|
let num_docs_containing = |s: &str| {
|
|
let term_a = Term::from_field_text(text_field, s);
|
|
index.reader().unwrap().searcher().doc_freq(&term_a)
|
|
};
|
|
assert_eq!(num_docs_containing("a"), 100);
|
|
assert_eq!(num_docs_containing("b"), 0);
|
|
}
|