Cassandra 資料複寫失敗

您目前正在查看 ApigeeApigee Hybrid 說明文件。
查看 Apigee Edge 說明文件。

問題

在多區域擴充期間複製資料時,CassandraDataReplication狀態可能會顯示錯誤,且資料複製作業可能會失敗。

錯誤訊息

使用 kubectl 查看重建狀態時:

  kubectl -n apigee get apigeeds \
  -o jsonpath="{.items[].status.cassandraDataReplication}{'\n'}"

您發現一或多個 Cassandra Pod 顯示錯誤狀態,且訊息指出重建作業失敗。例如:

{
  "rebuildDetails": {
    "apigee-cassandra-default-0": {
      "message": "failed to rebuild from us-west1: java.lang.IllegalStateException : Unable to find sufficient sources for streaming range (-8567285182390470134,-8567154549835592965] in keyspace system_distributed",
      "state": "error",
      "updated": 1641581899
    },
    …
  }
}

可能原因

原因 說明 適用於以下情況的疑難排解說明
來源區域有誤 Cassandra 資料複製 YAML 檔案中的 source.region 值不正確。 Apigee Hybrid
網路連線問題 不同資料中心內的 Cassandra Pod 可能發生網路連線問題。 Apigee Hybrid

常見的診斷步驟

  1. 擷取資料複製狀態:
    kubectl -n apigee get apigeeds \
    -o jsonpath="{.items[].status.cassandraDataReplication}{'\n'}"
  2. 如果看到類似「錯誤訊息」中指定的錯誤訊息,表示您遇到這個問題。

原因:來源區域不正確

如果您在資料複製 YAML 檔案中指定的來源區域 (datacenter) 與實際來源 datacenter 不同,資料複製作業就會失敗。請按照「診斷」一節的步驟分析這個情況,並按照「解決方法」一節的步驟修正問題。

診斷

  1. 列出來源區域中的所有 Cassandra pod:
    kubectl -n apigee get pods -l app=apigee-cassandra
    
  2. 從步驟 1 傳回的任一 Cassandra Pod 中取得實際的 datacenter 值:
    kubectl -n apigee exec -it apigee-cassandra-default-0 -- \
    nodetool -u JMX_user -pw JMX_password status
    
  3. 多區域部署中建立的 Cassandra 資料複製自訂資源 (YAML) 檔案中,取得 source.region 的值。如果您使用多區域部署說明文件中的範例檔案名稱,檔案應命名為 datareplication.yaml
    cat datareplication.yaml
    

    結果範例:

    apiVersion: apigee.cloud.google.com/v1alpha1
    kind: CassandraDataReplication
    metadata:
      name: region-expansion
      namespace: apigee
    spec:
      organizationRef: apigee-hybrid-example-org
      force: false
      source:
        region: "us-west1"
  4. 檢查 nodetool status 輸出結果,並確認 datacenter 值是否與 source.region 值相符:

    kubectl -n apigee exec -it apigee-cassandra-default-0 -- \
    nodetool -u jmxuser -pw iloveapis123 status
    

    結果範例:

    Datacenter: dc-1
    ================
    Status=Up/Down
    |/ State=Normal/Leaving/Joining/Moving
    --  Address      Load       Tokens       Owns (effective)  Host ID                               Rack
    UN  10.104.13.2  491.84 KiB  256          100.0%            7254711c-fe0a-4b34-b50f-861109f97936  ra-1
    UN  10.104.11.3  527.36 KiB  256          100.0%            5ec389f0-fd67-4de6-9f21-172d5899ff78  ra-1
    UN  10.104.12.7  838.46 KiB  256          100.0%            7a88be82-1f81-4117-86e3-2cda434c0878  ra-1
  5. 請注意,datareplication.yaml 檔案中的 source.region (us-west1) 與 nodetool 狀態輸出中的實際 datacenter 值 (dc-1) 不符。請按照「解決方案」一節的步驟修正設定。

解決方法

