Files
llmgw/internal/slurm/dbd.go
T
Ilker ManapandClaude Opus 5.5 748f777a56
CI / test (push) Successful in 10m57s
Slurm's accounting: slurmdbd and a MariaDB on the controller
Since 23.11 Slurm runs badly without accounting storage: the main
scheduler passes every job by as InvalidAccount. slurmdbd takes MySQL or
MariaDB only, so the controller's agent installs MariaDB beside it,
answering that machine alone, makes the database and its user (the
password made from the munge key, never on a command line), runs
slurmdbd and adds the cluster, all before slurmctld. A MariaDB that was
on the machine before keeps its settings. slurm.conf accounts the jobs
there, with what each used from its cgroup and the cards, and the
priority is multifactor again. Port 6819 joins Slurm's in the firewall.
ctl slurm status and the console say whether slurmdbd runs; the install
screen, server init --slurm and the guide say what is put where.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 07:59:08 +01:00

82 lines
2.6 KiB
Go

package slurm
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
// Accounting: slurmdbd on the controller, keeping the jobs' records in a
// MariaDB beside it that answers this machine alone. slurmdbd takes MySQL or
// MariaDB only, so it is not the cluster's PostgreSQL. Since 23.11 Slurm
// cannot run without it well: its main scheduler passes every job by as
// InvalidAccount, and backfill starts it a pass later.
const (
// DbdPort is slurmdbd's, which slurmctld and sacct reach.
DbdPort = 6819
// DbdConfPath is slurmdbd's file, readable by the slurm user alone: it
// holds the database's password.
DbdConfPath = ConfDir + "/slurmdbd.conf"
// AcctDB and AcctUser are the database and its user.
AcctDB = "slurm_acct_db"
AcctUser = "slurm"
)
// DbdPassword is the database user's password, made from the munge key:
// every controller the cluster has gets the same one, and nothing new is
// kept anywhere.
func DbdPassword(mungeKey []byte) string {
h := sha256.New()
h.Write([]byte("llmgw slurmdbd password\x00"))
h.Write(mungeKey)
return hex.EncodeToString(h.Sum(nil))[:40]
}
// DbdConf is slurmdbd.conf for the controller host, named as `hostname -s`
// says, which slurmdbd checks it runs on.
func DbdConf(host, password string) string {
return header + fmt.Sprintf(`AuthType=auth/munge
DbdHost=%s
DbdPort=%d
SlurmUser=slurm
LogFile=%s/slurmdbd.log
PidFile=/run/slurmdbd.pid
StorageType=accounting_storage/mysql
StorageHost=localhost
StorageUser=%s
StoragePass=%s
StorageLoc=%s
# Kept a year; older records are purged, a month at a time.
PurgeEventAfter=12months
PurgeJobAfter=12months
PurgeResvAfter=12months
PurgeStepAfter=12months
PurgeSuspendAfter=12months
PurgeTXNAfter=12months
PurgeUsageAfter=24months
`, host, DbdPort, LogDir, AcctUser, password, AcctDB)
}
// MariaDBConf is the database server's settings: this machine alone, and
// what Slurm's documentation asks of InnoDB.
const MariaDBConf = `# Written by llmgw (BACKLOG P): the database of Slurm's accounting
# (slurmdbd), on this machine alone.
[mysqld]
bind-address=127.0.0.1
skip-networking=0
innodb_buffer_pool_size=256M
innodb_lock_wait_timeout=900
`
// AcctSQL makes the database and its user, and gives the user the password
// again: run on every start of the controller's part, it changes nothing
// that is already so.
func AcctSQL(password string) string {
return fmt.Sprintf(`CREATE DATABASE IF NOT EXISTS %[1]s;
CREATE USER IF NOT EXISTS '%[2]s'@'localhost' IDENTIFIED BY '%[3]s';
ALTER USER '%[2]s'@'localhost' IDENTIFIED BY '%[3]s';
GRANT ALL ON %[1]s.* TO '%[2]s'@'localhost';
FLUSH PRIVILEGES;
`, AcctDB, AcctUser, password)
}