搭配 Dataproc Metastore 服務使用 Managed Migration

本頁說明如何啟動及管理 Dataproc Metastore 受管理遷移作業。

您可以使用 Dataproc Metastore API 設定遷移作業。

事前準備

開始遷移

執行啟動遷移時,Dataproc Metastore 會連線至 Cloud SQL,並將 Cloud SQL 做為後端資料庫。在此程序中,Dataproc Metastore 會執行管道,將資料從 Cloud SQL 複製到自己的資料庫 (Spanner)。

Dataproc Metastore 會繼續使用 Cloud SQL 做為後端,並複製資料,直到呼叫完整遷移程序為止。

開始遷移前,請務必設定受管理遷移作業的必要條件

開始遷移注意事項

  • Dataproc Metastore 服務一次只能執行一次遷移作業。

  • 在完成遷移程序前,遷移作業會持續進行。 遷移作業沒有期限,例如,遷移作業可能需要 1 天、30 天或 1 年。

  • 遷移期間不會限制排定的備份作業。不過,備份內容可能不完整。為避免發生問題,請在遷移作業進行期間停用所有排定的備份作業。

啟動遷移作業會觸發下列狀態變更:

  • Dataproc Metastore 會移至 MIGRATING 狀態。
  • 遷移作業執行狀態會移至 RUNNING
  • 遷移作業執行階段會移至 REPLICATION

控制台

開始使用

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面:

    前往 Dataproc Metastore

  2. 在「Dataproc Metastore」頁面中,按一下要遷移的服務名稱。

    「服務詳細資料」頁面隨即開啟。

  3. 按一下頁面頂端的「遷移資料」

    「建立遷移作業」頁面會開啟「連線」分頁,並顯示「Dataproc Metastore 的 Cloud SQL 資料庫設定」設定。

DPMS 的 Cloud SQL 資料庫設定

  1. 在「Instance connection name」(執行個體連線名稱) 中,輸入 Cloud SQL 資料庫的執行個體連線名稱,格式如下:project_id:region:instance_name

  2. 在「IP address」(IP 位址) 欄位中,輸入連線至 Cloud SQL 執行個體所需的 IP 位址。

  3. 在「Port」(通訊埠) 欄位中輸入 3306

  4. 在「Hive 資料庫名稱」中,輸入做為自行管理 Hive Metastore 後端的資料庫名稱。

  5. 在「Username」(使用者名稱) 欄位中,輸入您用來將 Cloud SQL 連線至 Hive Metastore 的使用者名稱。

  6. 在「Password」(密碼) 欄位中,輸入您用來將 Cloud SQL 連線至 Hive Metastore 的密碼。

SOCKS5 Proxy 服務

  1. 在「Proxy Subnet」(Proxy 子網路) 欄位中,輸入「Regular type」(一般類型) 的子網路。 子網路應位於 Cloud SQL 虛擬私有雲網路中。 這個子網路用於部署中繼 SOCKS5 Proxy 服務

  2. 在「Nat Subnet」(網路位址轉譯子網路) 欄位中,輸入Private Service Connect 類型的子網路。 這個子網路應位於 Cloud SQL 虛擬私有雲網路中,並用於透過 Private Service Connect 發布 SOCKS5 Proxy 服務

  3. 按一下「繼續」

    「變更資料擷取 (CDC)」分頁隨即開啟,並顯示「Datastream 的 Cloud SQL 資料庫設定」設定。

資料串流的 Cloud SQL 資料庫設定

  1. 在「使用者名稱」欄位中,輸入您用來登入 Datastream 所用 Cloud SQL CDC 的使用者名稱。

  2. 在「Password」(密碼) 欄位中,輸入您登入 Datastream 所用 Cloud SQL CDC 的密碼。

  3. 在「虛擬私有雲網路」欄位中,輸入與 Datastream 用於建立 CDC 私人連線的 Cloud SQL 執行個體相同的虛擬私有雲網路。

  4. 在「子網路 IP 範圍」欄位中,輸入至少 /29 的子網路 IP 範圍。Datastream 會使用這個 IP 建立虛擬私有雲網路的對等互連。

  5. 在「反向 Proxy 子網路」欄位中,輸入您在與 Cloud SQL 相同的虛擬私有雲網路中建立的子網路。Datastream 會使用這個子網路。子網路用於代管 Datastream CDC 的反向 Proxy 連線。子網路必須與 Dataproc Metastore 服務位於同一區域。

GCS 設定

  1. 在「Bucket ID」中,選取 Cloud Storage 路徑,以便在遷移期間儲存 CDC 資料。

  2. 在「Root path」(根路徑) 欄位中,輸入 Cloud Storage bucket 內的根路徑。串流事件資料會寫入這個路徑。

  3. 點選「建立」

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type:application/json" \
  -X POST -d \
  '{
    "migration_execution": {
      "cloud_sql_migration_config": {
        "cloud_sql_connection_config": {
          "instance_connection_name": INSTANCE_CONNECTION_NAME,
          "hive_database_name": "HIVE_DATABASE_NAME",
          "ip_address": "IP_ADDRESS",
          "port": 3306,
          "username": "CONNECTION_USERNAME",
          "password": "CONNECTION_PASSWORD",
          "proxy_subnet": "PROXY_SUBNET",
          "nat_subnet": "NAT_SUBNET"
        },
        "cdc_config": {
          "username": "CDC_USENAME",
          "password": "CDC_PASSWORD",
          "vpc_network": "VPC_NETWORK",
          "subnet_ip_range": "SUBNET_IP_RANGE",
          "reverse_proxy_subnet": "REVERSE_PROXY_SUBNET_ID",
          "bucket": "BUCKET_NAME",
          "root_path": "ROOT_PATH",
        }
      }
    }
}' \
  https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE:startMigration

