Change the Cassandra compaction strategy

Apigee uses Cassandra databases to store most of its data, including data for proxies, caches, and tokens. Compaction is a standard process to reduce the size of the data stored in databases, which is vital to keeping databases running efficiently. Cassandra supports various strategies for compaction. Apigee recommends that all Edge for Private Cloud customers operate their Cassandra clusters with the strategy LeveledCompactionStrategy, rather than the default strategy SizeTieredCompactionStrategy, for all column families. LeveledCompactionStrategy offers better performance, better disk utilization, more efficient compactions, and requires less free space, than SizedTieredCompactionStrategy.

All new installations of Apigee 4.51.00 or later will automatically set up Cassandra with LeveledCompactionStrategy. However, if you are using an older version of Apigee or have upgraded to Apigee 4.51.00 from an older version, your version may still be using Cassandra with SizeTieredCompactionStrategy. To find out which compaction strategy your version of Cassandra is using, see the section Check compaction strategy.

This page explains how to change the compaction strategy to LeveledCompactionStrategy.

Preparation

Check the existing compaction strategy

To check the existing compaction strategy on column families, follow the instructions in Check compaction strategy. If the compaction strategy is already LeveledCompactionStrategy, you don't need to follow the remaining instructions on this page.

Backup

Since changing compaction strategy triggers a full compaction cycle in C* nodes. it might introduce some latencies due to the load of compactions and simultaneous application traffic. A rollback of this change may be required to restore Cassandra nodes from backups. See How to backup to learn how to back up your data before changing the compaction strategy.

Compaction throughput

After the compaction strategy is changed to LeveledCompactionStrategy, compactions may run for a long time. Depending on the size of the data compaction, runtime may vary. During the compaction cycle, Cassandra may use up more system resources. To ensure compaction does not take up a lot of system resources, which might disrupt API Runtime requests, we recommend setting limits for compaction throughput.

Run the following nodetool command on each of the nodes to set compaction throughput to max out at 128MB on all C* nodes:

nodetool setcompactionthroughput 128

Sizing VMs for compactions

Ensure, C* nodes have enough CPU/Memory resources before executing this change. Ensure that no C* nodes are operating at more than 25% of the CPU load before executing this change.

After a compaction strategy change, a full compaction cycle is expected to run, so it is recommended to change the compaction strategy during low traffic periods.

Staggered runs

You might not be able to complete the change of all nodes within a day, especially if you operate large Cassandra clusters, as indices need to be rebuilt on each node one by one. You could change the compaction strategy of one schema or one column family (table) at a time. For this, alter the column family to change its compaction strategy and then rebuild all indices on the table (if any) on all the nodes. Then repeat the above procedure for each table or keyspace. Such runs for one table or one keyspace can be broken down to be run across different days.

For example, to change compaction strategy of oauth_20_access_tokens column family in kms schema, you can do the following:

  1. Alter table to change compaction strategy:
       
    ALTER TABLE kms.oauth_20_access_tokens WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  2. Rebuild all indices of just this table:
    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

Changing compaction strategy

At a high level, changing compaction strategy is a 2-step process:

  1. Modify compaction strategy of every table.
  2. Rebuild all indices on each node one by one.

Alter Table to set new compaction strategy

Run the following Cassandra Query Language (CQL) commands on any one Cassandra node, changing strategy for one keyspace at a time. You can run CQLs can at the cql prompt. To invoke the cql prompt:

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

You will see a response like the following:

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>

Run the following CQLs to change the compaction strategy:

  • CQLs to change compaction strategy for keyspace 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'};
  • CQLs to change compaction strategy for keyspace user_settings:
    ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace keyvaluemap:
       
    ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace 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'};
  • CQLs to change compaction strategy for keyspace 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'};
  • CQLs to change compaction strategy for keyspace cache:
    ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace ax_custom_report_model:
    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'};
  • CQLs to change compaction strategy for keyspace auth:
    ALTER TABLE auth.totp WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace audit:
    ALTER TABLE audit.audits WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE audit.audits_ref WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace 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'};
  • CQLs to change compaction strategy for keyspace apimodel:
    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'};
  • CQLs to change compaction strategy for keyspace identityzone:
    ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace dek:
    ALTER TABLE dek.keys WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace 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'};

Rebuild indices

You need to execute this step after the compaction strategy change. Run the following nodetool commands one by one on each Cassandra node one after the other.

