Skip to content

Commit f56c25d

Browse files
Tarantool config storage (#4056)
1 parent a5dc52c commit f56c25d

File tree

27 files changed

+1059
-114
lines changed

27 files changed

+1059
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Centralized configuration storages
2+
3+
Sample applications demonstrating how to store configuration data in one place using Tarantool or etcd-based storage. Learn more at [Centralized configuration storages](https://www.tarantool.io/en/doc/latest/concepts/configuration/configuration_etcd/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# 1. Remove the 'default.etcd' directory to reset etcd to initial state.
4+
# 2. Start etcd by executing the 'etcd' command.
5+
# 3. Execute this script to enable authentication.
6+
etcdctl user add root:topsecret
7+
etcdctl role add myapp_config_manager
8+
etcdctl role grant-permission myapp_config_manager --prefix=true readwrite /myapp/
9+
etcdctl user add sampleuser:123456
10+
etcdctl user grant-role sampleuser myapp_config_manager
11+
etcdctl auth enable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# etcd configuration storage
2+
3+
A sample application demonstrating how to obtain a cluster's configuration from the etcd-based configuration storage.
4+
5+
## Running
6+
7+
Before running this sample, start etcd and enable authentication by executing [etcd_config_storage.sh](../../etcd_config_storage.sh).
8+
9+
To start all instances, execute the following command in the [centralized_config](../../../centralized_config) directory:
10+
11+
```console
12+
$ tt start config_etcd
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
config:
2+
etcd:
3+
endpoints:
4+
- http://localhost:2379
5+
prefix: /myapp
6+
username: sampleuser
7+
password: '123456'
8+
http:
9+
request:
10+
timeout: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Tarantool configuration storage
2+
3+
A sample application demonstrating how to obtain a cluster's configuration from the Tarantool-based configuration storage.
4+
5+
## Running
6+
7+
Before running this sample, start a Tarantool-based configuration storage: [tarantool_config_storage](../tarantool_config_storage).
8+
9+
To start all instances, execute the following command in the [centralized_config](../../../centralized_config) directory:
10+
11+
```console
12+
$ tt start config_storage
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
config:
2+
storage:
3+
endpoints:
4+
- uri: '127.0.0.1:4401'
5+
login: sampleuser
6+
password: '123456'
7+
- uri: '127.0.0.1:4402'
8+
login: sampleuser
9+
password: '123456'
10+
- uri: '127.0.0.1:4403'
11+
login: sampleuser
12+
password: '123456'
13+
prefix: /myapp
14+
timeout: 3
15+
reconnect_after: 5
16+
17+
# Watch key changes
18+
app:
19+
file: 'myapp.lua'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
net_box = require('net.box')
2+
local conn = net_box.connect('127.0.0.1:4401')
3+
local log = require('log')
4+
conn:watch('config.storage:/myapp/config/all', function(key, value)
5+
log.info("Configuration stored by the '/myapp/config/all' key is changed")
6+
end)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Setting up Tarantool configuration storage
2+
3+
A sample application demonstrating how to set up Tarantool configuration storage.
4+
5+
## Running
6+
7+
To start all instances of the configuration storage, execute the following command in the [centralized_config](../../../centralized_config) directory:
8+
9+
```console
10+
$ tt start tarantool_config_storage
11+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
credentials:
2+
users:
3+
sampleuser:
4+
password: '123456'
5+
privileges:
6+
- permissions: [ read, write ]
7+
spaces: [ config_storage, config_storage_meta ]
8+
- permissions: [ execute ]
9+
universe: true
10+
replicator:
11+
password: 'topsecret'
12+
roles: [ replication ]
13+
14+
iproto:
15+
advertise:
16+
peer:
17+
login: replicator
18+
19+
replication:
20+
failover: election
21+
22+
database:
23+
use_mvcc_engine: true
24+
25+
groups:
26+
group001:
27+
replicasets:
28+
replicaset001:
29+
roles: [ config.storage ]
30+
roles_cfg:
31+
config.storage:
32+
status_check_interval: 3
33+
instances:
34+
instance001:
35+
iproto:
36+
listen:
37+
- uri: '127.0.0.1:4401'
38+
instance002:
39+
iproto:
40+
listen:
41+
- uri: '127.0.0.1:4402'
42+
instance003:
43+
iproto:
44+
listen:
45+
- uri: '127.0.0.1:4403'
46+
47+
# Interact with config storage
48+
app:
49+
file: 'myapp.lua'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
instance001:
2+
instance002:
3+
instance003:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function put_config()
2+
local fio = require('fio')
3+
local cluster_config_handle = fio.open('../../source.yaml')
4+
local cluster_config = cluster_config_handle:read()
5+
local response = config.storage.put('/myapp/config/all', cluster_config)
6+
cluster_config_handle:close()
7+
return response
8+
end
9+
10+
function get_config_by_path()
11+
local response = config.storage.get('/myapp/config/all')
12+
return response
13+
end
14+
15+
function get_config_by_prefix()
16+
local response = config.storage.get('/myapp/')
17+
return response
18+
end
19+
20+
function make_txn_request()
21+
local response = config.storage.txn({
22+
predicates = { { 'value', '==', 'v0', '/myapp/config/all' } },
23+
on_success = { { 'put', '/myapp/config/all', 'v1' } },
24+
on_failure = { { 'get', '/myapp/config/all' } }
25+
})
26+
return response
27+
end
28+
29+
function delete_config()
30+
local response = config.storage.delete('/myapp/config/all')
31+
return response
32+
end
33+
34+
function delete_all_configs()
35+
local response = config.storage.delete('/')
36+
return response
37+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# A sample cluster config used to demonstrate a centralized configuration storage.
2+
# Learn more: https://www.tarantool.io/en/doc/latest/concepts/configuration/configuration_etcd.
3+
credentials:
4+
users:
5+
replicator:
6+
password: 'topsecret'
7+
roles: [replication]
8+
9+
iproto:
10+
advertise:
11+
peer:
12+
login: replicator
13+
14+
replication:
15+
failover: manual
16+
17+
groups:
18+
group001:
19+
replicasets:
20+
replicaset001:
21+
leader: instance001
22+
instances:
23+
instance001:
24+
iproto:
25+
listen:
26+
- uri: '127.0.0.1:3301'
27+
instance002:
28+
iproto:
29+
listen:
30+
- uri: '127.0.0.1:3302'
31+
instance003:
32+
iproto:
33+
listen:
34+
- uri: '127.0.0.1:3303'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
modules:
2+
# Directory where the external modules are stored.
3+
directory: modules
4+
5+
env:
6+
# Restart instance on failure.
7+
restart_on_failure: false
8+
9+
# Directory that stores binary files.
10+
bin_dir: bin
11+
12+
# Directory that stores Tarantool header files.
13+
inc_dir: include
14+
15+
# Path to directory that stores all applications.
16+
# The directory can also contain symbolic links to applications.
17+
instances_enabled: instances.enabled
18+
19+
# Tarantoolctl artifacts layout compatibility: if set to true tt will not create application
20+
# sub-directories for control socket, pid files, log files, etc.. Data files (wal, vinyl,
21+
# snap) and multi-instance applications are not affected by this option.
22+
tarantoolctl_layout: false
23+
24+
app:
25+
# Directory that stores various instance runtime
26+
# artifacts like console socket, PID file, etc.
27+
run_dir: var/run
28+
29+
# Directory that stores log files.
30+
log_dir: var/log
31+
32+
# Directory where write-ahead log (.xlog) files are stored.
33+
wal_dir: var/lib
34+
35+
# Directory where memtx stores snapshot (.snap) files.
36+
memtx_dir: var/lib
37+
38+
# Directory where vinyl files or subdirectories will be stored.
39+
vinyl_dir: var/lib
40+
41+
# Path to file with credentials for downloading Tarantool Enterprise Edition.
42+
# credential_path: /path/to/file
43+
ee:
44+
credential_path:
45+
46+
templates:
47+
# The path to templates search directory.
48+
- path: templates
49+
50+
repo:
51+
# Directory where local rocks files could be found.
52+
rocks:
53+
# Directory that stores installation files.
54+
distfiles: distfiles

doc/code_snippets/snippets/config/instances.enabled/etcd/config.yaml

-5
This file was deleted.

doc/code_snippets/snippets/config/instances.enabled/etcd_full/config.yaml

-12
This file was deleted.

doc/concepts/configuration.rst

+16-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ There are two approaches to configuring Tarantool:
1111
* *Since version 3.0*: In the YAML format.
1212

1313
YAML configuration allows you to provide the full cluster topology and specify all configuration options.
14-
You can use local configuration in a YAML file for each instance or store configuration data in one reliable place using :ref:`etcd <configuration_etcd_overview>`.
14+
You can use local configuration in a YAML file for each instance or store configuration data in a reliable :ref:`centralized storage <configuration_etcd_overview>`.
1515

1616
* *In version 2.11 and earlier*: :ref:`In code <configuration_code>` using the ``box.cfg`` API.
1717

@@ -327,25 +327,29 @@ Below are a few examples that show how to set environment variables of different
327327

328328
.. _configuration_etcd_overview:
329329

330-
Configuration in etcd
331-
~~~~~~~~~~~~~~~~~~~~~
330+
Centralized configuration
331+
~~~~~~~~~~~~~~~~~~~~~~~~~
332332

333333
.. include:: /concepts/configuration/configuration_etcd.rst
334-
:start-after: ee_note_etcd_start
335-
:end-before: ee_note_etcd_end
334+
:start-after: ee_note_centralized_config_start
335+
:end-before: ee_note_centralized_config_end
336+
336337

337-
Tarantool enables you to store configuration data in one reliable place using `etcd <https://etcd.io/>`_.
338+
Tarantool enables you to store configuration data in one place using a Tarantool or etcd-based storage.
338339
To achieve this, you need to:
339340

340-
1. Provide a local YAML configuration with an etcd endpoint address and key prefix in the ``config`` section:
341+
1. Set up a centralized configuration storage.
342+
343+
2. Publish a cluster's configuration to the storage.
341344

342-
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/etcd/config.yaml
345+
3. Configure a connection to the storage by providing a local YAML configuration with an endpoint address and key prefix in the ``config`` section:
346+
347+
.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/config_etcd/config.yaml
343348
:language: yaml
349+
:end-at: prefix: /myapp
344350
:dedent:
345351

346-
2. Publish a cluster's configuration to an etcd server.
347-
348-
Learn more from the following guide: :ref:`Storing configuration in etcd <configuration_etcd>`.
352+
Learn more from the following guide: :ref:`configuration_etcd`.
349353

350354

351355
.. _configuration_precedence:
@@ -357,7 +361,7 @@ Tarantool configuration options are applied from multiple sources with the follo
357361

358362
- `TT_*` :ref:`environment variables <configuration_environment_variable>`.
359363
- Configuration from a :ref:`local YAML file <configuration_file>`.
360-
- :ref:`Centralized configuration <configuration_etcd_overview>` stored in etcd.
364+
- :ref:`Centralized configuration <configuration_etcd_overview>`.
361365
- `TT_*_DEFAULT` :ref:`environment variables <configuration_environment_variable>`.
362366

363367
If the same option is defined in two or more locations, the option with the highest precedence is applied.

0 commit comments

Comments
 (0)