Skip to content

Commit eb2e255

Browse files
A sharded cluster application with the CRUD module and roles (#4083)
1 parent 646ee16 commit eb2e255

File tree

11 files changed

+202
-21
lines changed

11 files changed

+202
-21
lines changed

doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster/config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ groups:
3232
storage-a-001:
3333
iproto:
3434
listen:
35-
- uri: '127.0.0.1:3301'
35+
- uri: '127.0.0.1:3302'
3636
storage-a-002:
3737
iproto:
3838
listen:
39-
- uri: '127.0.0.1:3302'
39+
- uri: '127.0.0.1:3303'
4040
storage-b:
4141
leader: storage-b-001
4242
instances:
4343
storage-b-001:
4444
iproto:
4545
listen:
46-
- uri: '127.0.0.1:3303'
46+
- uri: '127.0.0.1:3304'
4747
storage-b-002:
4848
iproto:
4949
listen:
50-
- uri: '127.0.0.1:3304'
50+
- uri: '127.0.0.1:3305'
5151
routers:
5252
app:
5353
module: router
@@ -59,4 +59,4 @@ groups:
5959
router-a-001:
6060
iproto:
6161
listen:
62-
- uri: '127.0.0.1:3300'
62+
- uri: '127.0.0.1:3301'

doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster/storage.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ box.schema.create_space('bands', {
88
if_not_exists = true
99
})
1010
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 })
11+
box.space.bands:create_index('bucket_id', { parts = { 'bucket_id' }, unique = false, if_not_exists = true })
1212

