OOM when alter column to compression

Description

Got an OOM when doing
ALTER TABLE t1 MODIFY a10 BLOB COLUMN_FORMAT COMPRESSED;

Reproduction:

1,

CREATE TABLE t1 (

a1 BLOB COLUMN_FORMAT COMPRESSED,

a2 BLOB COLUMN_FORMAT COMPRESSED,

a3 BLOB COLUMN_FORMAT COMPRESSED,

a4 BLOB COLUMN_FORMAT COMPRESSED,

a5 BLOB COLUMN_FORMAT COMPRESSED,

a6 BLOB COLUMN_FORMAT COMPRESSED,

a7 BLOB COLUMN_FORMAT COMPRESSED,

a8 BLOB COLUMN_FORMAT COMPRESSED,

a9 BLOB COLUMN_FORMAT COMPRESSED,

a10 BLOB);

2,

DROP PROCEDURE IF EXISTS save_data;

DELIMITER $$

CREATE PROCEDURE save_data()

BEGIN

  DECLARE i INT DEFAULT 1;

  WHILE I<=600000 DO

INSERT INTO t1 values(REPEAT('a', 10000), REPEAT('a', 10000),REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000), REPEAT('a', 10000));

    SET i = i+1;

  END WHILE;

END

$$

delimiter ;

CALL save_data();

(This takes quite a long time)

 

3,

ALTER TABLE t1 MODIFY a10 BLOB COLUMN_FORMAT COMPRESSED;

 

I got 30G memory. And this sql eat all of them.

Root cause:

Alter column_format sql goes to copy ddl. For write prebuilt, every copy write will allocate memory from prebuilt->compress_heap in row_compress_column func.

buf = static_cast<byte *>(mem_heap_zalloc(*compress_heap, buf_len));

And this heap is released at the end of the this statement. In my alter case, millions of column is compressed and tons of memory is allocated. It is easy to observe the memory is consumed by mysql server.

 

Solution: 

@@ -1031,6 +1032,9 @@ static void row_mysql_convert_row_to_innobase(
   ut_ad(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
   ut_ad(prebuilt->mysql_template);

+  if (prebuilt->compress_heap)

{ +    row_mysql_prebuilt_free_compress_heap(prebuilt); +  }

It seems free prebuilt->compress_heap before compress a row is a proper way to solve this issue.

Environment

Based on Jun 30 2023 branch 8.0 commit 696f9f5f06.

Attachments

10
  • 16 Nov 2023, 03:17 PM
  • 16 Nov 2023, 03:15 PM
  • 15 Nov 2023, 08:28 PM
  • 15 Nov 2023, 08:23 PM
  • 10 Oct 2023, 05:33 AM
  • 10 Oct 2023, 05:33 AM
  • 10 Oct 2023, 05:33 AM
  • 16 Aug 2023, 01:49 AM
  • 16 Aug 2023, 01:48 AM
  • 16 Aug 2023, 01:48 AM

Activity

Show:

Kamil Holubicki November 16, 2023 at 3:18 PM

8.0 PR: https://github.com/percona/percona-server/pull/5160

8.0 before fix:

8.0 after fix:

Kamil Holubicki November 15, 2023 at 8:41 PM

5.7 PR https://github.com/percona/percona-server/pull/5159

5.7 Before fix:

5.7 After fix:

Aaditya Dubey October 10, 2023 at 5:33 AM

Hi ,

Thank you for the report and code fix.
Verified as described.

PS Server : 8.0.34,8.0.33 mysql [localhost:8035] {msandbox} (test) > show tables; +----------------+ | Tables_in_test | +----------------+ | documents      | | t1             | +----------------+ 2 rows in set (0.00 sec) mysql [localhost:8035] {msandbox} (test) > select count(*) from t1; +----------+ | count(*) | +----------+ |   600000 | +----------+ 1 row in set (4.06 sec) mysql [localhost:8035] {msandbox} (test) > ALTER TABLE t1 MODIFY a10 BLOB COLUMN_FORMAT COMPRESSED;                                                                                                                                                           ERROR 2013 (HY000): Lost connection to MySQL server during query No connection. Trying to reconnect... ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql_sandbox8035.sock' (111) ERROR:  Can't connect to the server mysql [not_connected:8035] {msandbox} (test) >  mysql [not_connected:8035] {msandbox} (test) >  mysql [not_connected:8035] {msandbox} (test) >  mysql [not_connected:8035] {msandbox} (test) >  mysql [not_connected:8035] {msandbox} (test) > show tabes; No connection. Trying to reconnect... Connection id:    8 Current database: test Oct 10 05:23:01 localhost kernel: [ 1438.286192] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-3.scope,task=mysqld,pid=8628,uid=1000 Oct 10 05:23:01 localhost kernel: [ 1438.286704] Out of memory: Killed process 8628 (mysqld) total-vm:13651852kB, anon-rss:9708988kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:26168kB oom_score_adj:0 Oct 10 05:23:02 localhost containerd[727]: time="2023-10-10T05:22:48.676195599Z" level=error msg="get state for 40ff7d19597db3acfe00d9382c36fba46918571b012f1842467562c895f1067a" error="context deadline exceeded: unknown"

Sending the concern to engineering for further review and updates. Also CPU gets spike too so this also should be checked.

Done

Details

Assignee

Reporter

Needs Review

Yes

Needs QA

Yes

Priority

Smart Checklist

Created August 16, 2023 at 1:46 AM
Updated March 6, 2024 at 9:35 AM
Resolved December 4, 2023 at 9:28 AM

Flag notifications