Replication settings tntapi
In this section:
Simple master->slaves replication
Replication allows multiple tntapi instances to work on copies of the same database. The database copies are kept in sync because each instance can communicate its changes to all the other instances. Tarantool supports master-slave replication. You can add and delete data only by using the master instance. Slave instances (aka replicas) are read-only, i.e., can be used only for searching and consulting data.
To start a created replica for the first time, do the following:
Start the master instance.
docker run -tid --name tnt-1-1 --restart always --network server \ --env CFG_LISTEN_HOST=0.0.0.0 \ --env CFG_LISTEN_PORT=8001 \ --env CFG_NTLS=ntls:3133 \ --env TT_LISTEN=0.0.0.0:32001 \ --env TT_MEMTX_MEMORY=$((1024 * 1024 * 1024)) \ --volume /opt/ffserver/tnt/001-01:/opt/ntech/var/lib/tarantool/default \ --publish 127.0.0.1:8001:8001 \ docker.int.ntl/ntech/universe/tntapi:ffserver-11.240325
In the replica container environments, specify the IP address and the listening port of the master instance.
TT_REPLICATION=tnt-1-1:32001 # master address in TT_LISTEN TT_READ_ONLY=true
Create a directory for slave snapshots and xlogs.
sudo mkdir -p /opt/ffserver/tnt/001-02/{snapshots,xlogs}
Copy the latest snapshot of the master instance into the
/opt/ffserver/tnt/001-02/snapshots
directory of the replica.Copy the latest xlog of the master instance into the
/opt/ffserver/tnt/001-02/xlogs
directory of the replica.Start the replica docker container. You can start as many replicas affiliated with the same master instance as needed.
docker run -tid --name tnt-1-2 --restart always --network server \ --env CFG_LISTEN_HOST=0.0.0.0 \ --env CFG_LISTEN_PORT=8101 \ --env CFG_NTLS=ntls:3133 \ --env TT_LISTEN=0.0.0.0:32101 \ --env TT_REPLICATION=tnt-1-1:32001 \ --env TT_READ_ONLY=true \ --env TT_MEMTX_MEMORY=$((1024 * 1024 * 1024)) \ --volume /opt/ffserver/tnt/001-02:/opt/ntech/var/lib/tarantool/default \ --publish 127.0.0.1:8101:8101 \ docker.int.ntl/ntech/universe/tntapi:ffserver-11.240325
Check the status of the nodes.
curl -i http://localhost:8001/v2/status
HTTP/1.1 200 Ok X-request-id: TN:xfKtuMxP Content-type: application/json X-read-only: false Content-length: 19 Connection: keep-alive Server: Tarantool http (tarantool v2.10.4-2-gd536a7aa5) {"read_only":false}
curl -i http://localhost:8101/v2/status
HTTP/1.1 200 Ok X-request-id: TN:1ZMBu6Uf Content-type: application/json X-read-only: true Content-length: 18 Connection: keep-alive Server: Tarantool http (tarantool v2.10.4-2-gd536a7aa5) {"read_only":true}
Important
Live index does not work on replicas.
Tip
To synchronize the master instance and replica, you can also copy the latest master snapshot to the replica.