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. 执行以下 curl 命令,并通过 telnet 使用端口 7001 从第一个数据中心的第一个 Cassandra pod (dc-1) 连接到第二个数据中心的第一个 (dc-2):
    kubectl -n apigee exec -it apigee-cassandra-default-0 bash -- 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 上,请检查是否设置了阻止一个数据中心到另一个数据中心的流量的防火墙规则,并参阅 VPC 防火墙规则概览来分析网络连接问题。
  2. 如果此 Apigee Hybrid 部署是在 GKE On-Prem 上,请与相关网络团队合作分析网络连接问题。

如果问题仍然存在,请转到必须收集诊断信息

必须收集的诊断信息

如果按照上述说明操作后问题仍然存在,请收集以下诊断信息,然后联系 Apigee 支持团队

  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