更改 Cassandra 压缩策略

Apigee 使用 Cassandra 数据库存储其大部分数据,包括代理、缓存和令牌的数据。压缩是缩小数据库中存储的数据大小的关键过程,对于维持高效的数据库运行至关重要。Cassandra 支持各种压缩策略。Apigee 建议所有 Edge for Private Cloud 客户都使用 LeveledCompactionStrategy(而不是默认的 SizeTieredCompactionStrategy)来运行其 Cassandra 集群中的所有表。与 SizeTieredCompactionStrategy 相比,LeveledCompactionStrategy 具有更好的性能、更高的磁盘利用率、更高效的压缩,并且所需的可用空间更少。

所有 Edge for Private Cloud 4.52.02 或更高版本的新安装都会自动 使用 LeveledCompactionStrategy 配置 Cassandra。但是,如果您是从早期版本升级到 Edge for Private Cloud 4.54.00,则您的安装可能仍在使用 Cassandra 配置 SizeTieredCompactionStrategy。

虽然不建议将压缩策略更改为 LeveledCompactionStrategy 以外的任何策略,但本文档概述了如何在必要时进行更改,并提供了检查当前压缩策略的说明。如果将压缩策略更改为非推荐选项,可能会导致日后的 Cassandra 软件升级覆盖您的更改。如果您使用的是非标准方法,建议您在每次升级后验证压缩策略。

准备工作

前提条件

在 Edge for Private Cloud 4.54.00 中,Cassandra 5.x 需要 JDK 17 (Java 17)。 在 Cassandra 节点上运行 nodetool 或 cqlsh 命令之前,请确保 Java 17 已配置为默认 Java 版本 (例如,通过运行 sudo alternatives --set java JAVA_17_PATH/bin/java 或 将 JAVA_HOME 设置为您的 JDK 17 安装)。

检查现有压缩策略

您可以按照 附录 1中的说明检查表中的现有压缩策略。 如果压缩策略已经是 LeveledCompactionStrategy, 可能是因为您一开始安装的是 Edge for Private Cloud 4.51 或更高版本,或者之前已按照 Apigee 的建议更改为 LeveledCompactionStrategy。如果您已在使用 LeveledCompactionStrategy,Apigee 建议您继续使用此策略,避免进行更改。不过,由于 Edge for Private Cloud 由您运行,因此以下说明介绍了如何 根据需要更改压缩策略。

备份

由于更改压缩策略会在 Cassandra 节点中触发完整的压缩周期,因此可能会因压缩负载和同步应用流量而引入一些延迟。回滚此更改不需要从备份恢复;您可以按照方法 1:还原更改中的说明直接还原压缩策略。不过,为谨慎起见,请参阅如何备份,以便在更改压缩策略之前备份数据。

压缩吞吐量

将压缩策略更改为 LeveledCompactionStrategy 后,压缩可能会长时间运行。运行时可能会因数据压缩的大小而异。在压缩 周期内,Cassandra 可能会占用更多系统资源。为确保压缩不会占用大量 系统资源(这可能会中断 API 运行时请求),我们建议您为 压缩吞吐量设置限制。

在每个节点上运行以下 nodetool 命令,将所有 Cassandra 节点上的压缩吞吐量设置为上限 128MB:

nodetool setcompactionthroughput 128

调整虚拟机大小以进行压缩

在执行此更改之前,请确保 Cassandra 节点具有足够的 CPU 和 内存资源,并且 CPU 负载不超过 25%。

更改压缩策略后,预计会运行完整的压缩周期,因此建议在流量较低的时段更改压缩策略。

错峰运行

您可能无法在一天内完成所有节点的更改,尤其是在运行大型 Cassandra 集群时,因为需要在每个节点上逐个重建索引。您可以一次更改一个架构或一个表的压缩策略。为此,请更改表以更改其压缩策略,然后在所有节点上重建该表的所有索引(如果有)。然后,对每个表或键空间重复上述过程。针对一个表或一个键空间的此类运行可以分解为在不同的日期运行。