如要修正資料複製作業,請刪除資料複製工作,然後使用正確的 datacenter 名稱建立工作。請按照下列步驟操作:

  1. 刪除目前的資料複製程序。如果使用 多區域部署說明文件中的範例檔案名稱,檔案應命名為 datareplication.yaml
    kubectl delete -f datareplication.yaml
    
  2. 將 YAML 檔案中的區域名稱更新為正確的 datacenter 值,例如: dc-1
    apiVersion: apigee.cloud.google.com/v1alpha1
    kind: CassandraDataReplication
    metadata:
      name: region-expansion
      namespace: apigee
    spec:
      organizationRef: apigee-hybrid-example-org
      force: false
      source:
        region: "dc-1"
  3. 套用更新的資料複製作業:
    kubectl apply -f datareplication.yaml
    
  4. 使用下列指令檢查重建狀態,並確認您不再看到先前回報的錯誤狀態:
      kubectl -n apigee get apigeeds \
      -o jsonpath="{.items[].status.cassandraDataReplication}{'\n'}"
    
  5. 如果問題仍未解決,請參閱「原因:網路連線問題」。

原因:網路連線問題

資料複製錯誤也可能是 Cassandra 節點之間的連線問題所致。

診斷

請按照下列步驟分析這個情境:

  1. 列出所有 Cassandra Pod:
    # list cassandra pods
    kubectl -n=apigee get pods -l app=apigee-cassandra
  2. 執行下列指令,從第一個資料中心 (dc-1) 的第一個 Cassandra Pod,使用通訊埠 7001 Telnet 至第二個資料中心 (dc-2) 的第一個 Cassandra Pod:
    k debug -it apigee-cassandra-default-0 -n apigee --image=nginx -- sh curl -v telnet://DC_2_APIGEE_CASSANDRA_DEFAULT_0_POD_IP:7001
  3. 如果 Telnet 成功,系統會顯示類似以下的輸出內容:
    * Rebuilt URL to: telnet://10.0.4.10:7001/
    *   Trying 10.0.4.10...
    * TCP_NODELAY set
    * Connected to 10.0.4.10 (10.0.4.10) port 7001 (#0)
  4. 否則,系統會顯示類似下列內容的錯誤:
    * Rebuilt URL to: telnet://10.0.4.10:7001/
    *   Trying 10.0.4.10...
    * TCP_NODELAY set
    * connect to 10.0.4.10 port 7001 failed: Connection refused
    * Failed to connect to 10.0.4.10 port 7001: Connection refused
    * Closing connection 0
    curl: (7) Failed to connect to 10.0.4.10 port 7001: Connection refused

    如果一個資料中心內的 Cassandra Pod 無法連線至另一個資料中心內的 Cassandra Pod,表示防火牆可能設有限制,或是發生某種網路連線問題。

解決方法

  1. 如果這個 Apigee Hybrid 部署作業位於 GKE,請檢查是否已設定任何防火牆規則,封鎖從一個資料中心到另一個資料中心的流量,並參閱 虛擬私有雲防火牆規則總覽,分析網路連線問題。
  2. 如果這個 Apigee Hybrid 部署作業位於 GKE On-Prem,請與相關網路團隊合作,分析網路連線問題。

如果問題仍未解決,請參閱「必須收集診斷資訊」。

必須收集診斷資訊

如果按照上述指示操作後問題仍未解決,請收集下列診斷資訊,然後與 Google Cloud Customer Care 團隊聯絡:

  1. Google Cloud 專案 ID。
  2. Apigee Hybrid 機構。
  3. 來源和新區域的 overrides.yaml 檔案,並遮蓋任何私密資訊。
  4. CassandraDataReplication YAML 檔案。
  5. Cassandra nodetool status 輸出:
    kubectl -n apigee exec -it apigee-cassandra-default-0 -- \
    nodetool -u JMX_user -pw JMX_password status
    
  6. Cassandra nodetool describecluster 輸出:
    kubectl -n apigee exec -it apigee-cassandra-default-0 -- \
    nodetool -u JMX_user -pw JMX_password describecluster