Skip to content

Conversation

@beautifulentropy
Copy link
Member

@beautifulentropy beautifulentropy commented Nov 18, 2025

Today, timestamp truncation happens for queries using *borp.DbMap but not *borp.Transaction. That means comparisons still see sub-seconds, but inserts into MariaDB DATETIME columns silently truncate them to whole seconds.

On MySQL 8, the same queries will still include sub-seconds, but inserts into DATETIME columns will round to the nearest second instead of truncate. This leads to issues for queries like the one in *StorageAuthority.UpdateCRLShard(). When two CRL updaters write within the same second one may be rounded up to the next second. When the other updater attempts its own UPDATE .. WHERE thisUpdate <= ?, the condition fails because the stored timestamp now appears to be in the future.

Ahead of the transition from ProxySQL + MariaDB to Vitess + MySQL 8 in #8468, update borp (letsencrypt/borp#12) to expose Transaction arguments to the BoulderTypeConverter, allowing it to truncate all timestamps passed through Transactions and keep behavior consistent across *borp.DbMap and *borp.Transaction, as well as MariaDB and MySQL 8.

Part of #7736


Example of truncation vs rounding behavior in MariaDB and MySQL 8, respectively:

MariaDB> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.004 sec)

MariaDB> CREATE TABLE t1 (
    ->   id INT AUTO_INCREMENT PRIMARY KEY,
    ->   ts DATETIME(0)
    -> );
Query OK, 0 rows affected (0.003 sec)

MariaDB> INSERT INTO t1 (ts) VALUES
    ->   (‘2025-01-01 12:00:00.001’),
    ->   (‘2025-01-01 12:00:00.499’),
    ->   (‘2025-01-01 12:00:00.500’),
    ->   (‘2025-01-01 12:00:00.501’),
    ->   (‘2025-01-01 12:00:00.900’);
Query OK, 5 rows affected (0.000 sec)
Records: 5  Duplicates: 0  Warnings: 0