例如,如需将 kms 架构中 oauth_20_access_tokens 表的压缩策略更改为 LeveledCompactionStrategy,您可以执行以下操作:

  1. 运行以下 CQL,更改表以更改压缩策略:

    ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  2. 仅重建此表的所有索引:

    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_app_id_idx
    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_client_id_idx
    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_refresh_token_idx   
        

更改压缩策略

概括来讲,更改压缩策略是一个包含两个步骤的过程:

  1. 修改每个表的压缩策略。
  2. 在每个节点上逐个重建所有索引。

如需修改压缩策略,您需要一次对每个表执行一个 ALTER TABLE 命令。ALTER TABLE 命令的示例类似于以下内容:

# To change to LeveledCompactionStrategy
ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  
# To change to SizeTieredCompactionStrategy
ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};

更改表以设置新的压缩策略

在任何一个 Cassandra 节点上运行以下 CQL,一次更改一个键空间的策略。CQL 可以在 CQL 提示符下运行。调用 CQL 提示符的说明:

/opt/apigee/apigee-cassandra/bin/cqlsh `hostname -i`

Connected to Apigee at XXXXXXXX:9042.

[cqlsh 6.2.0 | Cassandra 5.0.8 | CQL spec 3.4.7 | Native protocol v5]
Use HELP for help.
cqlsh>

以下命令介绍了如何将压缩策略更改为 LeveledCompactionStrategy,但您可以使用类似的命令更改为其他压缩策略。

以下步骤 14 到 16 仅适用于您使用创收功能的情况。

  1. 用于更改键空间压缩策略的 CQL: kms
    ALTER TABLE kms.organizations WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.maps WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.apps WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.app_credentials WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.api_products WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.apiproducts_appslist WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.api_resources WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.app_end_user WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.oauth_20_authorization_codes WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.oauth_10_request_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.oauth_10_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.oauth_10_verifiers WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE kms.app_enduser_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  2. 用于更改键空间压缩策略的 CQL: user_settings
    ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  3. 用于更改键空间压缩策略的 CQL: keyvaluemap
    ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  4. 用于更改键空间压缩策略的 CQL: devconnect
    ALTER TABLE devconnect.developers WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE devconnect.companies WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE devconnect.company_developers WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  5. 用于更改键空间压缩策略的 CQL: counter
    ALTER TABLE counter.counters_current_version WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.counters_with_expiry WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.counters WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.key_timestamp_count WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.timestamp_key WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.period_timestamp WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE counter.gateway_quota WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  6. 用于更改键空间压缩策略的 CQL: cache
    ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  7. 用于更改键空间压缩策略的 CQL: auth
    ALTER TABLE auth.totp WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  8. 用于更改键空间压缩策略的 CQL: audit
    ALTER TABLE audit.audits WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE audit.audits_ref WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  9. 用于更改键空间压缩策略的 CQL: apprepo
    ALTER TABLE apprepo.organizations WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apprepo.environments WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apprepo.apiproxies WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apprepo.apiproxy_revisions WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apprepo.api_proxy_revisions_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  10. 用于更改键空间压缩策略的 CQL: apimodel_v2
    ALTER TABLE apimodel_v2.apis WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.apis_revision WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.resource WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.method WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.revision_counters WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.template_counters WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.template WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.credentials WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.credentialsv2 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.schemas WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.security WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE apimodel_v2.template_auth WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  11. 用于更改键空间压缩策略的 CQL: identityzone
    ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  12. 用于更改键空间压缩策略的 CQL: dek
    ALTER TABLE dek.keys WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  13. 用于更改键空间压缩策略的 CQL: analytics
    ALTER TABLE analytics.custom_aggregates_defn WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE analytics.custom_rules_defn WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE analytics.custom_aggregates_defn_updates WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE analytics.custom_rules_defn_updates WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  14. [仅限创收] 用于更改键空间压缩策略的 CQL: mint
    ALTER TABLE mint.limits WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE mint.suspended_developer_products WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE mint.invitations WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  15. [仅限创收] 用于更改键空间压缩策略的 CQL: taurus
    ALTER TABLE taurus.triggers WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE taurus.job_details WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE taurus.org_triggers WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE taurus.triggers_suite WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  16. [仅限创收] 用于更改键空间压缩策略的 CQL: notification
    ALTER TABLE notification.notification_service_item WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE notification.notification_service_black_list_item WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE notification.notification_email_template_item WITH compaction = {'class' : 'LeveledCompactionStrategy'};

