Skip to content

Commit 1e54dae

Browse files
committed
Migration tutorial draft
1 parent d9a8b4d commit 1e54dae

File tree

15 files changed

+1070
-90
lines changed

15 files changed

+1070
-90
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Centralized configuration storages
2+
3+
Sample applications demonstrating how to use the centralized migration mechanism
4+
for Tarantool EE clusters via the tt utility. Learn more at [Centralized configuration storages](https://www.tarantool.io/en/doc/latest/platform/https://www.tarantool.io/en/doc/latest/platform/ddl_dml/migrations/).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
7+
etcdctl user add root:topsecret
8+
etcdctl role add app_config_manager
9+
etcdctl role grant-permission app_config_manager --prefix=true readwrite /myapp/
10+
etcdctl user add app_user:config_pass
11+
etcdctl user grant-role app_user app_config_manager
12+
etcdctl auth enable
Lines changed: 10 additions & 0 deletions
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: app_user
7+
password: config_pass
8+
http:
9+
request:
10+
timeout: 3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
router-001-a:
2+
storage-001-a:
3+
storage-001-b:
4+
storage-002-a:
5+
storage-002-b:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package = 'myapp'
2+
version = 'scm-1'
3+
4+
source = {
5+
url = '/dev/null',
6+
}
7+
8+
dependencies = {
9+
'crud == 1.5.2',
10+
}
11+
12+
build = {
13+
type = 'none';
14+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
credentials:
2+
users:
3+
client:
4+
password: 'secret'
5+
roles: [super]
6+
replicator:
7+
password: 'secret'
8+
roles: [replication]
9+
storage:
10+
password: 'secret'
11+
roles: [sharding]
12+
13+
iproto:
14+
advertise:
15+
peer:
16+
login: replicator
17+
sharding:
18+
login: storage
19+
20+
sharding:
21+
bucket_count: 3000
22+
23+
groups:
24+
routers:
25+
sharding:
26+
roles: [router]
27+
roles: [roles.crud-router]
28+
replicasets:
29+
router-001:
30+
instances:
31+
router-001-a:
32+
iproto:
33+
listen:
34+
- uri: localhost:3301
35+
advertise:
36+
client: localhost:3301
37+
storages:
38+
sharding:
39+
roles: [storage]
40+
roles: [roles.crud-storage]
41+
replication:
42+
failover: manual
43+
replicasets:
44+
storage-001:
45+
leader: storage-001-a
46+
instances:
47+
storage-001-a:
48+
iproto:
49+
listen:
50+
- uri: localhost:3302
51+
advertise:
52+
client: localhost:3302
53+
storage-001-b:
54+
iproto:
55+
listen:
56+
- uri: localhost:3303
57+
advertise:
58+
client: localhost:3303
59+
storage-002:
60+
leader: storage-002-a
61+
instances:
62+
storage-002-a:
63+
iproto:
64+
listen:
65+
- uri: localhost:3304
66+
advertise:
67+
client: localhost:3304
68+
storage-002-b:
69+
iproto:
70+
listen:
71+
- uri: localhost:3305
72+
advertise:
73+
client: localhost:3305
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local helpers = require('tt-migrations.helpers')
2+
3+
local function apply_scenario()
4+
local space = box.schema.space.create('writers')
5+
6+
space:format({
7+
{name = 'id', type = 'number'},
8+
{name = 'bucket_id', type = 'number'},
9+
{name = 'name', type = 'string'},
10+
{name = 'age', type = 'number'},
11+
})
12+
13+
space:create_index('primary', {parts = {'id'}})
14+
space:create_index('bucket_id', {parts = {'bucket_id'}})
15+
16+
helpers.register_sharding_key('writers', {'id'})
17+
end
18+
19+
return {
20+
apply = {
21+
scenario = apply_scenario,
22+
},
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local function apply_scenario()
2+
local space = box.space['writers']
3+
4+
space:create_index('age', {parts = {'age'}})
5+
end
6+
7+
return {
8+
apply = {
9+
scenario = apply_scenario,
10+
},
11+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local function apply_scenario()
2+
local space = box.space['writers']
3+
local new_format = {
4+
{name = 'id', type = 'number'},
5+
{name = 'bucket_id', type = 'number'},
6+
{name = 'first_name', type = 'string'},
7+
{name = 'last_name', type = 'string'},
8+
{name = 'age', type = 'number'},
9+
}
10+
box.space.writers.index.age:drop()
11+
12+
box.schema.func.create('_writers_split_name', {
13+
language = 'lua',
14+
is_deterministic = true,
15+
body = [[
16+
function(t)
17+
local name = t[3]
18+
19+
local split_data = {}
20+
local split_regex = '([^%s]+)'
21+
for v in string.gmatch(name, split_regex) do
22+
table.insert(split_data, v)
23+
end
24+
25+
local first_name = split_data[1]
26+
assert(first_name ~= nil)
27+
28+
local last_name = split_data[2]
29+
assert(last_name ~= nil)
30+
31+
return {t[1], t[2], first_name, last_name, t[4]}
32+
end
33+
]],
34+
})
35+
36+
local future = space:upgrade({
37+
func = '_writers_split_name',
38+
format = new_format,
39+
})
40+
41+
future:wait()
42+
end
43+
44+
return {
45+
apply = {
46+
scenario = apply_scenario,
47+
},
48+
}
Lines changed: 54 additions & 0 deletions
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

0 commit comments

Comments
 (0)