變更 Cassandra 壓縮策略

Apigee 會使用 Cassandra 資料庫儲存大部分資料,包括 Proxy、快取和符記的資料。壓縮是減少資料庫儲存資料大小的重要程序,對於維護效率良好的資料庫作業而言,至關重要。Cassandra 支援多種壓縮策略。Apigee 建議所有 Private Cloud 客戶使用 LeveledCompactionStrategy (而非預設的 SizeTieredCompactionStrategy),為所有資料表操作 Cassandra 叢集。LeveledCompactionStrategy 提供更佳效能、更高的磁碟使用率、更有效率的壓縮功能,且與 SizeTieredCompactionStrategy 相比,所需的空間較少。

安裝 Apigee 4.52.02 以上版本的所有新安裝項目,都會自動使用 LeveledCompactionStrategy 設定 Cassandra。不過,如果您使用的是舊版 Apigee,或是已從舊版升級至 Apigee 4.53.00,安裝程序可能仍會使用 Cassandra 搭配 SizeTieredCompactionStrategy

雖然不建議將壓縮策略改為 LeveledCompactionStrategy 以外的任何內容,但本文將概述如何在必要時進行變更,並提供檢查目前壓縮策略的操作說明。如果將壓縮策略改為不建議的選項,日後升級 Cassandra 軟體時可能會覆寫您的變更。如果您使用非標準方法,建議您在每次升級後確認壓縮策略。

準備

檢查現有的壓縮策略

如要查看表格現有的壓縮策略,請按照 附錄 1 的指示操作。如果壓縮策略已處於 LeveledCompactionStrategy 狀態,可能是因為開始安裝 OPDK 4.51 以上版本,或之前曾按照 Apigee 建議變更為 LeveledCompactionStrategy。如果您已使用 LeveledCompactionStrategy,Apigee 建議您繼續採用這項策略,避免變更。不過,由於 Edge for Private Cloud 是由您操作,因此下列操作說明會說明如何視需要變更壓縮策略。

備份

由於變更壓縮策略會在 Cassandra 節點中觸發完整的壓縮週期,因此可能會因為壓縮和同時應用程式流量的負載而造成一些延遲。您可能需要回復這項變更,才能從備份還原 Cassandra 節點。請參閱「如何備份」,瞭解如何在變更壓縮策略前備份資料。

壓縮處理量

將壓縮策略變更為 LeveledCompactionStrategy 後,壓縮為 好像我們願意繼續說 他們耐心等待執行時間可能會因資料壓縮大小而異。在壓縮週期期間,Cassandra 可能會耗用更多系統資源。為確保壓縮作業不會占用太多系統資源,進而中斷 API 執行階段要求,建議您設定壓縮處理量的限制。

在每個節點上執行下列 nodetool 指令,將壓縮傳輸量設為所有 Cassandra 節點的 128 MB 上限:

nodetool setcompactionthroughput 128

調整 VM 大小以進行壓縮

請先確認 Cassandra 節點有足夠的 CPU 和記憶體資源,再執行這項變更。請先確認沒有任何 Cassandra 節點的 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`

已在 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. 可變更鍵空間的壓縮策略:user_settings
    ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  3. 可變更鍵空間的壓縮策略:keyvaluemap
    ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  4. 可變更鍵空間的壓縮策略: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. 可變更鍵空間的壓縮策略:cache
    ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    
  7. 可變更鍵空間的壓縮策略: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. 可變更鍵空間的壓縮策略: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. 可變更鍵空間的壓縮策略: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. [僅限營利] 負責變更鍵空間的壓縮策略: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. [僅限營利] 負責變更鍵空間的壓縮策略: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,下列查詢中的資料欄壓縮看起來會像這樣:
  • {'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';