検索機能変更の影響かも知れないエラー
検索機能変更の影響かも知れないエラー
Tantivyのアップグレードの影響かな…
code:searcher.rs
pub fn open(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> {
println!("0: {:?}", (*path).as_ref().to_str());
let mut index =
Index::open(MmapDirectory::open(path).map_err(|e| {
println!("1: {:?}", e);
SearcherError::IndexOpeningError
})?)
.map_err(|e| {
println!("2: {:?}", e);
SearcherError::IndexOpeningError
})?;
code:shell
0: Some("search-index2")
2: PathDoesNotExist("meta.json")
thread 'main' panicked at '
Plume was unable to open the search index. If you created the index
before, make sure to run Plume in the same directory it was created in, or
to set SEARCH_INDEX accordingly. If you did not yet create the search
index, run this command:
plm search init
Then try to restart Plume
', src/main.rs:114:49
ファイルあるけどな・・・
試しにtouch search-index2/meta.jsonしてみたらエラーメッセージが変わった
code:shell
0: Some("search-index2")
2: DataCorruption(Data corruption: (in file "meta.json"): Meta file cannot be deserialized. Error("EOF while parsing a value", line: 1, column: 0)..)
openとcreateでパスの解釈が違うのでは…
これは単に作る側のオペレーションがおかしかっただけ。最初からやり直したらうまくいった
うまくいきすぎた。サーバーが起動してしまった。
と思ったけどこれまでv0.4.0のつもりで実行してた物が0.5.0だったかもしれない。それならうまくいくよな。
やり直し。
0.4.0と0.5.0で別々のディレクトリーにチェックアウトして、plumeとplmをビルドする
問題が起こることを確認
0.4.0で検索インデックスを作成
code:v0.4.0
% SEARCH_INDEX=/tmp/plume-search-index ./target/debug/plm search init
no .env was found
Commiting result
0.5.0で起動
code:v0.5.0
% SEARCH_INDEX=/tmp/plume-search-index ./target/debug/plume
no .env was found
thread 'main' panicked at 'called Result::unwrap() on an Err value: IndexCreationError', src/main.rs:126:18
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.
よしよし、ちゃんとエラーになってくれた。
問題の検出方法を調べる
0.5.0でどういう風にエラーが起こるかを調べる。
今は上のレイヤーでラップされちゃって情報がなんもない。
code:v0.5.0.diff
diff --git a/plume-models/src/search/searcher.rs b/plume-models/src/search/searcher.rs
index a1f4c81..f681e4c 100644
--- a/plume-models/src/search/searcher.rs
+++ b/plume-models/src/search/searcher.rs
@@ -129,13 +129,15 @@ impl Searcher {
.garbage_collect(|| files)
.map_err(|_| SearcherError::IndexEditionError)?;
+ let reader = index
+ .reader_builder()
+ .reload_policy(ReloadPolicy::Manual)
+ .try_into()
+ .unwrap();
+
Ok(Self {
writer: Mutex::new(Some(writer)),
- reader: index
- .reader_builder()
- .reload_policy(ReloadPolicy::Manual)
- .try_into()
- .map_err(|_| SearcherError::IndexCreationError)?,
+ reader: reader,
index,
})
}
code:v0.5.0
% SEARCH_INDEX=/tmp/plume-search-index cargo run
(snip)
no .env was found
thread 'main' panicked at 'called Result::unwrap() on an Err value: IOError(IOError { path: Some("b87aec3eaf64434e88a30d024c6be24f.term"), err: Custom { kind: InvalidData, error: "stream did not contain valid UTF-8" } })', plume-models/src/search/searcher.rs:132:22
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.
InvalidDataとやらを見付けたらインデックス作り直すようにしたらいいかしら
作り直すならどこがいいか?
Searcher::opne()?
main.rs?
このちょっと前で
code:plume-models/src/search/searcher.rs
index
.directory_mut()
.garbage_collect(|| files)
.map_err(|_| SearcherError::IndexEditionError)?;
してる箇所があるけど、IndexEditionErrorってどういう時に使うんだろう、名前的には今回のケースも相応しそうだけど。
editionという言葉の意味によるか。Tantiyの用語なのか検索エンジン分野の用語なのか。
ああ、第二版とかの「版」かと思ったら、編集の名詞か。
code:managed_directory.rs
pub fn garbage_collect<L: FnOnce() -> HashSet<PathBuf>>(
&mut self,
get_living_files: L
) -> Result<GarbageCollectionResult>
This method does not panick nor returns errors. If a file cannot be deleted (for permission reasons for instance) an error is simply logged, and the file remains in the list of managed files.
じゃあ、carbage_collectのエラーを捕まえる必要はないんじゃん…
初登場時はこういうコードだった
code:plume-models/src/search/searcher.rs
let mut writer = index.writer(50_000_000).map_err(|_| SearcherError::WriteLockAcquisitionError)?;
writer.garbage_collect_files().map_err(|_| SearcherError::IndexEditionError)?;
この頃はTantivy 0.10.1
これも.directory_mut().garbage_collect()に行き着く
今回のインデックスの構造が違うのは「編集」のエラーではないから、新しいエラー型を作って返すのがいいな。
TODO
Plumeのv0.4.0とv0.5.0で構造が違うことを確認 変換方法を見付ける
0.11に上がる時と0.12に上がる時の二回ある
0.12の時はカスタムトークナイザーに非互換があるというやつで、これは対応済み
0.11の時は以下の通り:
The index format is changed. You are required to reindex your data to use tantivy 0.11.
plm search refillっていうコマンドがあるな。これの実装見て真似したらいけるのでは
インデックスフォーマットが違うことを検出する方法はやっぱり必要
Plume起動時に変換するようにする