變更 Cassandra 壓縮策略

Apigee 使用 Cassandra 資料庫儲存大部分資料,包括 Proxy、快取和權杖的資料。壓縮是減少資料儲存庫儲存資料大小的重要程序,有助於維持資料庫的運作效率。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

調整 VM 大小以進行壓縮

執行這項變更前,請確認 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`

已連線至 Apigee (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,下方查詢中的「壓縮」欄會類似於:
  • {'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';