Starting and stopping
How to start a single server, the SQL front-end in one or two processes, and a replica, and how to stop them without losing data.
Start a single server#
raftdb-serverWith no arguments the server listens on 127.0.0.1:7480 only, keeps its data in /var/lib/raftdb or %ProgramData%\RaftDB if that folder exists and otherwise in ./raftdb-data, and creates an admin account on the first start. The account's random password is written once to admin.password in the data directory and read back at every later start. The server prints the file's name, never the password:
raftdb-server: created raftdb-data/admin.password (the password for this account; keep it private)
raftdb-server listening on 127.0.0.1:7480 (binary protocol and HTTP), data in raftdb-dataGive the server explicit settings when you want something else:
raftdb-server --dir ./raftdb-data --addr 127.0.0.1:7480 --shards 4 --studio studio--studio studio serves the Studio at http://127.0.0.1:7480/. Log in with admin and the password from admin.password.
To write a settings file for a profile first:
raftdb-server init --profile single
raftdb-server --config raftdb.conf --check-config
raftdb-server --config raftdb.confStart the SQL front-end, one process#
Write the server's settings file and the front-end's:
# raftdb.conf
dir = ./raftdb-data
addr = 127.0.0.1:7480
shards = 2
user = connector:CHANGE-ME-1:admin# mysql.conf
listen = 127.0.0.1:3307
embed = raftdb.conf
raftdb_user = connector
raftdb_password = CHANGE-ME-1
user = app:CHANGE-ME-2
dialect = mysqlraftdb-mysql --config mysql.confThe process now serves MySQL clients on 3307, and Raft DB's binary protocol, HTTP and the Studio on 7480.
Start the SQL front-end, two processes#
Start raftdb-server as above (with an account such as --user connector:CHANGE-ME-1:admin), then:
# mysql.conf
listen = 127.0.0.1:3307
raftdb = 127.0.0.1:7480
raftdb_user = connector
raftdb_password = CHANGE-ME-1
user = app:CHANGE-ME-2raftdb-mysql --config mysql.confStart a MariaDB endpoint#
Run another raftdb-mysql with dialect = mariadb and its own listen port. An embedded server owns its data directory, and only one server process may use a directory, so give each embedding process its own raftdb.conf and dir (each dialect gets its own directory), or use the two-process mode (raftdb = HOST:PORT) against one server. A dialect marks the databases it creates with its own hidden table (__rdb_mysql or __rdb_mariadb) and lists only its own databases, so the two front-ends do not see each other's databases even on one server.
Start a replica#
raftdb-server --profile replica --replica-of PRIMARY:7480 --replica-user replicator:PASSWORD --dir ./replica-dataSee the replication chapter.
Start the watcher#
raftdb-watch --config watch.conf --check-config
raftdb-watch --config watch.confSee Monitoring with the watcher.
Is it up?#
raftdb-server --print-configshows the settings, andraftdb-watch --config watch.conf --oncechecks a running server and exits0,1or2.GET /v1/serverover HTTP (with a login) reports the role, uptime, replication and degraded commits.- A MySQL client:
mysql -h 127.0.0.1 -P 3307 -u app -p -e "SELECT VERSION()"should print8.0.36-Raft DB(MySQL dialect) or11.4.13-MariaDB-Raft DB(MariaDB dialect).
Stop#
- Ctrl-C,
kill(SIGTERM) or stopping the service. Every acknowledged write is already on disk, so stopping the process loses nothing that was acknowledged. There is no shutdown command in the protocol. --seconds Nmakesraftdb-serverstop gracefully after N seconds (tests and demos): it stops accepting, closes connections, lets the shards and flushers finish, and joins all threads.- A client whose statement was in progress when the process stopped gets a lost-connection error (
2013) and must retry; it cannot know whether an unacknowledged write happened. - An open SQL transaction is not durable until
COMMIT; if the front-end stops in the middle of one, what had been written stays written (the transaction is atomic only while the front-end lives). See Consistency guarantees. - Do not start a second server on the same data directory. There is no file lock yet, and two processes on one log would corrupt it.
Start-up recovery#
On start every shard replays its log, cuts a torn last record, and (if checkpoint-min-mb allows) rewrites a log that is large and mostly dead before it serves anything. Restart time follows the history in the log on the memory engine (replay speed is about 3.2 million records a second in the project's measurements) and is bounded by one memtable on the lsm engine.