

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon Keyspaces 中更新多区域表的预置容量和自动扩缩设置
<a name="tables-mrr-autoscaling"></a>

本节包括如何使用控制台、CQL 和来管理已配置的多区域表的 Amazon Keyspaces 自动扩展设置的示例。 AWS CLI 有关常规自动扩缩配置选项及其工作原理的更多信息，请参阅[使用 Amazon Keyspaces 自动扩缩自动管理吞吐能力](autoscaling.md)。

请注意，如果您对多区域表使用预置容量模式，则必须始终使用 Amazon Keyspaces API 调用来配置自动扩缩。这是因为底层的 Application Auto Scaling API 操作不支持区域感知。

有关如何估算预置多区域表的写入容量吞吐量的更多信息，请参阅[在 Amazon Keyspaces 中为多区域表估算和预置容量](tables-multi-region-capacity.md)。

有关该 Amazon Keyspaces API 的更多信息，请参阅 [https://docs.aws.amazon.com/keyspaces/latest/APIReference/Welcome.html](https://docs.aws.amazon.com/keyspaces/latest/APIReference/Welcome.html)。

更新多区域表的预置模式或自动扩缩设置时，可以更新表每个副本的读取容量设置和读取自动扩缩配置。

但是，写入容量在所有副本之间保持同步，以确保有足够的容量在所有区域中复制写入。

------
#### [ Cassandra Query Language (CQL) ]

**使用 CQL 更新多区域表的预置容量和自动扩缩设置**
+  您可以使用 `ALTER TABLE` 更新现有表的容量模式和自动扩缩设置。如果您要更新当前处于按需容量模式的表，则 `capacity_mode` 为必需。如果您的表已经处于预置容量模式，则可以忽略此字段。

  有关自动扩缩设置、目标跟踪策略、目标值和可选设置的详细信息，请参阅[创建启用了自动扩缩的新表](autoscaling.createTable.md)。

  在同一语句中，您还可以通过更新表的 `replica_updates` 属性来更新特定区域中表副本的读取容量和自动扩缩设置。下面是一个示例语句。

  ```
  ALTER TABLE mykeyspace.mytable
  WITH CUSTOM_PROPERTIES = {  
      'capacity_mode': {  
          'throughput_mode': 'PROVISIONED',  
          'read_capacity_units': 1,  
          'write_capacity_units': 1  
      }
  } AND AUTOSCALING_SETTINGS = {
      'provisioned_write_capacity_autoscaling_update': {
          'maximum_units': 10,  
          'minimum_units': 5,  
          'scaling_policy': {
              'target_tracking_scaling_policy_configuration': {
                  'target_value': 50
              }  
          }  
      },
      'provisioned_read_capacity_autoscaling_update': {  
          'maximum_units': 10,  
          'minimum_units': 5,  
          'scaling_policy': {  
              'target_tracking_scaling_policy_configuration': {  
                  'target_value': 50,
                  'scale_in_cooldown': 60,  
                  'scale_out_cooldown': 60
              }  
          }  
      },
      'replica_updates': {
          'us-east-1': {
              'provisioned_read_capacity_autoscaling_update': {
                  'maximum_units': 20,
                  'minimum_units': 5,
                  'scaling_policy': {
                      'target_tracking_scaling_policy_configuration': {
                          'target_value': 70
                      } 
                  }
              }
          }
      }
  };
  ```

------
#### [ CLI ]

**使用更新多区域表的预配置容量和 auto scaling 设置 AWS CLI**
+ 要更新现有表的预配置模式和 auto Scaling 配置，您可以使用 AWS CLI `update-table`命令。

  请注意，您必须使用 Amazon Keyspaces CLI 命令来创建或修改多区域自动扩缩设置。这是因为 Amazon Keyspaces 用来代表您执行表容量自动扩缩的 Application Auto Scaling 服务不支持多个 AWS 区域。

   要更新特定区域中表副本的读取容量，您可以为表的 `replicaSpecifications` 配置以下可选参数之一：
  + 预置读取容量单位（可选）
  + 读取容量的自动扩缩设置（可选）

  当您使用复杂的自动扩缩设置和不同的表副本配置更新多区域表时，建议从 JSON 文件加载表的自动扩缩设置和副本配置。

  要使用以下代码示例，您可以从 [auto-scaling.zip](samples/auto-scaling.zip) 下载示例 JSON 文件，然后提取 `auto-scaling.json` 和 `replication.json`。记下文件路径。

  在本示例中，JSON 文件位于当前目录下。有关不同的文件路径选项，请参阅[如何从文件加载参数](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-file.html#cli-usage-parameters-file-how)。

  ```
  aws keyspaces update-table --keyspace-name mykeyspace --table-name mytable \
  --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=1,writeCapacityUnits=1 \
  --auto-scaling-specification file://auto-scaling.json \
  --replica-specifications file://replication.json
  ```

------