Run the following nodetool commands to rebuild indices:

  • Rebuild indices for keyspace 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
  • Rebuild indices for keyspace 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
  • Rebuild indices for keyspace cache:
        
    nodetool rebuild_index cache cache_entries cache_entries_cache_name_idx
  • Rebuild indices for keyspace 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
  • Rebuild indices for keyspace apprepo:
    nodetool rebuild_index apprepo environments environments_organization_name_idx
  • Rebuild indices for keyspace 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
  • Rebuild indices for keyspace dek:
    nodetool rebuild_index dek keys usecase_index

Verification

  1. Check that the compaction strategy change on schema has taken effect by following the instructions in Check compaction strategy.
  2. Verify compaction has run successfully and data is compacted after the strategy change:
    1. On each cassandra node, run the following nodetool command to see if all compactions are completed and nothing is pending:
      nodetool compactionstats
    2. Once verified by using the command above to ensure no compactions are pending, check the last modified timestamp of the data files (under /opt/apigee/data/apigee-cassandra/data/) to be after the timestamp when the compaction strategy change CQL was executed.

Roll back

In case you need to roll back, you can follow one of the options below:

Option 1: Revert change

Roll back the compaction strategy to SizeTieredCompactionStrategy.

Run the following CQLs on any one Cassandra node changing strategy for one keyspace at a time. You can run CQLs at the cql prompt. To invoke the cql prompt:

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

You will see a response like the following:

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>

Run the following CQLs to change the compaction strategy:

  • CQLs to change compaction strategy for keyspace kms:
    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'};
  • CQLs to change compaction strategy for keyspace user_settings:
    ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace keyvaluemap:
    ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace devconnect:
    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'};
  • CQLs to change compaction strategy for keyspace counter:
    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'};
  • CQLs to change compaction strategy for keyspace cache:
    ALTER TABLE cache.cache_entries WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
    ALTER TABLE cache.cache_sequence_id_r24 WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace ax_custom_report_model:
    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'};
  • CQLs to change compaction strategy for keyspace auth:
    ALTER TABLE auth.totp WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace audit:
    ALTER TABLE audit.audits WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
    ALTER TABLE audit.audits_ref WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace apprepo:
    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'};
  • CQLs to change compaction strategy for keyspace apimodel:
    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'};
  • CQLs to change compaction strategy for keyspace identityzone:
    ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
    ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace dek:
        
    ALTER TABLE dek.keys WITH compaction = {'class' : 'SizeTieredCompactionStrategy'};
  • CQLs to change compaction strategy for keyspace analytics:
    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'};

After all the column families have been altered, if you have already rebuilt indices while changing compaction strategy to LeveledCompactionStrategy, you will need to rebuild indices again. Follow the same steps as earlier for rebuilding all indices. If you didn’t rebuild indices earlier, you don’t need to rebuild indices during the rollback.

Option 2 - Full data restore from backup

To perform a full data restore, see the instructions in Restore from backiup.

Check compaction strategy

Compaction strategies are set at a column family (table) level in Cassandra. You can use the CQL queries below to check compaction strategy for each column family.

You can run CQLs at the cql prompt. To invoke cql prompt:

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

You will see a response like the following:

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>

You can determine the current compaction strategy as follows:

  • If the compaction strategy is set to SizeTieredCompactionStrategy, the output of the queries below will be org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy.
  • If the compaction strategy is set to LeveledCompactionStrategy, the output of the queries below will be org.apache.cassandra.db.compaction.LeveledCompactionStrategy.

Run the following CQLs to verify the compaction strategy:

  • CQLs to verify compaction strategy for keyspace kms:
    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';
  • CQLs to verify compaction strategy for keyspace user_settings:
    SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'user_settings' and columnfamily_name = 'user_settings';
  • CQLs to verify compaction strategy for keyspace keyvaluemap:
    SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'keyvaluemap' and columnfamily_name = 'keyvaluemaps_r21';
  • CQLs to verify compaction strategy for keyspace devconnect:
    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';
  • CQLs to verify compaction strategy for keyspace counter:
    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';
  • CQLs to verify compaction strategy for keyspace cache:
    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';
  • CQLs to verify compaction strategy for keyspace ax_custom_report_model:
    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';
  • CQLs to verify compaction strategy for keyspace auth:
    SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'auth' and columnfamily_name = 'totp';
  • CQLs to verify compaction strategy for keyspace audit:
    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';
  • CQLs to verify compaction strategy for keyspace apprepo:
    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';
  • CQLs to verify compaction strategy for keyspace apimodel:
    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';
  • CQLs to verify compaction strategy for keyspace identityzone:
    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';
  • CQLs to verify compaction strategy for keyspace dek:
    SELECT compaction_strategy_class from system.schema_columnfamilies where keyspace_name = 'dek' and columnfamily_name = 'keys';
  • CQLs to verify compaction strategy for keyspace analytics:
    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';