1313
function insert_band(id, bucket_id, band_name, year)
1414
box.space.bands:insert({ id, bucket_id, band_name, year })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Sharded cluster with CRUD
2+
3+
A sample application demonstrating how to set up a sharded cluster with the [crud](https://github.com/tarantool/crud) module.
4+
5+
## Running
6+
7+
Before running the cluster, execute the `tt build` command in the [sharding](../../../sharding) directory:
8+
9+
```shell
10+
$ tt build sharded_cluster_crud
11+
```
12+
13+
Then, start all instances in the cluster using `tt start`:
14+
15+
```shell
16+
$ tt start sharded_cluster_crud
17+
```
18+
19+
## Bootstrapping a cluster
20+
21+
After starting instances, you need to bootstrap the cluster.
22+
Connect to the router instance using `tt connect`:
23+
24+
```shell
25+
$ tt connect sharded_cluster_crud:router-a-001
26+
• Connecting to the instance...
27+
• Connected to sharded_cluster_crud:router-a-001
28+
```
29+
30+
Call `vshard.router.bootstrap()` to perform the initial cluster bootstrap:
31+
32+
```shell
33+
sharded_cluster_crud:router-a-001> vshard.router.bootstrap()
34+
---
35+
- true
36+
...
37+
```
38+
39+
40+
## Inserting data
41+
42+
To insert sample data, call `crud.insert_many()` on the router:
43+
44+
```lua
45+
crud.insert_many('bands', {
46+
{ 1, box.NULL, 'Roxette', 1986 },
47+
{ 2, box.NULL, 'Scorpions', 1965 },
48+
{ 3, box.NULL, 'Ace of Base', 1987 },
49+
{ 4, box.NULL, 'The Beatles', 1960 },
50+
{ 5, box.NULL, 'Pink Floyd', 1965 },
51+
{ 6, box.NULL, 'The Rolling Stones', 1962 },
52+
{ 7, box.NULL, 'The Doors', 1965 },
53+
{ 8, box.NULL, 'Nirvana', 1987 },
54+
{ 9, box.NULL, 'Led Zeppelin', 1968 },
55+
{ 10, box.NULL, 'Queen', 1970 }
56+
})
57+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
storage:
7+
password: 'secret'
8+
roles: [sharding]
9+
10+
iproto:
11+
advertise:
12+
peer:
13+
login: replicator
14+
sharding:
15+
login: storage
16+
17+
sharding:
18+
bucket_count: 1000
19+
20+
groups:
21+
storages:
22+
roles: [storage]
23+
sharding:
24+
roles: [storage]
25+
replication:
26+
failover: manual
27+
replicasets:
28+
storage-a:
29+
leader: storage-a-001
30+
instances:
31+
storage-a-001:
32+
iproto:
33+
listen:
34+
- uri: '127.0.0.1:3302'
35+
storage-a-002:
36+
iproto:
37+
listen:
38+
- uri: '127.0.0.1:3303'
39+
storage-b:
40+
leader: storage-b-001
41+
instances:
42+
storage-b-001:
43+
iproto:
44+
listen:
45+
- uri: '127.0.0.1:3304'
46+
storage-b-002:
47+
iproto:
48+
listen:
49+
- uri: '127.0.0.1:3305'
50+
routers:
51+
roles: [router]
52+
sharding:
53+
roles: [router]
54+
replicasets:
55+
router-a:
56+
instances:
57+
router-a-001:
58+
iproto:
59+
listen:
60+
- uri: '127.0.0.1:3301'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
storage-a-001:
2+
storage-a-002:
3+
storage-b-001:
4+
storage-b-002:
5+
router-a-001:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local vshard = require('vshard')
2+
local crud = require('crud')
3+
4+
local M = {}
5+
6+
function M.validate()
7+
end
8+
9+
function M.apply()
10+
crud.init_router()
11+
end
12+
13+
function M.stop()
14+
crud.stop_router()
15+
end
16+
17+
return M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package = 'sharded_cluster_crud'
2+
version = 'scm-1'
3+
source = {
4+
url = '/dev/null',
5+
}
6+
7+
dependencies = {
8+
'vshard == 0.1.26',
9+
'crud == 1.4.3'
10+
}
11+
build = {
12+
type = 'none';
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local crud = require('crud')
2+
3+
local M = {}
4+
5+
function M.validate()
6+
end
7+
8+
function M.apply()
9+
crud.init_storage()
10+
if box.info.ro ~= true then
11+
box.schema.create_space('bands', {
12+
format = {
13+
{ name = 'id', type = 'unsigned' },
14+
{ name = 'bucket_id', type = 'unsigned' },
15+
{ name = 'band_name', type = 'string' },
16+
{ name = 'year', type = 'unsigned' }
17+
},
18+
if_not_exists = true
19+
})
20+
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
21+
box.space.bands:create_index('bucket_id', { parts = { 'bucket_id' }, unique = false, if_not_exists = true })
22+
end
23+
end
24+
25+
function M.stop()
26+
crud.stop_storage()
27+
end
28+
29+
return M

doc/code_snippets/snippets/sharding/templates/basic/config.yaml.tt.template

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ groups:
3232
storage-a-001:
3333
iproto:
3434
listen:
35-
- uri: '{{.listen_uri}}:3301'
35+
- uri: '{{.listen_uri}}:3302'
3636
storage-a-002:
3737
iproto:
3838
listen:
39-
- uri: '{{.listen_uri}}:3302'
39+
- uri: '{{.listen_uri}}:3303'
4040
storage-b:
4141
leader: storage-b-001
4242
instances:
4343
storage-b-001:
4444
iproto:
4545
listen:
46-
- uri: '{{.listen_uri}}:3303'
46+
- uri: '{{.listen_uri}}:3304'
4747
storage-b-002:
4848
iproto:
4949
listen:
50-
- uri: '{{.listen_uri}}:3304'
50+
- uri: '{{.listen_uri}}:3305'
5151
routers:
5252
app:
5353
module: router
@@ -59,4 +59,4 @@ groups:
5959
router-a-001:
6060
iproto:
6161
listen:
62-
- uri: '{{.listen_uri}}:3300'
62+
- uri: '{{.listen_uri}}:3301'

doc/how-to/vshard_quick.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Here is a schematic view of the cluster's topology:
192192
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/config.yaml
193193
:language: yaml
194194
:start-at: routers:
195-
:end-at: 127.0.0.1:3300
195+
:end-at: 127.0.0.1:3301
196196
:dedent:
197197

198198
The main group-level options here are:
@@ -406,28 +406,28 @@ To check the cluster's status, execute :ref:`vshard.router.info() <router_api-in
406406
replica:
407407
network_timeout: 0.5
408408
status: available
409-
409+
410410
name: storage-b-002
411411
bucket:
412412
available_rw: 500
413413
master:
414414
network_timeout: 0.5
415415
status: available
416-
416+
417417
name: storage-b-001
418418
name: storage-b
419419
storage-a:
420420
replica:
421421
network_timeout: 0.5
422422
status: available
423-
423+
424424
name: storage-a-002
425425
bucket:
426426
available_rw: 500
427427
master:
428428
network_timeout: 0.5
429429
status: available
430-
430+
431431
name: storage-a-001
432432
name: storage-a
433433
bucket:

locale/en/release/3.0.0.pot

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ msgid "groups:\n"
8888
" storage-a-001:\n"
8989
" iproto:\n"
9090
" listen:\n"
91-
" - uri: '127.0.0.1:3301'\n"
91+
" - uri: '127.0.0.1:3302'\n"
9292
" storage-a-002:\n"
9393
" iproto:\n"
9494
" listen:\n"
95-
" - uri: '127.0.0.1:3302'\n"
95+
" - uri: '127.0.0.1:3303'\n"
9696
" storage-b:\n"
9797
" leader: storage-b-001\n"
9898
" instances:\n"
9999
" storage-b-001:\n"
100100
" iproto:\n"
101101
" listen:\n"
102-
" - uri: '127.0.0.1:3303'\n"
102+
" - uri: '127.0.0.1:3304'\n"
103103
" storage-b-002:\n"
104104
" iproto:\n"
105105
" listen:\n"
106-
" - uri: '127.0.0.1:3304'\n"
106+
" - uri: '127.0.0.1:3305'\n"
107107
" routers:\n"
108108
" app:\n"
109109
" module: router\n"
@@ -115,7 +115,7 @@ msgid "groups:\n"
115115
" router-a-001:\n"
116116
" iproto:\n"
117117
" listen:\n"
118-
" - uri: '127.0.0.1:3300'"
118+
" - uri: '127.0.0.1:3301'"
119119
msgstr ""
120120

121121
#: ../../doc/release/3.0.0.rst:45

0 commit comments

Comments
 (0)