Upgrade to Pro — share decks privately, control downloads, hide ads and more …

データベースにプログレッシブデリバリーを導入しよう

nnaka2992
April 30, 2024
13

 データベースにプログレッシブデリバリーを導入しよう

2024年4月26日に開催した以下のイベントでの登壇資料です。

Jagu'e'r Observability-SRE分科会 Meetup#7 ハイブリッド
開発者に捧げる Site Reliability Engineering
https://jaguer.connpass.com/event/314081/

アプリケーションではブルーグリーンデプロイメントやカナリーリリースといった継続的デリバリーの手法により、安全なアプリケーションへの変更が確立されています。
データベースではステートを持つという特性から、アプリケーションほど柔軟なリリースを行うことが困難でした。

しかしデータベースの障害は可用性違反を一発で引き起こすため、データベースにこそロールバックが容易な段階的なデリバリープロセスが必要となります。
この資料ではデータベースでブルーグリーンデプロイメントを実践するテクニックを紹介します。

nnaka2992

April 30, 2024
Tweet

Transcript

  1. \du 2 株式会社スリーシェイク Sreake事業部 業務内容 • DBRE兼SRE見習い ◦ データベースを中心にインフラ・アプリ領域もがんばってます •

    自称データ雑用係 ◦ DBAでもDBREでもデータエンジニアでも 最近注目しているデータベース • Tsurugi • YugabyteDB 中楯 直希 @nnaka2992 @nnaka2992.bsky.social
  2. アプリケーションのプログレッシブデリバリーとの違い : データベースの復旧 7 データベースを復旧する場合リードタイムが長い • バックアップから復旧する場合最低でも数時間。 ◦ ひどい場合は数日 ◦

    バックアップの取得方法やアプリケーションの実装によっては 復旧できないデータも データベースこそプログレッシブデリバリーをするべきでは?
  3. データベースにおける変更とは? : データベースバージョンの変更 17 ブルーグリーンアップデートの手順 4 - a. アプリケーションの向き先を Green

    に変更 Cloud SQL for PostgreSQL 15 Cloud Run SQLを実行 Cloud SQL PostgreSQL 16 一番簡単なもののロールバックは出来ない ロールバックを諦められるなら このパターンを利用するべき
  4. データベースにおける変更とは? : データベースバージョンの変更 18 ブルーグリーンアップデートの手順 4 - b. アプリケーションの向き先に Green

    を変更し、逆方向レプリケーションを設定 Cloud SQL for PostgreSQL 15 Cloud Run SQLを実行 Cloud SQL PostgreSQL 16 Blue から Green にレプリ ケーションを実行 ひと手間かかるものの ニアリアルタイムのロールバックが 可能に!
  5. データベースにおける変更とは? : データベースバージョンの変更 19 ブルーグリーンアップデートの手順 4 - c. アプリケーションの向き先に Green

    を追加する Cloud SQL for PostgreSQL 15 Cloud Run SQLを実行 Cloud SQL PostgreSQL 16 データベースは楽できるものの アプリケーションの改修が必要に
  6. データベースにおける変更とは? : テーブルの変更 24 ブルーグリーンアップデートの手順(fullnameカラムの分割) 2. fullname カラムを firstname /

    lastname カラムに分割してインサートする Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname スペース等で区切って INSERT INSERTは細かいバッチサイズで 実行すること! 大きなサイズで行くとロック範囲が大きく大障害に ......!
  7. データベースにおける変更とは? : テーブルの変更 25 ブルーグリーンアップデートの手順(fullnameカラムの分割) 3. カラムの分割が終わったら Green 用 View

    を作成する Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname Users(View) text text text id firstname lastname
  8. データベースにおける変更とは? : テーブルの変更 26 ブルーグリーンアップデートの手順(fullnameカラムの分割) 3. Green 用 View を利用するアプリケーションを追加する

    Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname Users(View) text text text id firstname lastname
  9. データベースにおける変更とは? : テーブルの変更 27 ブルーグリーンアップデートの手順(fullnameカラムの分割) 4 - a. 問題が発生しなければ Blue

    用 View を利用するアプリケーションをロールアウトする Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname Users(View) text text text id firstname lastname
  10. データベースにおける変更とは? : テーブルの変更 28 ブルーグリーンアップデートの手順(fullnameカラムの分割) 5 - a. Blue 用

    View を削除する Cloud Run SQLを実行 Users text text id fullname text firstname text lastname Users(View) text text text id firstname lastname
  11. データベースにおける変更とは? : テーブルの変更 29 ブルーグリーンアップデートの手順(fullnameカラムの分割) 6 - a. 不要なカラムを DROP

    する Cloud Run SQLを実行 Users text id text firstname text lastname Users(View) text text text id firstname lastname
  12. データベースにおける変更とは? : テーブルの変更 30 ブルーグリーンアップデートの手順(fullnameカラムの分割) 6 - a. 不要なカラムを DROP

    する Cloud Run SQLを実行 Users text id text firstname text lastname Users(View) text text text id firstname lastname リリースが完了!
  13. データベースにおける変更とは? : テーブルの変更 31 ブルーグリーンアップデートの手順(fullnameカラムの分割) 4 - b. 問題が発生した場合 Green

    用 View を利用するアプリケーション切り戻す Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname Users(View) text text text id firstname lastname
  14. データベースにおける変更とは? : テーブルの変更 32 ブルーグリーンアップデートの手順(fullnameカラムの分割) 5 - b. Green 用

    View を削除する Cloud Run Users(View) text text id fullname SQLを実行 Users text text id fullname text firstname text lastname
  15. 38 参考資料 38 • データを移行してデータベースのメジャー バージョンをアップグレードする | Cloud SQL for

    MySQL ◦ https://cloud.google.com/sql/docs/mysql/upgrade-major-db-version-migrate?hl=ja • データを移行してデータベースのメジャー バージョンをアップグレードする | Cloud SQL for PostgreSQL ◦ https://cloud.google.com/sql/docs/postgres/upgrade-major-db-version-migrate?hl=ja • Aurora MySQL 一段飛ばしのバージョンアップとその他もろもろの話 ◦ https://www.docswell.com/s/hmatsu47/Z7WR15-2022-11-21-232543 • Amazon RDS ブルー/グリーンデプロイの概要 ◦ https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/blue-green-deployments-overview.html
  16. 39 参考資料 39 • Postgres schema changes are still a

    PITA | xata ◦ https://xata.io/blog/postgres-schema-changes-pita • Handling table and column renames | PlanetScale ◦ https://planetscale.com/docs/learn/handling-table-and-column-renames#how-to-rename-a-column-on-planetscale • 運用中のPostgreSQLのスキーマを無停止で安全に変更する | 株式会社ヌーラボ(Nulab inc.) ◦ https://nulab.com/ja/blog/typetalk/change-postgresql-schema-with-safety-and-non-stop/ • Safe and unsafe operations for high volume PostgreSQL | Leopard Blog ◦ https://leopard.in.ua/2016/09/20/safe-and-unsafe-operations-postgresql • 令和最新版: PostgreSQLの安全なSET NOT NULL | Wantedly Engineer Blog ◦ https://www.wantedly.com/companies/wantedly/post_articles/433252
  17. 40 参考資料 40 • Introducing pgroll: zero-downtime, reversible, schema migrations

    for Postgres | xata ◦ https://xata.io/blog/pgroll-schema-migrations-postgres • pgrollで実現するスキーマブルーグリーンデプロイメント ◦ https://speakerdeck.com/nnaka2992/pgrolldeshi-xian-surusukimaburugurindepuroimento • sqldefとpgrollを利用したPostgreSQLでのスキーマブルーグリーンデプロイメント ◦ https://zenn.dev/nnaka2992/articles/blue_grean_on_postgres_with_sqldeff_and_pgroll • xataio/pgroll ◦ https://github.com/xataio/pgroll • fabianlindfors/reshape ◦ https://github.com/fabianlindfors/reshape