-
Notifications
You must be signed in to change notification settings - Fork 0
observe: keep body generations aligned with retained logs (#134) #146
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a62a77e
observe: keep body generations aligned with retained logs (#134)
koriym f0df838
保持世代数を 100 に戻す
koriym 80ba6f2
剪定の rmdir を競合安全にする
koriym 740d357
Merge remote-tracking branch 'origin/1.x' into observe-body-retention
koriym fdfcd88
body 世代をログより多く作らない
koriym 577affd
剪定の catch が何を飲み込むかを正確に書く
koriym c09fc26
剪定の対象を body store が所有するディレクトリに限る
koriym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MyVendor\BeMart\Module; | ||
|
|
||
| use BEAR\EventSourcing\Resource\BodyStoreInterface; | ||
| use BEAR\EventSourcing\Resource\FileBodyStore; | ||
| use BEAR\Resource\AbstractRequest; | ||
| use BEAR\Resource\ResourceObject; | ||
| use Override; | ||
|
|
||
| /** | ||
| * Creates the generation directory only once a body is actually stored. | ||
| * | ||
| * `FileBodyStore::__construct()` creates its directory eagerly, and `ObserveModule::configure()` | ||
| * runs on every injector build — before routing decides the request method. A request that records | ||
| * nothing (an `OPTIONS` preflight never reaches `SemanticLogInvoker`'s recorded methods, and | ||
| * `LogFileWriter::write()` returns early when nothing was opened) would therefore add a generation | ||
| * directory while adding no log session. Retention counts the two separately, so the body window | ||
| * would advance ahead of the log window and eventually prune a generation a still-retained log's | ||
| * `body_ref` points at — the failure {@see \MyVendor\BeMart\Module\ObserveModule} exists to prevent. | ||
| * | ||
| * Deferring construction makes a generation strictly imply a stored body, and a stored body implies | ||
| * a recorded request, so generations can only ever be rarer than log sessions. Bodies then outlive | ||
| * the logs referencing them for any retention count the two share. | ||
| */ | ||
| final class DeferredFileBodyStore implements BodyStoreInterface | ||
| { | ||
| private FileBodyStore|null $store = null; | ||
|
|
||
| public function __construct(private readonly string $dir) | ||
| { | ||
| } | ||
|
|
||
| #[Override] | ||
| public function __invoke(AbstractRequest $request, ResourceObject $ro): string|null | ||
| { | ||
| $this->store ??= new FileBodyStore($this->dir); | ||
|
|
||
| return ($this->store)($request, $ro); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: be-framework/BeMart
Length of output: 24090
🏁 Script executed:
Repository: be-framework/BeMart
Length of output: 42219
body世代の作成直後に保持処理を実行してください。
ObserveModule::configure()と生成テンプレートは、新しい世代ディレクトリの作成前にだけ prune します。既存世代が100件ある場合、DeferredFileBodyStoreの初回呼び出しで101件目が作成されます。DevQueryRepositoryLogModuleの prune はログだけを対象とするため、101件目は次回の injector 構築まで残ります。これは
KEEP_GENERATIONS = 100の上限に違反します。ただし、余分な世代が残るだけであり、保持中のログのbody_refは失われません。保持ポリシーは
ObserveModuleに置き、prune callback をDeferredFileBodyStoreと生成される匿名 store に渡してください。初回のFileBodyStore作成直後に callback を実行し、現行世代を含めて古い世代を削除してください。🤖 Prompt for AI Agents