server が再生成された DB を再起動なしで読み直すようにする#276
Merged
Merged
Conversation
rake generate 後の修正→確認サイクルで、DB を再生成するたびに bitclust server を再起動しないと新しい内容が反映されない問題を解消する (fix rurema#275)。 App#initialize は MethodDatabase/FunctionDatabase と RequestHandler を 起動時に一度だけ生成し、Interface がそれを保持し続けていた。DB はエント リを一度読むとメモリ上にメモ化するため、ディスク上で DB を再生成しても プロセスは古い内容を返し続けていた。 ReloadableRequestHandler で RequestHandler をラップし、DB ディレクトリ 直下の properties ファイルの mtime を毎リクエスト stat して新鮮さを判定 する。mtime が変われば MethodDatabase/FunctionDatabase と RequestHandler を作り直し、$bitclust_context_cache もクリアする。dbpath が String (単一 DB)/Array(複数バージョン)のどちらでも、Rack/WEBrick どちらの ハンドラでも同様に動作する。 再生成の途中への手当ても入れた: - rm_rf 直後〜init 前は properties が存在しないため、新鮮さを判定できず 古いハンドラを使い続ける(リクエストを失敗させず、次のリクエストで再判定) - init 後〜update 完了前にリクエストが来ると init 時点の mtime で途中状態 の DB を掴んでしまうため、Database#transaction が commit 後に properties の mtime を進める(内容は変えず touch のみ)。これにより update 完了時に 必ず mtime が変わり、途中状態を読んだプロセスも次のリクエストで完成した DB に収束する Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
rake generate後にbitclust serverを再起動しなくても新しい内容が反映されるようにします(fix #275)。App#initializeが起動時に一度だけ DB と RequestHandler を生成して持ち続け、DB はエントリをメモリにメモ化するため、ディスク上の再生成がプロセスから見えませんでしたReloadableRequestHandlerで RequestHandler をラップし、リクエストごとに DB のpropertiesファイルの mtime を stat して新鮮さを判定します(stat 1回なのでコストは無視できるため、フラグ不要のデフォルト動作にしています。server は開発・プレビュー用途のため)。変わっていたら MethodDatabase/FunctionDatabase とハンドラを作り直し、$bitclust_context_cacheもクリアします。単一 DB / 複数バージョン(--capi含む)・Rack / WEBrick の全形態で動作しますpropertiesが無い間)は旧内容を提供し続け、リクエストを失敗させません(次のリクエストで再判定)Database#transactionが commit 後にpropertiesを touch(内容は変えず mtime のみ)するため、update 完了時に必ず mtime が変わり、次のリクエストで完成した DB に収束します検証
properties欠落中の継続提供・--capiの FunctionDatabase 再読込・generate 途中にリクエスト→ update 完了後に収束)。17756 → 17762 tests / 0 failures・rbs validate・steep checkエラーなしbitclust server起動 → curl → DB を再生成(サーバー再起動なし)→ curl で新しい内容が返ることを確認🤖 Generated with Claude Code