重建索引

此步骤需要在更改任何压缩策略后执行。在每个 Cassandra 节点上逐个运行以下 nodetool 命令。

以下步骤 7 到 9 仅适用于您使用创收功能的情况。

  1. 重建键空间的索引:kms

    nodetool rebuild_index kms api_products api_products_organization_name_idx
    nodetool rebuild_index kms app_credentials app_credentials_api_products_idx
    nodetool rebuild_index kms app_credentials app_credentials_organization_app_id_idx
    nodetool rebuild_index kms app_credentials app_credentials_organization_name_idx
    nodetool rebuild_index kms app_end_user app_end_user_app_id_idx
    nodetool rebuild_index kms apps apps_app_family_idx
    nodetool rebuild_index kms apps apps_app_id_idx
    nodetool rebuild_index kms apps apps_app_type_idx
    nodetool rebuild_index kms apps apps_name_idx
    nodetool rebuild_index kms apps apps_organization_name_idx
    nodetool rebuild_index kms apps apps_parent_id_idx
    nodetool rebuild_index kms apps apps_parent_status_idx
    nodetool rebuild_index kms apps apps_status_idx
    nodetool rebuild_index kms maps maps_organization_name_idx
    nodetool rebuild_index kms oauth_10_access_tokens oauth_10_access_tokens_app_id_idx
    nodetool rebuild_index kms oauth_10_access_tokens oauth_10_access_tokens_consumer_key_idx
    nodetool rebuild_index kms oauth_10_access_tokens oauth_10_access_tokens_organization_name_idx
    nodetool rebuild_index kms oauth_10_access_tokens oauth_10_access_tokens_status_idx
    nodetool rebuild_index kms oauth_10_request_tokens oauth_10_request_tokens_consumer_key_idx
    nodetool rebuild_index kms oauth_10_request_tokens oauth_10_request_tokens_organization_name_idx
    nodetool rebuild_index kms oauth_10_verifiers oauth_10_verifiers_organization_name_idx
    nodetool rebuild_index kms oauth_10_verifiers oauth_10_verifiers_request_token_idx
    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_app_id_idx
    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_client_id_idx
    nodetool rebuild_index kms oauth_20_access_tokens oauth_20_access_tokens_refresh_token_idx
    nodetool rebuild_index kms oauth_20_authorization_codes oauth_20_authorization_codes_client_id_idx
    nodetool rebuild_index kms oauth_20_authorization_codes oauth_20_authorization_codes_organization_name_idx
    
  2. 重建键空间的索引:devconnect

    nodetool rebuild_index devconnect companies companies_name_idx
    nodetool rebuild_index devconnect companies companies_organization_name_idx
    nodetool rebuild_index devconnect companies companies_status_idx
    nodetool rebuild_index devconnect company_developers company_developers_company_name_idx
    nodetool rebuild_index devconnect company_developers company_developers_developer_email_idx
    nodetool rebuild_index devconnect company_developers company_developers_organization_name_idx
    nodetool rebuild_index devconnect developers developers_email_idx
    nodetool rebuild_index devconnect developers developers_organization_name_idx
    nodetool rebuild_index devconnect developers developers_status_idx
    
  3. 重建键空间的索引:cache

    nodetool rebuild_index cache cache_entries cache_entries_cache_name_idx
    
  4. 重建键空间的索引:audit

    nodetool rebuild_index audit audits audits_operation_idx
    nodetool rebuild_index audit audits audits_requesturi_idx
    nodetool rebuild_index audit audits audits_responsecode_idx
    nodetool rebuild_index audit audits audits_timestamp_idx
    nodetool rebuild_index audit audits audits_user_idx
    
  5. 重建键空间的索引:apimodel_v2

    nodetool rebuild_index apimodel_v2 apis a_name
    nodetool rebuild_index apimodel_v2 apis a_org_name
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_active_rev
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_def_index_template
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_def_method_template
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_latest_rev
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_name
    nodetool rebuild_index apimodel_v2 apis_revision ar_a_uuid
    nodetool rebuild_index apimodel_v2 apis_revision ar_base_url
    nodetool rebuild_index apimodel_v2 apis_revision ar_is_active
    nodetool rebuild_index apimodel_v2 apis_revision ar_is_latest
    nodetool rebuild_index apimodel_v2 apis_revision ar_name
    nodetool rebuild_index apimodel_v2 apis_revision ar_org_name
    nodetool rebuild_index apimodel_v2 apis_revision ar_rel_ver
    nodetool rebuild_index apimodel_v2 apis_revision ar_rev_num
    nodetool rebuild_index apimodel_v2 method m_a_name
    nodetool rebuild_index apimodel_v2 method m_api_uuid
    nodetool rebuild_index apimodel_v2 method m_ar_uuid
    nodetool rebuild_index apimodel_v2 method m_base_url
    nodetool rebuild_index apimodel_v2 method m_name
    nodetool rebuild_index apimodel_v2 method m_org_name
    nodetool rebuild_index apimodel_v2 method m_r_name
    nodetool rebuild_index apimodel_v2 method m_r_uuid
    nodetool rebuild_index apimodel_v2 method m_res_path
    nodetool rebuild_index apimodel_v2 method m_rev_num
    nodetool rebuild_index apimodel_v2 resource r_a_name
    nodetool rebuild_index apimodel_v2 resource r_api_uuid
    nodetool rebuild_index apimodel_v2 resource r_ar_uuid
    nodetool rebuild_index apimodel_v2 resource r_base_url
    nodetool rebuild_index apimodel_v2 resource r_name
    nodetool rebuild_index apimodel_v2 resource r_org_name
    nodetool rebuild_index apimodel_v2 resource r_res_path
    nodetool rebuild_index apimodel_v2 resource r_rev_num
    nodetool rebuild_index apimodel_v2 schemas s_api_uuid
    nodetool rebuild_index apimodel_v2 schemas s_ar_uuid
    nodetool rebuild_index apimodel_v2 security sa_api_uuid
    nodetool rebuild_index apimodel_v2 security sa_ar_uuid
    nodetool rebuild_index apimodel_v2 template t_a_name
    nodetool rebuild_index apimodel_v2 template t_a_uuid
    nodetool rebuild_index apimodel_v2 template t_entity
    nodetool rebuild_index apimodel_v2 template t_name
    nodetool rebuild_index apimodel_v2 template t_org_name
    nodetool rebuild_index apimodel_v2 template_auth au_api_uuid
    
  6. 重建键空间的索引:dek

    nodetool rebuild_index dek keys usecase_index
    
  7. [仅限创收] 重建键空间的索引:mint

    nodetool rebuild_index mint limits limits_created_date_idx
    nodetool rebuild_index mint limits limits_id_idx
    nodetool rebuild_index mint limits limits_org_id_idx
    nodetool rebuild_index mint limits limits_updated_date_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_created_date_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_currency_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_dev_id_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_id_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_limit_id_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_org_id_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_prod_id_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_reason_code_idx
    nodetool rebuild_index mint suspended_developer_products suspended_developer_products_sub_org_id_idx
    nodetool rebuild_index mint invitations invitations_company_id_idx
    nodetool rebuild_index mint invitations invitations_created_at_idx
    nodetool rebuild_index mint invitations invitations_developer_id_idx
    nodetool rebuild_index mint invitations invitations_lastmodified_at_idx
    nodetool rebuild_index mint invitations invitations_org_id_idx
    
  8. [仅限创收] 重建键空间的索引:taurus

    nodetool rebuild_index taurus triggers triggers_env_idx
    nodetool rebuild_index taurus triggers triggers_job_id_idx
    nodetool rebuild_index taurus triggers triggers_org_id_idx
    nodetool rebuild_index taurus job_details job_details_job_class_name_idx
    nodetool rebuild_index taurus job_details job_details_job_group_idx
    nodetool rebuild_index taurus job_details job_details_job_name_idx
    nodetool rebuild_index taurus org_triggers org_triggers_org_id_idx
    nodetool rebuild_index taurus triggers_suite triggers_suite_group_idx
    nodetool rebuild_index taurus triggers_suite triggers_suite_name_idx
    nodetool rebuild_index taurus triggers_suite triggers_suite_suite_id_idx
    
  9. [仅限创收] 重建键空间的索引:notification

    nodetool rebuild_index notification notification_service_item notification_service_item_org_id_idx
    nodetool rebuild_index notification notification_service_item notification_service_item_status_idx
    nodetool rebuild_index notification notification_service_black_list_item notification_service_black_list_item_org_id_idx
    nodetool rebuild_index notification notification_service_black_list_item notification_service_black_list_item_to_email_idx
    nodetool rebuild_index notification notification_email_template_item notification_email_template_item_name_idx
    nodetool rebuild_index notification notification_email_template_item notification_email_template_item_org_id_idx
    

