Page MenuHomePhabricator

Compress data on cxc_corpora table in production
Closed, ResolvedPublic2 Estimated Story Points

Event Timeline

Nikerabbit triaged this task as Medium priority.Jul 10 2025, 6:15 AM
Nikerabbit moved this task from Needs Triage to Operational issues on the ContentTranslation board.

Suggestion given by @Ladsgroup

https://phabricator.wikimedia.org/T399083#11039284
slow it down with --sleep and add 1s between in each batch, put it in mwscript-k8s and let it run it for a day or a week.

https://phabricator.wikimedia.org/T399083#11039355
make sure you don't hit --follow and if you do, put it on a screen

abi_ moved this task from Ready for dev to In Progress on the LPL Essential (2025 Jul-Oct) board.
abi_ set the point value for this task to 2.

I've started running the script:

mwscript-k8s --comment="Run compress-corpora-content.php with 1s sleep (T399084)" -- extensions/ContentTranslation/scripts/compress-corpora-content.php --wiki=enwiki --sleep=1 --really
⏳ Starting extensions/ContentTranslation/scripts/compress-corpora-content.php on Kubernetes as job mw-script.eqiad.32o8x99h ...
👋 Refreshing the local Helm cache...
🚀 Job is running. For streaming logs, run:
K8S_CLUSTER=eqiad KUBECONFIG=/etc/kubernetes/mw-script-restricted-eqiad.config kubectl logs -f job/mw-script.eqiad.32o8x99h mediawiki-32o8x99h-app

Progress report:

Batch completed. Processed: 5,816,700, Compressed: 4,493,896 records so far
Last processed ID: 7102190

Total records: 83,657,300

Awesome! I think it's fine to take long. It's better than causing major issues to the database. I'd assume it'd take around 20 days? That's fine from my side.

Progress report:

Batch completed. Processed: 12,759,200, Compressed: 9785652 records so far
Last processed ID: 15540811

Awesome! I think it's fine to take long. It's better than causing major issues to the database. I'd assume it'd take around 20 days? That's fine from my side.

Should take <15 days as per my calculations.

Update:

Batch completed. Processed: 18,219,200, Compressed: 13558940 records so far
Last processed ID: 22375440

Total records: 83,657,300

Update:

Batch completed. Processed: 32,388,000, Compressed: 24571731 records so far
Last processed ID: 40527216

Noting that we got an alert for size of x1 in total increasing by 20% in just one week. The biggest increase in size is actually this table:

1root@db1217[dbbackups]> SELECT A.file_path, A.file_name, A.size AS size_job_1, B.size AS size_job_2, ABS(CONVERT(B.size, SIGNED) - CONVERT(A.size, SIGNED)) AS difference FROM backup_files A JOIN backup_files B ON A.file_path = B.file_path AND A.file_name = B.file_name WHERE A.backup_id = 35830 AND B.backup_id = 35942 ORDER BY ABS(CONVERT(B.size, SIGNED) - CONVERT(A.size, SIGNED)) DESC;
2+-----------+-----------------------------------------------------------------------+-------------+-------------+-------------+
3| file_path | file_name | size_job_1 | size_job_2 | difference |
4+-----------+-----------------------------------------------------------------------+-------------+-------------+-------------+
5| | wikishared.cx_corpora.00001.sql.gz | 28378714254 | 15496564937 | 12882149317 |
6| | wikishared.cx_corpora.00000.sql.gz | 20778934815 | 12614223920 | 8164710895 |
7| | commonswiki.globaljsonlinks.00001.sql.gz | 45533755 | 909974218 | 864440463 |
8| | commonswiki.globaljsonlinks.00000.sql.gz | 1131925497 | 280250168 | 851675329 |
9| | dewiki.growthexperiments_link_recommendations.sql.gz | 62802984 | 87134626 | 24331642 |
10| | enwiki.growthexperiments_link_recommendations.sql.gz | 78216708 | 102149394 | 23932686 |
11| | commonswiki.mediamoderation_scan.sql.gz | 2700859969 | 2712581570 | 11721601 |
12| | itwiki.growthexperiments_link_recommendations.sql.gz | 43541286 | 54582176 | 11040890 |
13| | enwiki.echo_event.00002.sql.gz | 1950198681 | 1958782695 | 8584014 |
14| | ruwiki.growthexperiments_link_recommendations.sql.gz | 155162137 | 161726574 | 6564437 |
15| | commonswiki.globaljsonlinks.00002.sql.gz | 7666771 | 11281704 | 3614933 |
16| | nlwiki.growthexperiments_link_recommendations.sql.gz | 18687051 | 21674627 | 2987576 |
17| | commonswiki.globaljsonlinks.00004.sql.gz | 2619507 | 289396 | 2330111 |
18| | wikishared.reading_list_entry.00001.sql.gz | 654906178 | 657170077 | 2263899 |
19| | commonswiki.echo_event.sql.gz | 910131665 | 912387526 | 2255861 |
20| | wikishared.reading_list_entry.00000.sql.gz | 653530858 | 655710558 | 2179700 |
21| | ptwiki.growthexperiments_link_recommendations.sql.gz | 62828348 | 64558531 | 1730183 |
22| | frwiki.growthexperiments_link_recommendations.sql.gz | 128920724 | 127395863 | 1524861 |
23| | frwiki.echo_event.sql.gz | 552606138 | 554033225 | 1427087 |
24| | dewiki.echo_event.sql.gz | 599819554 | 601227687 | 1408133 |
25| | enwiki.echo_notification.00001.sql.gz | 683712757 | 684987721 | 1274964 |
26| | wikishared.loginnotify_seen_net.sql.gz | 55135412 | 53896620 | 1238792 |
27| | enwiki.growthexperiments_user_impact.sql.gz | 81049532 | 82261730 | 1212198 |
28| | commonswiki.globaljsonlinks.00005.sql.gz | 2204142 | 3416138 | 1211996 |
29

