Skip to content

Commit 7dbe024

Browse files
committed
3.0 config replication
1 parent 99fa56a commit 7dbe024

File tree

6 files changed

+233
-0
lines changed

6 files changed

+233
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Sharded cluster
2+
3+
A sample application demonstrating how to configure a [sharded](https://www.tarantool.io/en/doc/latest/concepts/sharding/) cluster.
4+
5+
## Running
6+
7+
To run the cluster, go to the `sharding` directory in the terminal and perform the following steps:
8+
9+
1. Install `vshard`:
10+
11+
```console
12+
$ tt rocks install vshard
13+
```
14+
15+
2. Run the cluster:
16+
17+
```console
18+
$ tt start sharded_cluster
19+
```
20+
21+
3. Connect to the router:
22+
23+
```console
24+
$ tt connect sharded_cluster:router-a-001
25+
```
26+
27+
4. Insert test data:
28+
29+
```console
30+
sharded_cluster:router-a-001> insert_data()
31+
---
32+
...
33+
```
34+
35+
5. Connect to storages in different replica sets to see how data is distributed across nodes:
36+
37+
a. `storage-a-001`:
38+
39+
```console
40+
sharded_cluster:storage-a-001> box.space.bands:select()
41+
---
42+
- - [1, 614, 'Roxette', 1986]
43+
- [2, 986, 'Scorpions', 1965]
44+
- [5, 755, 'Pink Floyd', 1965]
45+
- [7, 998, 'The Doors', 1965]
46+
- [8, 762, 'Nirvana', 1987]
47+
...
48+
```
49+
50+
b. `storage-b-001`:
51+
52+
```console
53+
sharded_cluster:storage-b-001> box.space.bands:select()
54+
---
55+
- - [3, 11, 'Ace of Base', 1987]
56+
- [4, 42, 'The Beatles', 1960]
57+
- [6, 55, 'The Rolling Stones', 1962]
58+
- [9, 299, 'Led Zeppelin', 1968]
59+
- [10, 167, 'Queen', 1970]
60+
...
61+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
storage:
7+
password: 'secret'
8+
roles: [super]
9+
10+
iproto:
11+
advertise:
12+
peer: replicator@
13+
sharding: storage@
14+
15+
sharding:
16+
bucket_count: 1000
17+
18+
groups:
19+
storages:
20+
app:
21+
module: storage
22+
sharding:
23+
roles: [storage]
24+
replication:
25+
failover: manual
26+
replicasets:
27+
storage-a:
28+
leader: storage-a-001
29+
instances:
30+
storage-a-001:
31+
iproto:
32+
listen: 127.0.0.1:3301
33+
storage-a-002:
34+
iproto:
35+
listen: 127.0.0.1:3302
36+
storage-b:
37+
leader: storage-b-002
38+
instances:
39+
storage-b-001:
40+
iproto:
41+
listen: 127.0.0.1:3303
42+
storage-b-002:
43+
iproto:
44+
listen: 127.0.0.1:3304
45+
routers:
46+
app:
47+
module: router
48+
sharding:
49+
roles: [router]
50+
replicasets:
51+
router-a:
52+
instances:
53+
router-a-001:
54+
iproto:
55+
listen: 127.0.0.1:3300
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sharded_cluster.storage-a-001:
2+
sharded_cluster.storage-a-002:
3+
sharded_cluster.storage-b-001:
4+
sharded_cluster.storage-b-002:
5+
sharded_cluster.router-a-001:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
local vshard = require('vshard')
2+
3+
vshard.router.bootstrap()
4+
5+
function put(id, band_name, year)
6+
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
7+
vshard.router.callrw(bucket_id, 'put', { id, bucket_id, band_name, year })
8+
end
9+
10+
function get(id)
11+
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
12+
return vshard.router.callro(bucket_id, 'get', { id })
13+
end
14+
15+
function insert_data()
16+
put(1, 'Roxette', 1986)
17+
put(2, 'Scorpions', 1965)
18+
put(3, 'Ace of Base', 1987)
19+
put(4, 'The Beatles', 1960)
20+
put(5, 'Pink Floyd', 1965)
21+
put(6, 'The Rolling Stones', 1962)
22+
put(7, 'The Doors', 1965)
23+
put(8, 'Nirvana', 1987)
24+
put(9, 'Led Zeppelin', 1968)
25+
put(10, 'Queen', 1970)
26+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
box.schema.create_space('bands', {
2+
format = {
3+
{ name = 'id', type = 'unsigned' },
4+
{ name = 'bucket_id', type = 'unsigned' },
5+
{ name = 'band_name', type = 'string' },
6+
{ name = 'year', type = 'unsigned' }
7+
},
8+
if_not_exists = true
9+
})
10+
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
11+
box.space.bands:create_index('bucket_id', { parts = { 'id' }, unique = false, if_not_exists = true })
12+
13+
function put(id, bucket_id, band_name, year)
14+
box.space.bands:insert({ id, bucket_id, band_name, year })
15+
end
16+
17+
function get(id)
18+
local tuple = box.space.bands:get(id)
19+
if tuple == nil then
20+
return nil
21+
end
22+
return { tuple.id, tuple.band_name, tuple.year }
23+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
tt:
2+
modules:
3+
# Directory where the external modules are stored.
4+
directory: "modules"
5+
6+
app:
7+
# Directory that stores various instance runtime
8+
# artifacts like console socket, PID file, etc.
9+
run_dir: "var/run"
10+
11+
# Directory that stores log files.
12+
log_dir: var/log
13+
14+
# The maximum size in MB of the log file before it gets rotated.
15+
log_maxsize: 100
16+
17+
# The maximum number of days to retain old log files.
18+
log_maxage: 8
19+
20+
# The maximum number of old log files to retain.
21+
log_maxbackups: 10
22+
23+
# Restart instance on failure.
24+
restart_on_failure: false
25+
26+
# Directory where write-ahead log (.xlog) files are stored.
27+
wal_dir: "var/lib"
28+
29+
# Directory where memtx stores snapshot (.snap) files.
30+
memtx_dir: "var/lib"
31+
32+
# Directory where vinyl files or subdirectories will be stored.
33+
vinyl_dir: "var/lib"
34+
35+
# Directory that stores binary files.
36+
bin_dir: "bin"
37+
38+
# Directory that stores Tarantool header files.
39+
inc_dir: "include"
40+
41+
# Path to directory that stores all applications.
42+
# The directory can also contain symbolic links to applications.
43+
instances_enabled: "instances.enabled"
44+
45+
# Tarantoolctl artifacts layout compatibility: if set to true tt will not create application
46+
# sub-directories for control socket, pid files, log files, etc.. Data files (wal, vinyl,
47+
# snap) and multi-instance applications are not affected by this option.
48+
tarantoolctl_layout: false
49+
50+
# Path to file with credentials for downloading Tarantool Enterprise Edition.
51+
# credential_path: /path/to/file
52+
ee:
53+
credential_path: ""
54+
55+
templates:
56+
# The path to templates search directory.
57+
- path: "templates"
58+
59+
repo:
60+
# Directory where local rocks files could be found.
61+
rocks: ""
62+
# Directory that stores installation files.
63+
distfiles: "distfiles"

0 commit comments

Comments
 (0)