验证

  1. 按照 附录 1中的 说明检查架构中的压缩策略更改是否已生效。
  2. 验证压缩是否已成功运行,并且数据在策略更改后已压缩:
    1. 在每个 Cassandra 节点上,运行以下 nodetool 命令,查看所有压缩是否已完成,是否有任何压缩处于待处理状态:
      nodetool compactionstats
    2. 使用上述命令验证以确保没有待处理的压缩后,检查数据文件(位于 /opt/apigee/data/apigee-cassandra/data/ 下)的上次修改时间戳是否晚于执行压缩策略更改 CQL 的时间戳。

回滚

如果您需要执行回滚,可以选择以下选项之一:

方法 1:还原更改

将压缩策略回滚到您最初使用的策略。

在 CQL 提示符下运行与您之前运行的命令类似的 ALTER TABLE 命令,以 更改压缩策略。

如果您在将压缩策略更改为 LeveledCompactionStrategy 时已重建索引,则需要再次重建索引。请按照与之前重建所有索引相同的步骤操作。如果您之前没有重建索引,则在回滚期间无需重建索引。

方法 2:从备份中完整恢复数据

从备份中恢复所有键空间的数据:

按照从备份恢复中记录的说明进行恢复。

附录 1:检查压缩策略

压缩策略在 Cassandra 中是在表一级设置的。您可以使用以下查询检查每个表的压缩策略。