Maybe we are not deleting the old rows? or it's an in-place update?

Update:

Batch completed. Processed: 56,871,400, Compressed: 43,345,672 records so far
Last processed ID: 71,968,298

Total records: 83,874,264

Noting that we got an alert for size of x1 in total increasing by 20% in just one week. The biggest increase in size is actually this table:

Maybe we are not deleting the old rows? or it's an in-place update?

It's an in-place update. The number of rows haven't increased a lot so the size increase doesn't make sense.

I think I know why it exploded, mariadb is double compressing it on storage[1]. I will fix it while optimizing it. It should reduce the size.

[1] You might ask if mariadb is compressing it, why are we compressing it on the application layer: 1- It is not compressed on memory (where we are the most limited) 2- It is not compressed over network 3- It has a lot of limitations (https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-row-formats/innodb-compressed-row-format)

cumin2024@db2186.codfw.wmnet[wikishared]> show create table cx_corpora
    -> ;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
| Table      | Create Table                                                                                                                                                                                                     >
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
| cx_corpora | CREATE TABLE `cx_corpora` (
  `cxc_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cxc_translation_id` int(11) NOT NULL,
  `cxc_section_id` varbinary(30) NOT NULL,
  `cxc_origin` varbinary(30) NOT NULL,
  `cxc_sequence_id` int(11) DEFAULT NULL,
  `cxc_timestamp` binary(14) DEFAULT NULL,
  `cxc_content` mediumblob DEFAULT NULL,
  PRIMARY KEY (`cxc_id`),
  UNIQUE KEY `cx_corpora_unique` (`cxc_translation_id`,`cxc_origin`,`cxc_section_id`,`cxc_timestamp`)
) ENGINE=InnoDB AUTO_INCREMENT=103260610 DEFAULT CHARSET=binary ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
1 row in set (0.031 sec)

The script is complete.

[101043783] Compressed: 12026 -> 2431 bytes (79.79% reduction)
[101043785] Skipped: compression does not reduce size
Batch completed. Processed: 80881969, Compressed: 60014055 records so far
Last processed ID: 101043785

Completed processing. Processed: 80881969, Compressed: 60014055 records (240.56 GB saved)

Thanks. I run the optimize table now.

Nikerabbit changed the task status from Open to Stalled.Sep 1 2025, 8:40 AM

So far, result of T403362

50GB removed

root@db1179:/srv/sqldata/wikishared# ls -Ssh | head
total 152G
131G cx_corpora.ibd
 12G reading_list_entry.ibd

https://grafana.wikimedia.org/d/000000377/host-overview?orgId=1&refresh=5m&var-server=db1179&var-datasource=000000026&var-cluster=mysql&viewPanel=panel-28&from=2025-09-01T07:29:23.021Z&to=2025-09-01T10:09:02.754Z&timezone=utc

decent amount of storage saved and this considering that it was already compressed on disk.

Nikerabbit moved this task from Need QA to Done on the LPL Essential (2025 Jul-Oct) board.

I'll assume that means we're good... for now.