Maintaining your Tuwunel setup
Moderation
Tuwunel has moderation through admin room commands. “binary commands” (medium priority) and an admin API (low priority) is planned. Some moderation-related config options are available in the example config such as “global ACLs” and blocking media requests to certain servers. See the example config for the moderation config options under the “Moderation / Privacy / Security” section.
Tuwunel has moderation admin commands for:
- managing room aliases (
!admin rooms alias) - managing room directory (
!admin rooms directory) - managing room banning/blocking and user removal (
!admin rooms moderation) - managing user accounts (
!admin users) - fetching
/.well-known/matrix/supportfrom servers (!admin federation) - blocking incoming federation for certain rooms (not the same as room banning)
(
!admin federation) - deleting media (see the media section)
Any commands with -list in them will require a codeblock in the message with
each object being newline delimited. An example of doing this is:
!admin rooms moderation ban-list-of-rooms
```
!roomid1:server.name
#badroomalias1:server.name
!roomid2:server.name
!roomid3:server.name
#badroomalias2:server.name
```
Database (RocksDB)
Generally there is very little you need to do. Compaction is ran automatically based on various defined thresholds tuned for Tuwunel to be high performance with the least I/O amplifcation or overhead. Manually running compaction is not recommended, or compaction via a timer, due to creating unnecessary I/O amplification. RocksDB is built with io_uring support via liburing for improved read performance.
RocksDB troubleshooting can be found in the RocksDB section of troubleshooting.
Compression
Some RocksDB settings can be adjusted such as the compression method chosen. See the RocksDB section in the example config.
btrfs users have reported that database compression does not need to be disabled
on Tuwunel as the filesystem already does not attempt to compress. This can be
validated by using filefrag -v on a .SST file in your database, and ensure
the physical_offset matches (no filesystem compression). It is very important
to ensure no additional filesystem compression takes place as this can render
unbuffered Direct IO inoperable, significantly slowing down read and write
performance. See https://btrfs.readthedocs.io/en/latest/Compression.html#compatibility
Important
Compression is done using the COW mechanism so it’s incompatible with nodatacow. Direct IO read works on compressed files but will fall back to buffered writes and leads to no compression even if force compression is set. Currently nodatasum and compression don’t work together.
btrfs
btrfs is Copy-on-Write, which interacts badly with the way RocksDB allocates
its write-ahead logs. Set rocksdb_allow_fallocate = false in tuwunel.toml.
Preallocation cannot reserve in-place write space on a CoW filesystem anyway,
so there is nothing to lose by turning it off there. Tuwunel warns at startup
when database_path is on btrfs and the option is still enabled.
RocksDB preallocates each WAL with fallocate(2), writes to it, then truncates
it to the written length on close. btrfs does not split the preallocated extent
on truncation: for as long as the file references any part of it, the whole
extent stays allocated. A WAL holding a few kilobytes of records can pin tens
of megabytes of disk this way.
Obsolete WALs compound it. They are moved to database_path/archive and reaped
only once the archive passes 1 GB, which RocksDB measures from the length of
the files rather than the space they occupy. Truncated WALs therefore sit there
far longer than their real cost warrants, and they accumulate quickly on a
server taking live traffic.
The gap between those two numbers is what makes this hard to recognize. du
reports the small one; only df or btrfs filesystem usage shows the disk
filling. compsize reports both for a directory. Defragmenting does not give
the space back, so the files have to be rewritten or removed: setting the
option stops any further growth, and an offline copy of database_path (see
Offline backups) reclaims what has already
accumulated.
ZFS
ZFS has several quirks that interact badly with RocksDB defaults. Apply both the Tuwunel config changes and the dataset properties below.
In tuwunel.toml:
rocksdb_direct_io = false. OpenZFS prior to 2.3 silently ignoredO_DIRECTand fell back to buffered. OpenZFS 2.3+ honorsO_DIRECTonly when requests are page-aligned and a multiple of the recordsize, which RocksDB cannot guarantee.rocksdb_allow_fallocate = false. OpenZFS does not implementfallocate(2)preallocation; onlyFALLOC_FL_PUNCH_HOLEandFALLOC_FL_ZERO_RANGEare supported. Tuwunel warns at startup while this is left enabled on ZFS.- Leave
rocksdb_optimize_for_spinning_disks = falseon NVMe or SSD pools, even when running on ZFS.
On the dataset hosting database_path:
| Property | Value | Reason |
|---|---|---|
recordsize | 128K (or 64K) | Match RocksDB’s working set. 16K causes severe write amplification on compaction. |
primarycache | metadata | Tuwunel’s block cache already serves data; ARC caching of data duplicates RAM. |
compression | off | RocksDB SSTs are already zstd-compressed by Tuwunel. |
atime | off | Avoid an FS write per read. |
logbias | throughput | Route ZIL through the normal txg path, which suits append-only WAL traffic. |
recordsize takes effect only on files written after the property is
changed. After adjusting it, dump the database (offline copy out, wipe the
dataset, copy back) so existing SSTs adopt the new recordsize. Without a
dump-and-reload, compaction will gradually rewrite into the new recordsize
over weeks; pre-existing files keep the old size in the meantime.
For sync write latency, in order of preference: a separate SLOG vdev, then
logbias=throughput, then sync=disabled (only if you accept that a host
crash may discard the WAL tail; Tuwunel recovers cleanly from this via
rocksdb_recovery_mode=1, the default).
Files in database
Do not touch any of the files in the database directory. This must be said due
to users being mislead by the .log files in the RocksDB directory, thinking
they’re server logs or database logs, however they are critical RocksDB files
related to WAL tracking.
The only safe files that can be deleted are the LOG files (all caps). These
are the real RocksDB telemetry/log files, however Tuwunel has already
configured to only store up to 3 RocksDB LOG files due to generally being
useless for average users unless troubleshooting something low-level. If you
would like to store nearly none at all, see the rocksdb_max_log_files
config option.
Integrity checks
Use the !admin integrity commands in the admin room to check your database
for problems. The checks do not change the database.
- Run
!admin integrity listto see every check and what it verifies. - Run
!admin integrity checkto run every check available on the open database. To run only certain checks, add their names after the command. Add--limit Nto show up toNfindings from each check (8by default).
A check reports clean when it finds no problems. Otherwise, it reports
the number of findings and a sample, or failed with the error.
Checks marked (read-only open) compare data across database columns.
Writes during a check could look like defects, so these checks run only
when the database is opened read-only. On a writable database,
!admin integrity check skips them and lists them at the end. If you
request one by name, it reports that it needs a read-only open.
Checking with the server stopped
To run the (read-only open) checks, stop the server and open its database
read-only for the check.
Warning
Stop the server before opening its database read-only. RocksDB documents a read-only open beside a running server as undefined behavior, and Tuwunel does not refuse one.
Before running the commands below, check your Tuwunel configuration file.
An explicit setting takes precedence over --read-only. For example,
read_only = false under [global.rocksdb] keeps the database writable.
In that case, the read-only open checks are reported as skipped.
For a systemd installation, run the following commands on the server host.
The example uses the tuwunel service and user, and the configuration file
/etc/tuwunel/tuwunel.toml. Adjust these to match your installation.
systemctl stop tuwunel
sudo -u tuwunel tuwunel --config /etc/tuwunel/tuwunel.toml --read-only \
-O database_migrations=false --execute "integrity check" \
--execute "server shutdown"
systemctl start tuwunel
The temporary process prints the findings, then
--execute "server shutdown" shuts it down. The last command starts the
normal service again. The --read-only option opens the database read-only,
subject to the configuration override above. The
-O database_migrations=false option skips startup migrations, which write
to the database.
If startup reports that the required local state memo invalidation has not
run, start once with database_migrations enabled before trying again.
Scheduling a repair
To schedule a repair, run
!admin integrity repair NAME --yes-i-know-what-im-doing in the admin room.
Replace NAME with one of the supported check names below.
pdu-room-idshighlight-keysrelation-indexthread-summaries(also rebuilds the thread activity index)thread-activity
The repair runs on the next start with database_migrations enabled,
before the server begins serving. The command refuses to schedule a repair
without the confirmation flag, on a database it cannot write, or for a
check whose repair step is not safe to run twice. It gives the reason
when it refuses.
Backups
Database backup, checkpoint, and restore procedures are documented on the Backups page.
Media
Media still needs various work, however Tuwunel implements media deletion via:
- MXC URI or Event ID (unencrypted and attempts to find the MXC URI in the event)
- Delete list of MXC URIs
- Delete remote media in the past
Nseconds/minutes via filesystem metadata on the file created time (btime) or file modified time (mtime)
See the !admin media command for further information. All media in Tuwunel
is stored at $DATABASE_DIR/media. This will be configurable soon.
If you are finding yourself needing extensive granular control over media, we recommend looking into Matrix Media Repo. Tuwunel intends to implement various utilities for media, but MMR is dedicated to extensive media management.
Built-in S3 support is also planned, but for now using a “S3 filesystem” on
media/ works. Tuwunel also sends a Cache-Control header of 1 year and
immutable for all media requests (download and thumbnail) to reduce unnecessary
media requests from browsers, reduce bandwidth usage, and reduce load.