更改 Cassandra 压缩策略

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

所有新安装的 Apigee 4.52.02 或更高版本都会自动为 Cassandra 配置 LeveledCompactionStrategy。但是,如果您使用的是旧版 Apigee,或者已从旧版升级到 Apigee 4.52.02,则安装时可能仍将 Cassandra 与 SizeTieredCompactionStrategy 搭配使用。

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

准备

检查现有的压缩策略

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

备份

由于更改压缩策略会在 Cassandra 节点中触发完整的压缩周期,因此可能会因压缩负载和并发应用流量而引入一些延迟。如需从备份恢复 Cassandra 节点,可能需要回滚此更改。请参阅如何备份,了解如何在更改压缩策略之前备份数据。

压缩吞吐量

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

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

nodetool setcompactionthroughput 128

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

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

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

交错运行

您可能无法在一天内完成所有节点的更改,尤其是当您操作大型 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`

在 XXXXXXXX:9042 连接到 Apigee。

[cqlsh 5.0.1 | Cassandra 3.11.16 | CQL spec 3.4.4 | Native protocol v4]
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 5.0.1 | Cassandra 3.11.16 | CQL spec 3.4.4 | Native protocol v4]
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';