> [!NOTE]
> **Note:** Follow instructions on this page if you are using Cassandra 3.X with Edge for Private Cloud 4.52.02 or later.
>
> If you have not yet upgraded Cassandra to version 3.X and are looking to change compaction strategy to LeveledCompactionStrategy as part of upgrade prerequisites, you should refer to the article pertaining to Changing Compaction Strategy specific to the Private Cloud version you are on.
>
> For example, if you are currently on Private Cloud version 4.52.00, with Cassandra 2.X and are looking for steps to change compaction strategy to LeveledCompactionStrategy as part of upgrade prerequisites, refer to version 4.52.00's [Change the Cassandra compaction strategy](https://docs.apigee.com/private-cloud/v4.52.00/cassandra-compaction-strategy) page.

Apigee uses the Cassandra database to store most of its data, including data for proxies, caches, and tokens. *Compaction* is a critical process for reducing the size of data stored in databases, essential for maintaining efficient database operations. Cassandra supports various strategies for compaction. Apigee recommends that all Edge for Private Cloud customers operate their Cassandra clusters with the `LeveledCompactionStrategy`, rather than the default `SizeTieredCompactionStrategy`, for all tables. `LeveledCompactionStrategy` offers better performance, improved disk utilization, more efficient compactions, and requires less free space compared to `SizeTieredCompactionStrategy`.

All new installations of Apigee 4.52.02 or later automatically configure Cassandra with `LeveledCompactionStrategy`. However, if you are using an older version of Apigee or have upgraded to Apigee 4.52.02 from an older version, your installation may still use Cassandra with `SizeTieredCompactionStrategy`.

Although it is not recommended to change the compaction strategy to anything other than `LeveledCompactionStrategy`, this document outlines how to make the change if necessary and provides instructions for checking your current compaction strategy. Changing the compaction strategy to a non-recommended option may result in future Cassandra software upgrades overwriting your changes. We recommend that you verify your compaction strategy after every upgrade if you are using a non-standard approach.

## Preparation

### Check the existing compaction strategy

