创建具有更高温吞吐量的新 Amazon Keyspaces 表 - Amazon Keyspaces(Apache Cassandra 兼容)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

创建具有更高温吞吐量的新 Amazon Keyspaces 表

在创建 Amazon Keyspaces 表时,您可以使用控制台、CQL 或调整热吞吐量值。 Amazon CLI

Console
如何使用热吞吐量设置创建新表
  1. 登录并在家中打开 Amazon Keyspaces 控制台。 Amazon Web Services 管理控制台 https://console.aws.amazon.com/keyspaces/

  2. 在导航窗格中,选择,然后选择创建表

  3. 创建表页面的表详细信息部分中,选择一个键空间并为新表提供一个名称。

  4. 部分,为您的表创建架构。

  5. 主键部分中,定义表的主键并选择可选的集群列。

  6. 表设置部分,选择自定义设置

  7. 继续读取/写入容量设置

  8. 对于容量模式,您可以选择按需预配置。

  9. 表格的预热部分中,您可以根据需要增加每秒读取单位数和每秒写入单位数的值,以准备表处理计划的峰值事件。

    默认情况下,Amazon Keyspaces 根据您的按需使用量或预配置容量调整的温吞吐量值适用于所有表,无需支付额外费用。请注意,如果您手动增加默认的热吞吐量值以预热流量高峰事件,则需要支付额外费用。

  10. 根据需要配置其他可选表格功能。然后选择 “创建表”。

Cassandra Query Language (CQL)
  • 使用以下方法之一创建具有温吞吐量的表:

    • 对于预配置模式,使用以下 CQL 语法创建表并指定读取和写入的预期峰值容量:

      CREATE TABLE catalog.book_awards ( year int, award text, rank int, category text, book_title text, author text, publisher text, PRIMARY KEY ((year, award), category, rank)) WITH CUSTOM_PROPERTIES = { 'capacity_mode': { 'throughput_mode': 'PROVISIONED', 'read_capacity_units': 20000, 'write_capacity_units': 10000 }, 'warm_throughput': { 'read_units_per_second': 40000, 'write_units_per_second': 20000 } };
    • 对于按需模式,使用以下 CQL 语法创建表并指定读取和写入的预期峰值容量:

      CREATE TABLE catalog.book_awards ( year int, award text, rank int, category text, book_title text, author text, publisher text, PRIMARY KEY ((year, award), category, rank)) WITH CUSTOM_PROPERTIES = { 'capacity_mode': { 'throughput_mode': 'PAY_PER_REQUEST' }, 'warm_throughput': { 'read_units_per_second': 40000, 'write_units_per_second': 20000 } };

    要确认表的容量设置,请参阅查看 Amazon Keyspaces 表的热吞吐量

CLI
  1. 使用以下方法之一创建具有温吞吐量的表 Amazon CLI

    • 在预置模式下创建新表,并指定新表的预期读取和写入容量峰值。下面是一个示例语句。

      aws keyspaces create-table \ --keyspace-name 'catalog' \ --table-name 'book_awards' \ --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \ --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=20000,writeCapacityUnits=10000 \ --warm-throughput-specification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
    • 在按需模式下创建新表,并为新表指定读取和写入的预期峰值容量值。下面是一个示例语句。

      aws keyspaces create-table \ --keyspace-name 'catalog' \ --table-name 'book_awards' \ --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \ --warmThroughputSpecification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
  2. 命令的输出返回表的 ARN,如下例所示。

    { "resourceArn": "arn:aws::cassandra:us-east-1:111122223333:/keyspace/catalog/table/book_awards>" }

    要确认表的容量设置,请参阅查看 Amazon Keyspaces 表的热吞吐量

Java
使用适用于 Java 的 SDK 创建新表。
  • 在预置模式下创建新表,并指定新表的预期读取和写入容量峰值。以下代码示例就是一个例子。

    import software.amazon.awssdk.services.keyspaces.KeyspacesClient; import software.amazon.awssdk.services.keyspaces.model.*; public class PreWarmingExample { public static void main(String[] args) { KeyspacesClient keyspacesClient = KeyspacesClient.builder().build(); // Define schema List<ColumnDefinition> columns = Arrays.asList( ColumnDefinition.builder().name("year").type("int").build(), ColumnDefinition.builder().name("award").type("text").build(), ColumnDefinition.builder().name("rank").type("int").build(), ColumnDefinition.builder().name("category").type("text").build(), ColumnDefinition.builder().name("book_title").type("text").build(), ColumnDefinition.builder().name("author").type("text").build(), ColumnDefinition.builder().name("publisher").type("text").build() ); List<PartitionKey> partitionKeys = Arrays.asList( PartitionKey.builder().name("year").build(), PartitionKey.builder().name("award").build() ); List<ClusteringKey> clusteringKeys = Arrays.asList( ClusteringKey.builder().name("category").orderBy("ASC").build(), ClusteringKey.builder().name("rank").orderBy("ASC").build() ); SchemaDefinition schema = SchemaDefinition.builder() .allColumns(columns) .partitionKeys(partitionKeys) .clusteringKeys(clusteringKeys) .build(); // Define capacity specification CapacitySpecification capacitySpec = CapacitySpecification.builder() .throughputMode(ThroughputMode.PROVISIONED) .readCapacityUnits(20000) .writeCapacityUnits(10000) .build(); // Define warm throughput specification WarmThroughputSpecification warmThroughput = WarmThroughputSpecification.builder() .readUnitsPerSecond(40000L) .writeUnitsPerSecond(20000L) .build(); // Create table with PreWarming CreateTableRequest request = CreateTableRequest.builder() .keyspaceName("catalog") .tableName("book_awards") .schemaDefinition(schema) .capacitySpecification(capacitySpec) .warmThroughputSpecification(warmThroughput) .build(); CreateTableResponse response = keyspacesClient.createTable(request); System.out.println("Table created with ARN: " + response.resourceArn()); } }