Blocks · Databases

db/mariadb

MariaDB on a replicated volume. One MariaDB server on a replicated volume behind a VIP; every acknowledged commit survives a failover.

Overview

Runs one mariadbd whose whole data directory is on a replicated volume. The block is a singleton that runs where the volume's primary is, behind a stable VIP. DRBD replicates synchronously, so MariaDB's own replication and Galera are not used. InnoDB syncs its redo log on every commit and keeps the doublewrite buffer on, so every commit a client sees acknowledged survives the crash that a failover is.

Compare db/postgres, which replicates with PostgreSQL's own streaming replication across one volume per replica.

Shape
Singleton on a replicated volume
Reached at
VIP
Node package
pkgs.mariadb

Fetched on demand: the first time a block of this type is placed on a node, its agent fetches pkgs.mariadb, built from the node's own nixpkgs so the NixOS binary cache serves it. That first placement needs network access (or a binary cache on the LAN) and waits for the download; later placements on that node start at once.

Example

mariadb.yaml
apiVersion: expanse.io/v1
kind: Block
metadata:
  name: appdb
  namespace: default
spec:
  type: db/mariadb
  replicas: 1
  strategy:
    kind: SINGLETON
  resources:
    requests:
      cpu: 500m
      memory: 1Gi
  storage:
    - name: appdb-data
      size: 50Gi
      replication: 3
      mountPath: /var/lib/mariadb
  config:
    port: 13306          # never 3306: the VIP holder binds that
    rootPassword: change-me-root
    database: app
    user: app
    password: change-me-app
    bufferPool: 512M
  network:
    ports:
      - name: mysql
        port: 3306
        target_port: 13306
        protocol: tcp
        expose: EXPOSE_VIP
    health_check:
      readiness:
        type: PROBE_TCP
        port: 13306
        period_seconds: 2
$ expanse ctl block apply -f mariadb.yaml --dry-run   # validate only
$ expanse ctl block apply -f mariadb.yaml

Configuration

Keys go under spec.config and are checked against the type's JSON Schema when the block is applied. A default is what the block uses when the key is unset.

KeyDefaultMeaning
rootPasswordrequiredPassword for root@localhost and root@'%', at least 8 characters; applied on every start. Sealed: kept out of the stored block (block secrets).
databasenoneDatabase created on start if it is missing.
usernoneApplication account with all privileges on database; needs password and database.
passwordnonePassword for user; applied on every start. Sealed: kept out of the stored block (block secrets).
bufferPool128Minnodb_buffer_pool_size; keep it inside the memory request.
maxConnections151max_connections.
port13306mariadbd's listen port, the target_port of 3306.

Using it

$ mariadb -h <VIP> -P 3306 -u app -p app

A Go DSN: app:<password>@tcp(<VIP>:3306)/app. Changing rootPassword or password and redeploying rotates them. The block deletes every other root account and every anonymous account on each start.

Connections are not encrypted and root@'%' can log in from anywhere that reaches the VIP, so keep the VIP on a network you trust and choose a strong rootPassword.

When a node fails

When the serving node dies, the block, its volume's primary and its VIP move together to a survivor, and InnoDB runs crash recovery on the same data. Open connections break and in-flight transactions roll back; a transaction whose COMMIT returned is on the volume. When a connection drops before COMMIT returns, the transaction may or may not have committed, so retries must be idempotent. In Expanse's VM test the VIP was on a survivor 53 s after the serving node was killed.

Limits

  • No TLS, and one application account and database.
  • No read replicas: one block is one mariadbd, replicated by DRBD.
  • Backups: a crash-consistent volume snapshot is a valid restore point (see util/restic-backup); for logical dumps run mariadb-dump against the VIP.

Source

All block types · Fields every block shares