更改下列內容:

  • SERVICE:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。

Cloud SQL 遷移設定

  • INSTANCE_CONNECTION_NAME:Cloud SQL 資料庫的執行個體連線名稱,格式如下:PROJECT_ID/LOCATION/CLOUDSQL_INSTANCE_ID
  • :連結至 Cloud SQL 的自我管理 Hive 資料庫名稱。HIVE_DATABASE_NAME
  • IP_ADDRESS:連線至 Cloud SQL 執行個體所需的 IP 位址。
  • CONNECTION_USERNAME:用於將 Cloud SQL 連線至 Hive Metastore 的使用者名稱。
  • CONNECTION_PASSWORD 用於將 Cloud SQL 連線至 Hive Metastore 的密碼
  • PROXY_SUBNET:Cloud SQL 虛擬私有雲網路中使用的子網路。這個子網路會代管中繼 Proxy,以提供跨遞移網路的連線。
  • NAT_SUBNETPrivate Service Connect 子網路,可提供從 Dataproc Metastore 服務到中繼 Proxy 的連線。子網路大小的前置字元長度至少須為 /29,且位於 IPv4 範圍內。

設定 CDC

  • CDC_USERNAME:Datastream 服務用來登入 Cloud SQL 的使用者名稱。
  • CDC_PASSWORD:Datastream 服務用來登入 Cloud SQL 的密碼。
  • VPC_NETWORK:與 Cloud SQL 執行個體位於相同 VPC 網路的網路,Datastream 會使用該網路建立與 CDC 的私人連線。
  • SUBNET_IP_RANGE:Datastream 用於建立與虛擬私有雲網路對等互連的子網路 IP 範圍,至少為 /29。
  • REVERSE_PROXY_SUBNET_ID:與 Datastream 使用的 Cloud SQL 執行個體位於相同 VPC 網路的子網路。子網路用於代管 Datastream CDC 的反向 Proxy 連線。子網路必須與 Dataproc Metastore 服務位於同一區域。
  • BUCKET_NAME:遷移期間用來儲存 CDC 資料的 Cloud Storage 路徑。
  • ROOT_PATH:Cloud Storage bucket 內的根路徑。串流事件資料會寫入這個路徑。

完成遷移

完成遷移作業後,Dataproc Metastore 會連線至 Spanner,並開始使用 Spanner 做為後端資料庫。

完成遷移作業後,系統會觸發下列狀態變更:

  • Dataproc Metastore 會返回 ACTIVE 狀態。
  • 遷移作業執行狀態會移至 SUCCEEDED

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面。

  2. 按一下頁面頂端的「遷移資料」

    「遷移資料」頁面隨即開啟,並顯示已完成的代管遷移作業。

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type:application/json" \
  -X POST -d '' \
   https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE:completeMigration

更改下列內容:

  • SERVICE:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。

取消遷移

取消遷移作業後,Dataproc Metastore 會還原所有變更,並開始使用 Spanner 資料庫類型做為後端資料庫。所有在遷移期間轉移的資料都會遭到刪除。

取消遷移作業會觸發下列狀態變更:

  • Dataproc Metastore 會返回 ACTIVE 狀態。
  • 遷移作業執行狀態會移至 CANCELLED

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面。

  2. 按一下頁面頂端的「遷移資料」

    「遷移資料」頁面隨即開啟,並顯示已取消的受管理遷移作業。

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type:application/json" \
  -X POST -d '' \
    https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE:cancelMigration

更改下列內容:

  • SERVICE_NAME:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。

取得遷移作業詳細資料

取得單一受管理遷移作業的詳細資料。

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面。

  2. 按一下頁面頂端的「遷移資料」

    「遷移資料」頁面隨即開啟,並顯示您管理的遷移作業。

    如要查看更多遷移詳細資料,請按一下受管理遷移作業的名稱。

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -X GET \
   https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE/migrationExecutions/MIGRATION_ID

更改下列內容:

  • SERVICE:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。
  • MIGRATION_ID:Dataproc Metastore 遷移作業的名稱或 ID。

列出遷移作業

列出代管遷移作業。

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面。

  2. 按一下頁面頂端的「遷移資料」

    「遷移資料」頁面隨即開啟,並顯示您管理的遷移作業。

  3. 確認指令是否列出遷移作業。

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -X GET \
   https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE/migrationExecutions/MIGRATION_ID

更改下列內容:

  • SERVICE:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。

刪除遷移作業

刪除代管遷移作業。

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面。

  2. 按一下頁面頂端的「遷移資料」

    「遷移資料」頁面隨即開啟,並顯示您管理的遷移作業。

  3. 選取要刪除的遷移作業,然後按一下「刪除」

REST

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
   -X DELETE \
    https://metastore.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/SERVICE/migrationExecutions/MIGRATION_ID

更改下列內容:

  • SERVICE:Dataproc Metastore 服務的名稱或 ID。
  • PROJECT_ID:Dataproc Metastore 服務所在的專案 ID。 Google Cloud
  • LOCATION:Dataproc Metastore 服務所在的 Google Cloud 區域。
  • MIGRATION_ID:Dataproc Metastore 遷移作業的名稱或 ID。

後續步驟