clear-code / redmine_full_text_search

Full text search for Redmine
MIT License
61 stars 24 forks source link

ActiveRecord::RecordNotFound (Couldn't find FullTextSearch::Tag with 'id'= ... ) #83

Closed number623 closed 4 years ago

number623 commented 4 years ago

groonga(mroonga)とプラグインのインストール後、検索を実行すると以下のエラーとなります。 原因、対処方法についてご教示いただけますでしょうか?

Started` GET "/search?utf8=%E2%9C%93&scope=&q=test" for 127.0.0.1 at 2020-03-31 01:08:17 +0900
Processing by SearchController#index as HTML
  Parameters: {"utf8"=>"✓", "scope"=>"", "q"=>"test"}
  Current user: mutsumi.namba (id=10)
[full-text-search][search] {"search_id":"1585584497.9244506","q":"test","scope":"","all_words":"1","titles_only":"0","attachments":"1","open_issues":"0","offset":0,"limit":10,"order_target":"score","order_type":"desc","options":"0","issues":"1","news":"1","documents":"1","changesets":"1","wiki_pages":"1","messages":"1","projects":"1","changes":"1","tags":[],"user_id":10,"project_id":null,"n_hits":6,"total_n_hits":6,"elapsed_time":0.0009238719940185547,"timestamp":"2020-03-30T16:08:17Z"}
  Rendering plugins/full_text_search/app/views/search/index.html.erb within layouts/base
  Rendered plugins/full_text_search/app/views/search/index.html.erb within layouts/base (31.6ms)
Completed 500 Internal Server Error in 79ms (ActiveRecord: 18.5ms)

ActiveRecord::RecordNotFound (Couldn't find FullTextSearch::Tag with 'id'=844826369):

plugins/full_text_search/lib/full_text_search/searcher.rb:333:in `block in tag_drilldown'
plugins/full_text_search/lib/full_text_search/searcher.rb:331:in `collect'
plugins/full_text_search/lib/full_text_search/searcher.rb:331:in `tag_drilldown'
plugins/full_text_search/lib/full_text_search/searcher.rb:340:in `tag_drilldowns'
plugins/full_text_search/app/views/search/index.html.erb:128:in `_plugins_full_text_search_app_views_search_index_html_erb__779642241605352108_53493420'
lib/redmine/sudo_mode.rb:65:in `sudo_mode'

環境 ・OS: CentOS 6.10 ・Redmine: 4.1.0.stable ・redmine_full_text_search: 1.0.4 ・mroonga:V10.01 ・Rails:5.2.4.1 ・MySQL2: 5.6

kou commented 4 years ago

どうやってインストールしたか具体的なコマンドとその結果を教えてもらえますか?

grep 844826369 log/production.logの結果を見せてもらえますか?

私の環境でも再現できるように再現手順を用意できますか?

number623 commented 4 years ago

インストールコマンドとそのログを添付いたしました。 初回インストール時にログをとっていませんでしたので、一旦removeしてから改めてインストールしたものです。

grep の結果は以下でした。

[namba@CentOS log]$ grep 844826369 production.log 
ActiveRecord::RecordNotFound (Couldn't find FullTextSearch::Tag with 'id'=844826369):
ActiveRecord::RecordNotFound (Couldn't find FullTextSearch::Tag with 'id'=844826369):
ActiveRecord::RecordNotFound (Couldn't find FullTextSearch::Tag with 'id'=844826369):

手順としてはインストール後redmineを開いて検索ボックスから検索を実行しただけなのですが、もしデータベースの内容依存等の場合、データの提供はすみませんが難しいです。

install_log.txt

kou commented 4 years ago

ありがとうございます。 RAILS_ENV=production bin/rails full_text_search:synchronizeでの処理対象のレコード数が0なのですが、これは問題が発生している環境で実行した結果ですか?それともログ取得用に用意した環境で実行した結果ですか?

確実にデータベースの内容に依存しています。 ただ、こちらとして実データでなく、実データを元に作ったダミーデータでも問題ない(手元で現象を再現させたいだけだから)のですが、問題が再現するダミーデータの作成には協力できますか?できなそうならこれ以上の調査はできないのでこのissueはクローズしたほうがいいと思っています。

協力できそうであれば、RAILS_ENV=production bin/rails consoleで次の式を実行して得られるレコードの中にこの問題に関連している可能性が高いのでこの情報を元に再現手順を確立してもらうことになります。

FullTextSearch::Target.full_text_search("tag_ids", "*SS tag_ids @ 9") # .limit(10)をつけると先頭10件を取得できる
number623 commented 4 years ago

処理対象レコード数が0の件については、問題が発生している環境で改めて実行した結果です。(それ以前に既に同期化処理は済ませています。) ダミーデータ作成のご協力につきましては問題ありません。 以下実行結果です。

[root@CentOS redmine]# RAILS_ENV=production bin/rails console
Loading production environment (Rails 5.2.4.1)
irb(main):001:0> FullTextSearch::Target.full_text_search("tag_ids", "*SS tag_ids @ 9")
=> #<ActiveRecord::Relation []>
kou commented 4 years ago

あぁ、すみません。9ではなくて844826369にしないといけなかったです。

FullTextSearch::Target.full_text_search("tag_ids", "*SS tag_ids @ 844826369") # .limit(10)をつけると先頭10件を取得できる

ダミーデータの作成、よろしくおねがいします。

number623 commented 4 years ago

同じ結果になりました。

irb(main):002:0> FullTextSearch::Target.full_text_search("tag_ids", "*SS tag_ids @ 844826369") 
=> #<ActiveRecord::Relation []>
kou commented 4 years ago

うーん、であれば、これ以上の調査はキビシイです。。。

number623 commented 4 years ago

わかりました。 本件クローズいたしますが、特にバージョンの組み合わせについては問題は無いでしょうか? 今後の環境構築の参考にいたします。

kou commented 4 years ago

このエラーがあってもwarningログを出力するようにして処理を継続するようにしたので少なくともこのエラーで結果がでないということはなくなったと思います。

ただ、検索するたびに毎回次のようなログがでるはずです。

[full-text-search][searcher][drilldown][tag] unknown tag ID exists: 844826369(XXX): related target IDs: [AAA, BBB, ...]

AAA, BBB, ...のところに数値が出たら、FullTextSearch::Target.find(数値)とかFullTextSearch::Target.find(数値).source_recordすれば怪しそうなデータの情報が得られるはずです。それらの情報で再現用のデータを作れたら新しくissueを作って調査に協力してください。

バージョンの組み合わせは問題なさそうにみえますが、CentOS 6は今年の11月一杯でEOLになって、MySQL 5.6は来年の2月にはEOLになるので、今のうちにアップデートしておいたほうがよいとは思います。

number623 commented 4 years ago

ありがとうございます。 問題となるチケット群は特定できました。(正常なチケットとの差異はまだ特定できていません) ちなみにですが、searcher.rb:345行目はrails → Railsに変更しないとエラーになりました。 当該チケット群はredmine立ち上げ時のお試しのものばかりでしたので、削除しても支障は無く、データの提供も可能です。別途起票いたしますが、mysqldumpしたものでよろしいでしょうか?

kou commented 4 years ago

問題となるチケット群は特定できました。

よかったです。

ちなみにですが、searcher.rb:345行目はrails → Railsに変更しないとエラーになりました。

おぉ。。。直しました。

当該チケット群はredmine立ち上げ時のお試しのものばかりでしたので、削除しても支障は無く、データの提供も可能です。別途起票いたしますが、mysqldumpしたものでよろしいでしょうか?

再現するならそれでもいいので手元でそれをリストアして再現するか試してもらえますか? (再現しないような気がします。)