Skip to content

fix: cleanRemoteNotesのDELETEにローカルstatement_timeoutを適用#17306

Closed
pooza wants to merge 503 commits intomisskey-dev:developfrom
pooza:fix/clean-remote-notes-delete-timeout
Closed

fix: cleanRemoteNotesのDELETEにローカルstatement_timeoutを適用#17306
pooza wants to merge 503 commits intomisskey-dev:developfrom
pooza:fix/clean-remote-notes-delete-timeout

Conversation

@pooza
Copy link
Copy Markdown

@pooza pooza commented Apr 12, 2026

背景

ダイスキー本番(~980万行のnoteテーブル)で cleanRemoteNotes を有効化した後、#411#414 の一連の修正を経て 2026-04-13 にようやく crash せず完走するようになった。しかし実際の削除件数は 35件/日 と極めて少なく、ジョブログには以下のパターンが残っていた:

Deleted 1081 notes; 4606ms
Deleted 500 notes; 2967ms
...
DELETE query timed out (1783 notes), reducing limit to 25 and retrying...
Deleted 91 notes; 1968ms
Deleted 78 notes; 1895ms
DELETE query timed out (1777 notes), reducing limit to 10 and retrying...
Deleted 14 notes; 2168ms
Deleted 11 notes; 2164ms
DELETE query timed out at minimum limit (1758 notes), ending this run...

currentLimit を minimumLimit (10) まで縮小しても DELETE が statement_timeout (10s) に間に合わず、#414 の縮小リトライ後に break で終了していた。グローバル statement_timeout = 10s は対話API保護のため必要だが、巨大なリモートノートツリーの DELETE には事実上通らない。削除が必要ないサーバーでは動くが、本当に必要な規模のサーバーでは削除が進まないという逆説的な状態。

変更

DELETE クエリをトランザクションで包み、 SET LOCAL statement_timeout = '300s' で削除パスだけタイムアウトを緩和する。SET LOCAL はトランザクション終了時に自動復帰するため、他のクエリパスには影響しない。

効果(期待値)

  • minimumLimit (10) バッチでも確実に DELETE が通るようになり、chore(package): update webpack to version 2.4.1 #414 の縮小リトライ→早期break経路に入らない
  • candidate walkの cursor がより深くまで進み、1回のジョブで削除できる件数が桁違いに増える見込み
  • 1日あたりの削除ペースが改善し、現実的な期間でのクリーンアップ完了が可能に

リスク

  • 削除中はトランザクションがノート行のロックを保持するが、削除バッチは数十〜数千件単位で短期間のため実運用への影響は軽微
  • 5分は十分余裕を持った値。もし不足する規模があれば別途調整

pooza and others added 22 commits February 17, 2026 17:50
fix: AP受信時、tag配列にのみ存在するハッシュタグをテキストに補完
fix: スパムブロック時の例外をIdentifiableErrorに変更
Mastodon 4.2+のフッタータグ判定との互換性を確保。
<br />フラット構造を<p>タグ構造に変換することで、
lastChildが最後の<p>全体を取得し、末尾ハッシュタグ群が
すべてフッタータグとして認識されるようにする。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
番組選択時にdecoration: {minutes: N}をコマンドノートに含め、
モロヘイヤ側のデコレーション自動適用・時限復元を発火させる。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MkSuspenseがフラグメントコンポーネント(v-if/v-else-if/v-else)のため、
RouterViewからのattribute fallthrough(.contentクラス)が適用されず、
スクロール領域が固定高さを持たなかった。
PageWithHeaderをedit.vueのルート要素に移動し、MkSuspenseをその内部に
配置することで修正。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix: ギャラリー編集画面のモバイルスクロール不具合を修正
リモートノート自動削除を有効化するにあたり、デフォルトハッシュタグ
(config.defaultTag.tag)付きのノートはローカルコンテンツと同等に
扱い、削除対象から除外する。タグ名はハードコードせず設定から取得する。

Closes #408

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
minIdクエリがtry/catchで囲まれておらず、statement_timeoutで
ジョブ全体がcrashしていた。バッチクエリには自動縮小の仕組みが
あるが、minIdのcrashにより到達できなかった。

タイムアウト時はスキップして次回再試行する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
minIdクエリと同様に、バッチサイズ最小時のスキップ処理(idWindow)も
try/catchで囲まれておらず、タイムアウトでジョブ全体がcrashしていた。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DELETE クエリのcatchがclass 23(integrity violation)専用だったため、
statement_timeoutでジョブ全体がcrashしていた。タイムアウト時は
このrunを終了し、次回実行で再試行する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DELETE タイムアウト時に break するだけだったのを、candidateNotesQuery
と同じパターンに変更。currentLimit を 1/4 に縮小して continue し、
cursorLeft を進めずに小さいバッチで再試行する。

最小値まで下げても失敗する場合のみ break する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
グローバルstatement_timeout=10sはAPIクエリ保護のために必要だが、
数百万件規模のリモートノートツリーを削除するには短すぎる。
DELETEクエリをトランザクションで包み SET LOCAL statement_timeout='300s'
を実行することで、対話クエリの保護を維持したまま削除バッチを通す。

ダイスキー本番ではこの制約によりcurrentLimitが最小値まで縮小しても
DELETEがタイムアウトし早期break、1日の実削除が数十件に留まっていた。
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 12, 2026
@pooza
Copy link
Copy Markdown
Author

pooza commented Apr 12, 2026

Wrong fork target — recreating on pooza/misskey.

@pooza pooza closed this Apr 12, 2026
@github-project-automation github-project-automation bot moved this from Todo to Done in [実験中] 管理用 Apr 12, 2026
@github-actions github-actions bot added packages/frontend Client side specific issue/PR packages/backend Server side specific issue/PR labels Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/backend Server side specific issue/PR packages/frontend Client side specific issue/PR size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

1 participant