Risk alert: InnoDB compressed tables with KEY_BLOCK_SIZE less than 4 KB may cause data corruption

Updated at:

Issue description

PolarDB for MySQL uses a proprietary distributed file system whose minimum atomic write unit is 4 KB. When InnoDB compressed tables (ROW_FORMAT=COMPRESSED) use a KEY_BLOCK_SIZE less than 4 KB (that is, 1 KB or 2 KB), the mismatch between the compressed block size and the underlying atomic write unit may cause data corruption. To avoid data loss, check your table configurations and take the recommended actions described in this topic.

Affected versions

Database engine version

Affected revision versions

PolarDB for MySQL 5.6

≤ 5.6.1.0.46.1

PolarDB for MySQL 5.7

≤ 5.7.1.0.40

PolarDB for MySQL 8.0.1

≤ 8.0.1.1.53

PolarDB for MySQL 8.0.2

≤ 8.0.2.2.33

Note

You can check your current database engine version in the Settings and Management > Version Management page of the PolarDB for MySQL cluster in the console.

Solution

  1. Check whether your cluster has any affected compressed tables.

    Run one of the following SQL queries based on your database engine version to identify InnoDB compressed tables with KEY_BLOCK_SIZE less than 4 KB:

    • For PolarDB for MySQL 5.6 and 5.7:

      SELECT * FROM information_schema.innodb_sys_tables WHERE ROW_FORMAT = 'Compressed' AND ZIP_PAGE_SIZE < 4096;
    • For PolarDB for MySQL 8.0.1 and 8.0.2:

      SELECT * FROM information_schema.innodb_tables WHERE ROW_FORMAT = 'Compressed' AND ZIP_PAGE_SIZE < 4096;

    If the query returns any results, your cluster has affected tables. Submit a ticket for assistance with the affected tables. If the query returns no results, we still recommend upgrading your cluster to a fixed version for automatic protection.

    Warning

    On affected versions, do not create compressed tables with KEY_BLOCK_SIZE less than 4 KB. If you need to use compressed tables, make sure that KEY_BLOCK_SIZE is set to 4 or greater.

  2. Upgrade the database to a fixed engine version.

    Warning

    Upgrading the database engine version may cause a brief connection interruption. We recommend that you perform this operation during off-peak hours.

    Upgrade the database engine to a version later than the affected versions listed in the preceding table. For more information, see Revision version management.

  3. After the upgrade, configure a policy to prevent creation of incompatible compressed tables. Fixed versions introduce the polar_compressed_table_policy parameter, which controls how the system handles the creation of compressed tables. The following policies are available:

    Policy

    Behavior

    NATIVE

    Executes the statement as-is without intervention. Not recommended due to the risk of data corruption.

    ADJUST_KEY_BLOCK_SIZE

    Default policy. Allows compressed table creation but automatically adjusts KEY_BLOCK_SIZE to 4 if the specified value is less than 4.

    AUTO_CONVERT_ROW_FORMAT

    Silently converts the table to the default row format instead of creating a compressed table.

    REJECTED

    Rejects the compressed table creation and returns an error.

    Note

    We recommend setting polar_compressed_table_policy to ADJUST_KEY_BLOCK_SIZE (default), AUTO_CONVERT_ROW_FORMAT, or REJECTED to prevent accidental data corruption.