Skip to content

GTFS integrate前にgtfs_*をANALYZEしてハングを修正#1526

Merged
TinyKitten merged 2 commits into
devfrom
fix/gtfs-integrate-analyze
May 15, 2026
Merged

GTFS integrate前にgtfs_*をANALYZEしてハングを修正#1526
TinyKitten merged 2 commits into
devfrom
fix/gtfs-integrate-analyze

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

@TinyKitten TinyKitten commented May 15, 2026

概要

GTFSデータ統合 (integrate_gtfs_to_stations) が build_stop_route_mapping でハングする問題を、integrate 実行前に gtfs_* テーブルを ANALYZE することで修正。

変更の種類

  • バグ修正
  • 新機能
  • データの修正・追加
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • ECS(サイドカー PostgreSQL)環境で GTFS データ取り込み後の統合処理が build_stop_route_mapping の重い CTE クエリで実質ハングしていた問題を修正
  • 根本原因: import_csv 末尾の ANALYZE; は CSV と GTFS が並行実行されているタイミングで動くため、gtfs_* テーブルが空または途中状態で統計が取られていた。その結果、integrate_gtfs_to_stations 実行時に PostgreSQL が「空テーブル」前提の劣悪な実行計画(Nested Loop など)を選び、gtfs_stop_times への巨大ジョインで進まなくなっていた
  • 対処: gtfs_handle.await 成功後・integrate_gtfs_to_stations 呼び出し前に gtfs_* 9テーブルを個別に ANALYZE し、最新統計を埋める
  • 副次変更: import_gtfs / integrate_gtfs_to_stations / download_gtfs の各ステップに経過時間付き進捗ログを追加(今回のハング箇所特定に使用。今後の運用診断にも有用なため残置)

テスト

  • cargo fmt --all -- --check が通ること
  • cargo clippy -- -D warnings が通ること
  • cargo test(SQLX_OFFLINE=true)が通ること

ECSステージング環境で chore/gtfs-debug-logs ブランチを deploy し、[integrate] routes_to_lines done の後にハングする挙動を確認。ANALYZE 追加後の動作確認は本 PR マージ前のステージング deploy で行う。

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

リリースノート

  • 改善
    • GTFSデータのダウンロード・インポート・統合処理における実行時間の計測とログ記録を強化
    • エラーメッセージをより詳細に表示
    • データベース統計情報の更新処理を追加し、クエリ最適化を改善

Review Change Stack

TinyKitten and others added 2 commits May 16, 2026 08:21
ECSデプロイ後にGTFSデータが入らない事象の切り分けのため、
import_gtfs / integrate_gtfs_to_stations / download_gtfs と
main.rs の gtfs_handle.await 周辺の各ステップに経過時間付きの
info ログを追加。

これにより、ダウンロード・HTTP応答・DB接続・各サブテーブルの
DELETE/INSERT・transaction commit のどこでハングしているか
特定可能になる。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
build_stop_route_mappingでハングする問題への対処。
CSV側のANALYZEがgtfs_*テーブル空のタイミングで走るため、
integrate実行時に統計情報が0行ベースのまま劣悪なplanが選ばれていた。
GTFSインポート完了直後、integrate呼び出し前に
gtfs_*の9テーブルをANALYZEして最新統計を埋める。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this May 15, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9734dd9a-68bf-47f2-8e6f-5321c2d543ce

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb5aa0 and 9398c1b.

📒 Files selected for processing (2)
  • stationapi/src/import.rs
  • stationapi/src/main.rs

📝 Walkthrough

Walkthrough

GTFSインポートパイプラインの各段階に計測用Instantと詳細ログを追加し、処理の可観測性を向上させました。HTTP取得、データベース接続、トランザクション管理、個別のインポート・統合ステップの所要時間とステータスを記録し、統合前にデータベース統計情報を更新する処理も導入しました。

Changes

GTFS Import Pipeline Observability

Layer / File(s) Summary
download_gtfs timing instrumentation
stationapi/src/import.rs
HTTP取得・レスポンス受信・ボディ読込各段階でInstantによる計測を追加し、ステータスコード・所要時間・バイト数をtracingログで記録。
import_gtfs pipeline instrumentation
stationapi/src/import.rs
ダウンロード、抽出、トランスレーション読込、DB接続、トランザクション開始、既存データクリア、各GTFSファイル取込ステップ(agencies/routes/stops/calendar/calendar_dates/shapes/trips/stop_times/feed_info)、コミットの各段階をInstantで区切り、所要時間と件数をログ出力。
integrate_gtfs_to_stations instrumentation
stationapi/src/import.rs
DB接続、gtfs_routes件数取得、トランザクション開始、既存バスデータクリア、統合サブステップ(routes_to_lines、stop_route_mapping、stops_to_stations、crossreferences、trip_variations_to_types)、コミットをInstantで計測し、各ステップの完了と合計所要時間をログ出力。
main.rs import orchestration observability and statistics refresh
stationapi/src/main.rs
GTFSインポート完了待機の経過時間をログ出力し、統合前にgtfs_agenciesなどのgtfs_*テーブルへANALYZEを実行して統計情報を更新。接続・実行失敗時は警告ログを記録しつつ処理継続。

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • TrainLCD/StationAPI#1516: integrate_gtfs_to_stationsの同一処理単位に対して、本PRはログ・計測機能を、#1516はBus TrainType登録ステップを追加しており、関連して います。
  • TrainLCD/StationAPI#1525: stationapi/src/main.rsrun()内GTFS取込後のintegrate_gtfs_to_stations()呼び出しフロー周辺で、本PR追加のANALYZEと計測ログが同一箇所の変更と直結しています。

Suggested labels

fix

Poem

🐰 計測と観測で道は明るく、
タイミング足跡、ログで輝く。
GTFSの流れ、今は見える、
各段階の時は数字で映える。
インポート、統合、統計更新も、
ウサギの目には透き通る!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはGTFS integrate前にgtfs_*をANALYZEしてハングを修正する主な変更内容を明確に表しており、変更セットの主要な目的と一致しています。
Description check ✅ Passed 説明はテンプレートの必須セクション(概要、変更の種類、変更内容、テスト)を適切に埋めており、ハングの原因分析、対処方法、副次変更、テスト実施状況が詳細に記載されています。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/gtfs-integrate-analyze

Comment @coderabbitai help to get the list of available commands and usage tips.

@TinyKitten TinyKitten merged commit d854d6e into dev May 15, 2026
11 checks passed
@TinyKitten TinyKitten deleted the fix/gtfs-integrate-analyze branch May 15, 2026 23:26
@TinyKitten TinyKitten mentioned this pull request May 17, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant