Page MenuHomePhabricator

Produnto schema
Closed, ResolvedPublic

Description

Schema for Scribunto/Git integration.

All tables are shared.

CREATE TABLE `produnto_active_deployment` (
  `pad_wiki` VARBINARY(255) NOT NULL,
  `pad_deployment` INTEGER UNSIGNED NOT NULL,
  PRIMARY KEY(`pad_wiki`)
);

CREATE TABLE `produnto_deployment` (
  `pd_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  -- The wiki ID of the deployment target
  `pd_target_wiki` VARBINARY(255) NOT NULL,
  -- The wiki ID of the JSON page controlling the deployment
  `pd_control_wiki` VARBINARY(255) NOT NULL,
  -- The rev_id of the JSON page which is controlling this deployment
  `pd_control_rev_id` INTEGER UNSIGNED NOT NULL,
  -- For determining the replacement timestamp during purging
  INDEX (`pd_target_wiki`, `pd_id`),
  PRIMARY KEY(`pd_id`)
);

CREATE TABLE `produnto_deployment_data` (
  `pdd_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  -- Link to produnto_deployment.pd_id
  `pdd_deployment` INTEGER UNSIGNED NOT NULL,
  -- The name of the deployment data, e.g. "scribunto"
  `pdd_name` VARBINARY(255) NOT NULL,
  `pdd_text` LONGBLOB NOT NULL,
  UNIQUE INDEX (`pdd_deployment`, `pdd_name`),
  PRIMARY KEY(`pdd_id`)
);

CREATE TABLE `produnto_package_deployment` (
  -- Link to produnto_deployment.pd_id
  `ppd_deployment` INTEGER UNSIGNED NOT NULL,
  -- Link to produnto_package_version.ppv_id
  `ppd_package_version` INTEGER UNSIGNED NOT NULL,
  UNIQUE INDEX (`ppd_deployment`, `ppd_package_version`),
  -- For purging - find deployments that keep a version alive
  INDEX (`ppd_package_version`)
);

CREATE TABLE `produnto_package_version` (
  `ppv_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  -- Link to produnto_package.pp_id
  `ppv_package` INTEGER UNSIGNED NOT NULL,
  `ppv_version` VARBINARY(255) NOT NULL,
  -- PHP const: 1=fetching, 2=ready
  `ppv_state` TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY(`ppv_id`),
  -- To deduplicate fetch requests
  UNIQUE INDEX (`ppv_package`,`ppv_version`)
);

CREATE TABLE `produnto_package` (
  `pp_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `pp_name` VARBINARY(255) NOT NULL,
  `pp_url` BLOB NOT NULL,
  PRIMARY KEY(`pp_id`),
  INDEX(`pp_name`)
);

CREATE TABLE `produnto_file` (
  `pf_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  -- Link to produnto_package_version.ppv_id
  `pf_package_version` INTEGER UNSIGNED NOT NULL,
  -- Link to produnto_file_name.pfn_id
  `pf_name_id` INTEGER UNSIGNED NOT NULL,
  -- Link to produnto_file_text.pft_hash
  `pf_hash` BINARY(64) NOT NULL,
  PRIMARY KEY(`pf_id`),
  -- For loading files, and for purging the produnto_file_name table
  INDEX `produnto_file_name_package` (`pf_name_id`, `pf_package_version`),
  -- For purging the produnto_file_text table
  INDEX (`pf_hash`),
);

CREATE TABLE `produnto_file_name` (
  `pfn_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `pfn_name` VARBINARY(4095) NOT NULL,
  PRIMARY KEY(`pfn_id`),
  -- For insert deduplication, loading
  UNIQUE INDEX (`pfn_name`)
);

CREATE TABLE `produnto_file_text` (
  `pft_hash` BINARY(64) NOT NULL,
  `pft_text` LONGBLOB NOT NULL,
  PRIMARY KEY(`pft_hash`)
);

Sample queries

Load named file from currently deployed package (T412181)

SET @deployment = ( SELECT pad_deployment FROM produnto_active_deployment WHERE pad_id=1 );
SET @hash = ( SELECT pf_hash 
  FROM produnto_file
  JOIN produnto_file_name ON pfn_id=pf_name_id
  JOIN produnto_package_version ON ppv_id=pf_package
  JOIN produnto_package ON pp_id=ppv_package
  JOIN produnto_package_deployment ON ppd_package_version=ppv_id
  WHERE ppd_deployment=@deployment
    AND pp_name=@package
    AND pfn_name=@name );
SELECT pft_text WHERE pft_hash=@hash;

Ballpark size

Based on enwiki Module namespace

NameRowsRow lengthSize (MB)
produnto_active_deployment180
produnto_deployment100040
produnto_package_deployment100000088
produnto_package_version100000162
produnto_package10001000
produnto_file5000004421
produnto_file_name200001002
produnto_file_text5000005000025000 (~100 with purging, T412473)

Details

Related Changes in Gerrit:

Event Timeline

tstarling renamed this task from Packages schema to Produnto schema.Dec 12 2025, 1:14 AM
tstarling updated the task description. (Show Details)
tstarling updated the task description. (Show Details)

I haven't had time to review the proposed schema in depth (I'm in an offsite until next week) but to get the discussion starting, the number of tables per-wiki is still too many[1]. I wonder if the table with one row only can be merged into something else. I don't think these tables will grow much so I'd lean towards de-normalizing as much as possible.

[1] in s3, MariaDB process needs to open many many files because of combination of many wikis and many tables and each table creating two files. Adding three tables to every wiki adds around 6000 more files to be opened by the process which impacts the performance the database.

I haven't had time to review the proposed schema in depth (I'm in an offsite until next week) but to get the discussion starting, the number of tables per-wiki is still too many[1]. I wonder if the table with one row only can be merged into something else. I don't think these tables will grow much so I'd lean towards de-normalizing as much as possible.

[1] in s3, MariaDB process needs to open many many files because of combination of many wikis and many tables and each table creating two files. Adding three tables to every wiki adds around 6000 more files to be opened by the process which impacts the performance the database.

They can be in a virtual domain, they don't need to be in s3.

I've previously looked for information about how the open file count impacts performance, but I couldn't find anything. Have you done any tests or have you got a public source for this information? A lot of sources say that increasing the open file count risks exceeding the ulimit, which is obvious but is not a performance issue in itself, it's a configuration issue.

We could put the deployments in a shared table, with wiki ID columns.

So the problem with having many files (we used to have a lot more before Amir did some clean ups) doesn't automatically start degrading performance. However, there are indirect performance impacts that can appear once certain thresholds are crossed.
The most obvious one (as you mentioned) is the ulimit, that's not a performance issue per se, but it can essentially crash the server (I've seen this before, even during mysql start ups - not at WMF, but at a previous gig).
There are two flags that can cause issues (open_files_limit or table_open_cache), especially if InnoDB has to open/close ibd files.
In some cases, you can see extra latency due to metadata handling if there're multiple files opened at the same time (close to limits of course), this can lead to lots of mutex contention.

Regarding the startup or crash recoveries we already suffer slowness on upgrades - can take ages (hours) as mariadb needs to open/scan new files for tables discovery (this takes already quite lots of time on s3).

In the cloning process, having to send so many (generally) small files takes also lots of time, in fact, I believe s3 is now one of the sections that takes the longest, and not because of size, but because of files (2 per table).
Same happens with backups if I recall correctly, although I haven't checked lately if it is still the case.

In any case, if we can avoid adding more stuff to s3, that's generally a good thing.

OK, thanks @Marostegui.

It should simplify purging (T412473) if all tables are shared, since there is a need for global locking. You can check to make sure a package hasn't been touched recently before purging it, but ultimately you need a locked view of that condition.

I updated the schema to make all tables be shared, and also for the new purging algorithm at T412473.

Now that they are shared, LGTM.

We should consider how T178146: Add support for a newer Lua version than Lua 5.1 to luasandbox will affect the project, especially the proposed database schema.

I added produnto_deployment_data for storing a JSON file mapping the module name to package and file name. Scribunto builds this cache by parsing the package manifest, as described in T412181.

I extended the text field types from MEDIUMBLOB to LONGBLOB because the overhead of the extra length byte will be a small percentage of the table size. Limits can be implemented at the application level -- there's no good rationale for making the DB be the first thing to break when someone tries to make a large file.

Increased hash sizes from 32 to 64 bytes to accommodate SHA-256 in hexadecimal format.

As long as they are a shared table in x1 I have no objections.

Change #1229848 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/extensions/Produnto@master] SQL schema

https://gerrit.wikimedia.org/r/1229848

Change #1229848 merged by jenkins-bot:

[mediawiki/extensions/Produnto@master] SQL schema

https://gerrit.wikimedia.org/r/1229848

tstarling claimed this task.