Apigee 使用 Cassandra 数据库来存储其大部分数据,包括代理、缓存和令牌的数据。
压缩是一种用于缩减数据库中存储的数据大小的标准流程,对确保数据库高效运行至关重要。Cassandra 支持各种压缩策略。Apigee 建议所有 Edge for Private Cloud 客户针对所有列族使用策略 LeveledCompactionStrategy
(而非默认策略 SizeTieredCompactionStrategy
)来运行 Cassandra 集群。与 SizedTieredCompactionStrategy
相比,LeveledCompactionStrategy
可提供更好的性能、更高的磁盘利用率、更高效的压缩,并且需要的空闲空间更少。
所有新安装的 Apigee 4.51.00 或更高版本都会自动使用 LeveledCompactionStrategy
设置 Cassandra。不过,如果您使用的是较低版本的 Apigee,或者从较低版本升级到了 Apigee 4.51.00,您的版本可能仍在使用带有 SizeTieredCompactionStrategy
的 Cassandra。
如需了解您的 Cassandra 版本使用的是哪种压缩策略,请参阅检查压缩策略部分。
本页介绍了如何将压缩策略更改为 LeveledCompactionStrategy
。
准备工作
检查现有压缩策略
如需检查列族的现有压缩策略,请按照检查压缩策略中的说明操作。如果压缩策略已设为 LeveledCompactionStrategy
,则无需按照本页中的其余说明操作。
备份
由于更改压缩策略会在 C* 节点中触发完整压缩周期,因此可能会因压缩负载和同时的应用流量而引入一些延迟。您可能需要回滚此更改,才能从备份恢复 Cassandra 节点。 请参阅如何备份,了解如何在更改压缩策略之前备份数据。
压缩吞吐量
将压缩策略更改为 LeveledCompactionStrategy
后,压缩操作可能会运行很长时间。运行时可能会因数据压缩的大小而异。在压缩周期期间,Cassandra 可能会耗用更多系统资源。为确保压缩不会占用大量系统资源(这可能会中断 API 运行时请求),我们建议您为压缩吞吐量设置限制。
在每个节点上运行以下 nodetool
命令,以将所有 C* 节点上的压缩吞吐量设置为上限为 128MB:
nodetool setcompactionthroughput 128
为压缩调整虚拟机的大小
在执行此更改之前,请确保 C* 节点有足够的 CPU/内存资源。在执行此更改之前,请确保没有任何 C* 节点的 CPU 负载超过 25%。
更改压缩策略后,系统预计会运行一个完整的压缩周期,因此建议在流量较低时更改压缩策略。
分批运行
您可能无法在一天内完成所有节点的更改,尤其是在您运营大型 Cassandra 集群的情况下,因为需要在每个节点上逐个重新构建索引。您一次只能更改一个架构或一个列族(表)的压缩策略。为此,请更改列族以更改其压缩策略,然后在所有节点上重建表上的所有索引(如果有)。然后,对每个表或键空间重复上述步骤。针对一个表或一个键空间的此类运行作业可以拆分为在不同日期运行。
例如,如需更改 kms
架构中 oauth_20_access_tokens
列族的压缩策略,您可以执行以下操作:
- 更改表以更改压缩策略:
ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 仅重建此表的所有索引:
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
更改压缩策略
概括来讲,更改压缩策略是一个 2 步流程:
- 修改每个表的压缩策略。
- 逐个重新构建每个节点上的所有索引。
修改表以设置新的压缩策略
在任意 Cassandra 节点上运行以下 Cassandra 查询语言 (CQL) 命令,一次更改一个键空间的策略。您可以在 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 2.1.16 | CQL spec 3.2.1 | Native protocol v3] Use HELP for help. cqlsh>
运行以下 CQL 以更改压缩策略:
- 用于更改键空间
kms
的压缩策略的 CQL: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'};
- 用于更改键空间
user_settings
的压缩策略的 CQL:ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
keyvaluemap
的压缩策略的 CQL:ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
devconnect
的压缩策略的 CQL: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'};
- 用于更改键空间
counter
的压缩策略的 CQL: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'};
- 用于更改键空间
cache
的压缩策略的 CQL:ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
ax_custom_report_model
的压缩策略的 CQL:ALTER TABLE ax_custom_report_model.report_description WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_id_lookup WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE ax_custom_report_model.org_metadata WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE ax_custom_report_model.org_report_lookup WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_created_view WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_viewed_view WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
auth
的压缩策略的 CQL:ALTER TABLE auth.totp WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
audit
的压缩策略的 CQL:ALTER TABLE audit.audits WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE audit.audits_ref WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
apprepo
的压缩策略的 CQL: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'};
- 用于更改键空间
apimodel
的压缩策略的 CQL:ALTER TABLE apimodel.apis WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.apis_revision WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.resource WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.method WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.revision_counters WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.template_counters WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.template WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.credentials WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.credentialsv2 WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.schemas WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.security WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE apimodel.template_auth WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
identityzone
的压缩策略的 CQL:ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'LeveledCompactionStrategy'}; ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
dek
的压缩策略的 CQL:ALTER TABLE dek.keys WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- 用于更改键空间
analytics
的压缩策略的 CQL: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'};
重建索引
您需要在压缩策略更改后执行此步骤。依次在每个 Cassandra 节点上逐个运行以下 nodetool
命令。
运行以下 nodetool
命令以重新构建索引:
- 为键空间
kms
重新构建索引:nodetool rebuild_index kms maps maps_organization_name_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 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 api_products api_products_organization_name_idx nodetool rebuild_index kms app_end_user app_end_user_app_id_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 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_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_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_verifiers oauth_10_verifiers_organization_name_idx nodetool rebuild_index kms oauth_10_verifiers oauth_10_verifiers_request_token_idx
- 为键空间
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
- 为键空间
cache
重新构建索引:nodetool rebuild_index cache cache_entries cache_entries_cache_name_idx
- 为键空间
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
- 为键空间
apprepo
重新构建索引:nodetool rebuild_index apprepo environments environments_organization_name_idx
- 为键空间
apimodel
重新构建索引:nodetool rebuild_index apimodel apis a_name nodetool rebuild_index apimodel apis a_org_name nodetool rebuild_index apimodel apis_revision ar_a_name nodetool rebuild_index apimodel apis_revision ar_a_uuid nodetool rebuild_index apimodel apis_revision ar_base_url nodetool rebuild_index apimodel apis_revision ar_is_active nodetool rebuild_index apimodel apis_revision ar_is_latest nodetool rebuild_index apimodel apis_revision ar_org_name nodetool rebuild_index apimodel apis_revision ar_rel_ver nodetool rebuild_index apimodel apis_revision ar_rev_num nodetool rebuild_index apimodel resource r_a_name nodetool rebuild_index apimodel resource r_api_uuid nodetool rebuild_index apimodel resource r_ar_uuid nodetool rebuild_index apimodel resource r_base_url nodetool rebuild_index apimodel resource r_name nodetool rebuild_index apimodel resource r_org_name nodetool rebuild_index apimodel resource r_res_path nodetool rebuild_index apimodel resource r_rev_num nodetool rebuild_index apimodel method m_a_name nodetool rebuild_index apimodel method m_api_uuid nodetool rebuild_index apimodel method m_ar_uuid nodetool rebuild_index apimodel method m_base_url nodetool rebuild_index apimodel method m_name nodetool rebuild_index apimodel method m_org_name nodetool rebuild_index apimodel method m_r_name nodetool rebuild_index apimodel method m_r_uuid nodetool rebuild_index apimodel method m_res_path nodetool rebuild_index apimodel method m_rev_num nodetool rebuild_index apimodel method m_verb nodetool rebuild_index apimodel template t_a_name nodetool rebuild_index apimodel template t_a_uuid nodetool rebuild_index apimodel template t_entity nodetool rebuild_index apimodel template t_name nodetool rebuild_index apimodel template t_org_name nodetool rebuild_index apimodel schemas s_api_uuid nodetool rebuild_index apimodel schemas s_ar_uuid nodetool rebuild_index apimodel security sa_api_uuid nodetool rebuild_index apimodel security sa_ar_uuid nodetool rebuild_index apimodel template_auth au_api_uuid
- 为键空间
dek
重新构建索引:nodetool rebuild_index dek keys usecase_index
验证
- 按照检查压缩策略中的说明,检查架构的压缩策略更改是否已生效。
- 验证压缩是否已成功运行,以及在更改策略后是否压缩了数据:
- 在每个 Cassandra 节点上,运行以下
nodetool
命令,以查看所有压缩操作是否已完成且没有任何待处理的压缩操作:nodetool compactionstats
- 使用上述命令验证没有待处理的压缩操作后,检查数据文件(位于 /opt/apigee/data/apigee-cassandra/data/ 下)的上次修改时间戳,确保该时间戳晚于执行压缩策略更改 CQL 的时间戳。
- 在每个 Cassandra 节点上,运行以下
回滚
如果您需要回滚,可以按照以下任一选项操作:
选项 1:还原更改
将压缩策略回滚到 SizeTieredCompactionStrategy
。
在任意一个 Cassandra 节点上运行以下 CQL,一次更改一个键空间的策略。您可以在 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 2.1.16 | CQL spec 3.2.1 | Native protocol v3] Use HELP for help. cqlsh>
运行以下 CQL 以更改压缩策略:
- 用于更改键空间
kms
的压缩策略的 CQL:ALTER TABLE kms.organizations WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.maps WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.apps WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.app_credentials WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.api_products WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.apiproducts_appslist WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.api_resources WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.app_end_user WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.oauth_20_authorization_codes WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.oauth_10_request_tokens WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.oauth_10_access_tokens WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.oauth_10_verifiers WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE kms.app_enduser_tokens WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
user_settings
的压缩策略的 CQL:ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
keyvaluemap
的压缩策略的 CQL:ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
devconnect
的压缩策略的 CQL:ALTER TABLE devconnect.developers WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE devconnect.companies WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE devconnect.company_developers WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
counter
的压缩策略的 CQL:ALTER TABLE counter.counters_current_version WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.counters_with_expiry WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.counters WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.key_timestamp_count WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.timestamp_key WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.period_timestamp WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE counter.gateway_quota WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
-
用于更改键空间
cache
的压缩策略的 CQL:ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
ax_custom_report_model
的压缩策略的 CQL:ALTER TABLE ax_custom_report_model.report_description WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_id_lookup WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE ax_custom_report_model.org_metadata WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE ax_custom_report_model.org_report_lookup WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_created_view WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE ax_custom_report_model.report_viewed_view WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
auth
的压缩策略的 CQL:ALTER TABLE auth.totp WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
audit
的压缩策略的 CQL:ALTER TABLE audit.audits WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE audit.audits_ref WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
apprepo
的压缩策略的 CQL:ALTER TABLE apprepo.organizations WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apprepo.environments WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apprepo.apiproxies WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apprepo.apiproxy_revisions WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apprepo.api_proxy_revisions_r21 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
apimodel
的压缩策略的 CQL:ALTER TABLE apimodel.apis WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.apis_revision WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.resource WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.method WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.revision_counters WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.template_counters WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.template WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.credentials WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.credentialsv2 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.schemas WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.security WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE apimodel.template_auth WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
identityzone
的压缩策略的 CQL:ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
dek
的压缩策略的 CQL:ALTER TABLE dek.keys WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
- 用于更改键空间
analytics
的压缩策略的 CQL:ALTER TABLE analytics.custom_aggregates_defn WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE analytics.custom_rules_defn WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE analytics.custom_aggregates_defn_updates WITH compaction = {'class' : 'SizeTieredCompactionStrategy'}; ALTER TABLE analytics.custom_rules_defn_updates WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
更改所有列族后,如果您在将压缩策略更改为 LeveledCompactionStrategy
时已重建索引,则需要再次重建索引。按照之前重新构建所有索引的步骤操作。如果您之前未重建索引,则无需在回滚期间重建索引。
选项 2 - 从备份中完全恢复数据
如需执行完整数据恢复,请参阅使用备份进行恢复中的说明。
检查压缩策略
在 Cassandra 中,压缩策略是在列族(表)级设置的。您可以使用以下 CQL 查询检查每个列族的压缩策略。
您可以在 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 2.1.16 | CQL spec 3.2.1 | Native protocol v3] Use HELP for help. cqlsh>
您可以按如下方式确定当前的压缩策略:
- 如果将压缩策略设置为
SizeTieredCompactionStrategy
,则以下查询的输出将为org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
。 - 如果将压缩策略设置为
LeveledCompactionStrategy
,则以下查询的输出将为org.apache.cassandra.db.compaction.LeveledCompactionStrategy
。
运行以下 CQL 以验证压缩策略:
- 用于验证键空间
kms
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'organizations'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'maps'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'apps'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'app_credentials'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'api_products'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'apiproducts_appslist'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'api_resources'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'app_end_user'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'oauth_20_authorization_codes'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'oauth_20_access_tokens'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'oauth_10_request_tokens'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'oauth_10_access_tokens'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'oauth_10_verifiers'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name ='kms' and columnfamily_name = 'app_enduser_tokens';
- 用于验证键空间
user_settings
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'user_settings' and columnfamily_name = 'user_settings';
- 用于验证键空间
keyvaluemap
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'keyvaluemap' and columnfamily_name = 'keyvaluemaps_r21';
- 用于验证键空间
devconnect
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'devconnect' and columnfamily_name = 'developers'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'devconnect' and columnfamily_name = 'companies'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'devconnect' and columnfamily_name = 'company_developers';
- 用于验证键空间
counter
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'counters_current_version'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'counters_with_expiry'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'counters'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'key_timestamp_count'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'timestamp_key'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'period_timestamp'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'counter' and columnfamily_name = 'gateway_quota';
- 用于验证键空间
cache
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'cache' and columnfamily_name = 'cache_entries'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'cache' and columnfamily_name = 'cache_sequence_id_r24';
- 用于验证键空间
ax_custom_report_model
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'report_description'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'report_id_lookup'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'org_metadata'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'org_report_lookup'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'report_created_view'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'ax_custom_report_model' and columnfamily_name = 'report_viewed_view';
- 用于验证键空间
auth
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'auth' and columnfamily_name = 'totp';
- 用于验证键空间
audit
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'audit' and columnfamily_name = 'audits'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'audit' and columnfamily_name = 'audits_ref';
- 用于验证键空间
apprepo
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apprepo' and columnfamily_name = 'organizations'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apprepo' and columnfamily_name = 'environments'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apprepo' and columnfamily_name = 'apiproxies'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apprepo' and columnfamily_name = 'apiproxy_revisions'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apprepo' and columnfamily_name = 'api_proxy_revisions_r21';
- 用于验证键空间
apimodel
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'apis'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'apis_revision'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'resource'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'method'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'revision_counters'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'template_counters'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'template'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'credentials'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'credentialsv2'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'schemas'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'security'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'apimodel' and columnfamily_name = 'template_auth';
- 用于验证键空间
identityzone
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'identityzone' and columnfamily_name = 'identityzones'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'identityzone' and columnfamily_name = 'orgtoidentityzone';
- 用于验证键空间
dek
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'dek' and columnfamily_name = 'keys';
- 用于验证键空间
analytics
的压缩策略的 CQL:SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'analytics' and columnfamily_name = 'custom_aggregates_defn'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'analytics' and columnfamily_name = 'custom_rules_defn'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'analytics' and columnfamily_name = 'custom_aggregates_defn_updates'; SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'analytics' and columnfamily_name = 'custom_rules_defn_updates';