You can check the existing compaction strategy on tables by following the instructions in [Appendix 1](https://docs.apigee.com/private-cloud/v4.52.02/cassandra-compaction-strategy#appendix-1:-check-compaction-strategy). If the compaction strategy is already `LeveledCompactionStrategy`, it may be due to starting with an installation of OPDK 4.51 or later, or having previously changed to `LeveledCompactionStrategy` as recommended by Apigee. If you are already using `LeveledCompactionStrategy`, Apigee recommends continuing with this strategy and avoiding changes. However, since Edge for Private Cloud is operated by you, the following instructions explain how to change the compaction strategy if desired.

> [!CAUTION]
> **Caution:** If you engage Apigee support for an issue and it is observed that the problem could have been caused by Cassandra, Apigee support will likely ask you to first modify your cluster to use the recommended compaction strategy (`LeveledCompactionStrategy`) before troubleshooting further.

### Backup

Since changing the compaction strategy triggers a full compaction cycle in Cassandra 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](https://docs.apigee.com/private-cloud/v4.52.02/how-perform-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 Cassandra nodes:

```
nodetool setcompactionthroughput 128
```

### Sizing VMs for compactions

Ensure Cassandra nodes have enough CPU and memory resources before executing this change. Please ensure that no Cassandra 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 may 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 table at a time. For this, alter the table 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 the compaction strategy of the `oauth_20_access_tokens` table in the `kms` schema to `LeveledCompactionStrategy`, you can do the following:

1. Alter table to change compaction strategy by running the following CQL:

   ```
   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 the compaction strategy is a two-step process:

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

For modifying the compaction strategy, you need to execute an `ALTER TABLE` command on each table one at a time. A sample `ALTER TABLE` command would look like below:

    # 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'};

### Alter Table to Set New Compaction Strategy

Run the following CQLs on any one Cassandra node to change the strategy for one keyspace at a time. CQLs can be run on the CQL prompt. Instructions to invoke the CQL prompt:

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

Connected to Apigee at XXXXXXXX:9042.

```
[cqlsh 5.0.1 | Cassandra 3.11.16 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
```

The commands below cover changing the Compaction Strategy to `LeveledCompactionStrategy`, but similar commands can be used to change to other compaction strategies.

Steps 14 to 16 below are only applicable if you use monetization.

1. 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'};
   ```
2. CQLs to change compaction strategy for keyspace: `user_settings`

   ```
   ALTER TABLE user_settings.user_settings WITH compaction = {'class' : 'LeveledCompactionStrategy'};
   ```
3. CQLs to change compaction strategy for keyspace: `keyvaluemap`

   ```
   ALTER TABLE keyvaluemap.keyvaluemaps_r21 WITH compaction = {'class' : 'LeveledCompactionStrategy'};
   ```
4. 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'};
   ```
5. 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'};
   ```
6. 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'};
   ```
7. CQLs to change compaction strategy for keyspace: `auth`

   ```
   ALTER TABLE auth.totp WITH compaction = {'class' : 'LeveledCompactionStrategy'};
   ```
8. 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'};
   ```
9. 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'};
   ```
10. CQLs to change compaction strategy for keyspace: `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. CQLs to change compaction strategy for keyspace: `identityzone`

    ```
    ALTER TABLE identityzone.IdentityZones WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ALTER TABLE identityzone.OrgToIdentityZone WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ```
12. CQLs to change compaction strategy for keyspace: `dek`

    ```
    ALTER TABLE dek.keys WITH compaction = {'class' : 'LeveledCompactionStrategy'};
    ```
13. 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'};
    ```
14. **\[Monetization only\]** CQLs to change compaction strategy for keyspace: `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. **\[Monetization only\]** CQLs to change compaction strategy for keyspace: `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. **\[Monetization only\]** CQLs to change compaction strategy for keyspace: `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'};
    ```

### Rebuild Indices

This step needs to be executed after any compaction strategy change. Please run the following `nodetool` commands one by one on each Cassandra node.

> [!NOTE]
> **Note:**
>
> - The `nodetool` command may be located at `/opt/apigee/apigee-cassandra/bin/nodetool`. You may need to pass the entire path to `nodetool` if it cannot be located by your OS.
> - Rebuilding indices of `kms` and `audit` keyspaces may take a while to complete.

Steps 7 to 9 below are only applicable if you use monetization.

1. Rebuild indices for keyspace: `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. 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
   ```
3. Rebuild indices for keyspace: `cache`

   ```
   nodetool rebuild_index cache cache_entries cache_entries_cache_name_idx
   ```
4. 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
   ```
5. Rebuild indices for keyspace: `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. Rebuild indices for keyspace: `dek`

   ```
   nodetool rebuild_index dek keys usecase_index
   ```
7. **\[Monetization only\]** Rebuild indices for keyspace: `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. **\[Monetization only\]** Rebuild indices for keyspace: `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. **\[Monetization only\]** Rebuild indices for keyspace: `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
   ```

### Verification

1. Check that the compaction strategy change on schema has taken effect by following instructions in [Appendix 1](https://docs.apigee.com/private-cloud/v4.52.02/cassandra-compaction-strategy#appendix-1:-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.

## Rollback

In case you need to perform a rollback, you can choose one of the options below:

### Option 1: Revert change

Rollback the compaction strategy to the strategy you originally had.

> [!WARNING]
> **Caution:** Changing the compaction strategy during rollback will cause another set of compactions to run. Rollback only if absolutely necessary and take precautions to allow compactions to complete.

Run similar ALTER TABLE commands on the CQL prompt that you had run earlier to [change the compaction strategy](https://docs.apigee.com/private-cloud/v4.52.02/cassandra-compaction-strategy#alter-table-to-set-new-compaction-strategy).

If you had already rebuilt indices while changing the compaction strategy to `LeveledCompactionStrategy`, you will need to rebuild indices again. Follow the same steps as earlier for [rebuilding all indices](https://docs.apigee.com/private-cloud/v4.52.02/cassandra-compaction-strategy#rebuild-indices). If you didn't rebuild indices earlier, you do not need to rebuild indices during rollback.

### Option 2: Full data restore from backup

Restore data from backup for all keyspaces:

> [!WARNING]
> **Caution:** This option restores data from all keyspaces, including both runtime and management keyspaces. Restoring from backup may result in data loss, especially any data that was added to Cassandra between the backup creation and restore operation. Use this restore option only when absolutely necessary.

Please follow instructions to restore as documented in [Restore from a backup](https://docs.apigee.com/private-cloud/v4.52.02/how-perform-restore).

## Appendix 1: Check compaction strategy

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

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 3.11.16 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
```

You can determine the current compaction strategy as follows:

Each row in the output pertains to a table within a keyspace. For each row, the column *compaction* indicates the compaction strategy used by the table.

- If the compaction strategy is set to SizeTieredCompactionStrategy, the column *compaction* in the queries below will be something like this:

```
{'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
```
- If the compaction strategy is set to LeveledCompactionStrategy, the column *compaction* in the queries below will be something like this:

```
{'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'}
```

Queries below can be run to determine compaction strategy for each table in a particular keyspace:

```
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';
```