您可以在 CQL 提示符下运行 CQL。如需调用 CQL 提示符,请执行以下操作:

/opt/apigee/apigee-cassandra/bin/cqlsh `hostname -i`

您将看到类似如下的响应:

Connected to apigee at XX.XX.XX.XX:9042.
[cqlsh 6.2.0 | Cassandra 5.0.8 | CQL spec 3.4.7 | Native protocol v5]
Use HELP for help.
cqlsh>

您可以按如下方式确定当前的压缩策略:

输出中的每一行都与键空间中的一个表有关。对于每一行,列 compaction 表示表使用的压缩策略。

  • 如果压缩策略设置为 SizeTieredCompactionStrategy,则以下查询中的 compaction 列将类似于以下内容:
  • {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
  • 如果压缩策略设置为 LeveledCompactionStrategy,则以下查询中的 compaction 列将类似于以下内容:
  • {'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'}

您可以运行以下查询,确定特定键空间中每个表的压缩策略:

select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'kms';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'user_settings';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'keyvaluemap';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'devconnect';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'counter';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'cache';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'auth';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'audit';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'apprepo';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'apimodel_v2';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'identityzone';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'dek';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'analytics';

#If you are using Monetization, check the below as well
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'mint';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'taurus';
select keyspace_name, table_name, compaction from system_schema.tables where keyspace_name = 'notification';