MariaDB> SELECT id, ts FROM t1 ORDER BY id;
+----+---------------------+
| id | ts                  |
+----+---------------------+
|  1 | 2025-01-01 12:00:00 |
|  2 | 2025-01-01 12:00:00 |
|  3 | 2025-01-01 12:00:00 |
|  4 | 2025-01-01 12:00:00 |
|  5 | 2025-01-01 12:00:00 |
+----+---------------------+
5 rows in set (0.001 sec)
mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> CREATE TABLE t1 (
    ->   id INT AUTO_INCREMENT PRIMARY KEY,
    ->   ts DATETIME(0)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 (ts) VALUES
    ->   (‘2025-01-01 12:00:00.001’),
    ->   (‘2025-01-01 12:00:00.499’),
    ->   (‘2025-01-01 12:00:00.500’),
    ->   (‘2025-01-01 12:00:00.501’),
    ->   (‘2025-01-01 12:00:00.900’);
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT id, ts FROM t1 ORDER BY id;
+----+---------------------+
| id | ts                  |
+----+---------------------+
|  1 | 2025-01-01 12:00:00 |
|  2 | 2025-01-01 12:00:00 |
|  3 | 2025-01-01 12:00:01 |
|  4 | 2025-01-01 12:00:01 |
|  5 | 2025-01-01 12:00:01 |
+----+---------------------+
5 rows in set (0.00 sec)

@beautifulentropy beautifulentropy merged commit 1f6ec8c into main Nov 19, 2025
20 of 22 checks passed
@beautifulentropy beautifulentropy deleted the upgrade-borp branch November 19, 2025 14:59
npurtova pushed a commit to plesk/boulder that referenced this pull request Nov 25, 2025
…erter (letsencrypt#8494)

Today, timestamp truncation happens for queries using `*borp.DbMap` but
not `*borp.Transaction`. That means comparisons still see sub-seconds,
but inserts into MariaDB `DATETIME` columns silently truncate them to
whole seconds.

On MySQL 8, the same queries will still include sub-seconds, but inserts
into `DATETIME` columns will round to the nearest second instead of
truncate. This leads to issues for queries like the one in
`*StorageAuthority.UpdateCRLShard()`. When two CRL updaters write within
the same second one may be rounded up to the next second. When the other
updater attempts its own `UPDATE .. WHERE thisUpdate <= ?`, the
condition fails because the stored timestamp now appears to be in the
future.

Ahead of the transition from ProxySQL + MariaDB to Vitess + MySQL 8 in
letsencrypt#8468, update borp (letsencrypt/borp#12) to
expose Transaction arguments to the BoulderTypeConverter, allowing it to
truncate all timestamps passed through Transactions and keep behavior
consistent across `*borp.DbMap` and `*borp.Transaction`, as well as
MariaDB and MySQL 8.

Part of letsencrypt#7736
aarongable pushed a commit that referenced this pull request Dec 8, 2025
The original plan for getting the Vitess infrastructure running was to
use
[vttestserver](https://vitess.io/docs/22.0/reference/programs/vttestserver)
as a starting point to reach a minimum viable setup. However,
vttestserver didn’t work out because some of its defaults conflicted
with how we clean up rows and the level of resources (threads) we need.

Fortunately, vttestserver is just a wrapper around
[vtcombo](https://vitess.io/docs/21.0/reference/programs/vtcombo) that
generates a [vttest
protobuf](https://github.com/vitessio/vitess/blob/v22.0.1/proto/vttest.proto)
describing the configuration for an in-memory topology server started by
vtcombo, encoded in JSON. By modifying vttestserver’s
[run.sh](https://github.com/vitessio/vitess/blob/v22.0.1/docker/vttestserver/run.sh),
we're able to interact with vtcombo directly, passing the JSON
configuration along with other vttestserver defaults reverse-engineered
from run.sh and
[vtprocess.go](https://github.com/vitessio/vitess/blob/v22.0.1/go/vt/vttest/vtprocess.go).

Vitess doesn’t provide a `vtcombo` image, we must build our own. Build
and upload a [boulder-vtcomboserver
image](https://hub.docker.com/repository/docker/letsencrypt/boulder-vtcomboserver)
on top of Docker's official MySQL 8.4 image, which provides native arm64
support. The accompanying tag-and-upload shell script defaults to amd64
for CI.

As an aside, Vitess’s official Dockerfiles are only published for amd64,
and modifying them to build for arm64 would prove difficult because
Oracle doesn’t publish MySQL arm64 binaries in its [Debian apt
repository](https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community).

With boulder-vtcomboserver up and running I was able to find/validate
the following issues and provide workarounds:

- **Problem:** db-migrate, the tool we use to apply database migrations,
must be configured to talk to MariaDB and to MySQL through Vitess
(vtgate + vttablet).
**Solution:** Create two new dbconfig YAML files (mariadb and vitess)
and use `test/entrypoint.sh` to set the appropriate file for
`sql-migrate` (`test/create_db.sh`) to use. Also, symlink each of these
two new files from db to db-next just like the old dbconfig.yml file.

- **Problem:** Vitess does not allow database `CREATE` statements and
any DDL containing them will be rejected by vtgate.
**Solution:** These databases are already created by vtcombo since
they’re defined as KEYSPACES. Skip database creation in
`test/create_db.sh`.

- **Problem:** Vitess does not allow user creation or grants (`CREATE
USER`, `GRANT`), and any DDL containing these commands will be blocked
by vtgate.
**Solution:** Skip user creation and grant steps in `test/create_db.sh`.
Set `%` for `--vschema_ddl_authorized_users` as vttestserver does, and
revisit this later for a more complete approach.

- **Problem:** vttablet default for maximum number of rows returned from
a (non-streaming) query (10,000) is too low for Boulder’s needs, causing
queries to fail due to vttablet rejecting them.
**Solution:** Increase `--queryserver-config-max-result-size` to
1,000,000 and `--queryserver-config-warn-result-size` to 1,000,000.

- **Problem:** vttablet default for connection pool size (16) and
maximum number of concurrent transactions (20) are too low for Boulder’s
needs, causing queries to fail due to vttablet being overloaded.
**Solution:** Increase `--queryserver-config-pool-size` to 64 and
`--queryserver-config-transaction-cap` to 80.
  
- **Problem:** Vitess does not allow `TRIGGER` statements and any DDL
containing them will be rejected by vtgate. Without TRIGGER statements
TestIssuanceCertStorageFailed, an integration test, will fail.
**Soluton:** Run these TRIGGER statements in an entrypoint
scripttest/vtcomboserver/install_trigger.sh, bypassing vtgate entirely.

Depends on #8479
Depends on #8489
Depends on #8490
Depends on #8494
Fixes #7736
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants