Skip to content

Commit 06bdb55

Browse files
askaltpsergee
authored andcommitted
create: add built-in vshard cluster template
This patch introduces built-in `vshard_cluster` template, which uses tarantool 3.0 config. Part of #489
1 parent 0442a40 commit 06bdb55

File tree

12 files changed

+364
-3
lines changed

12 files changed

+364
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Module ``tt replicaset``, to manage replicasets:
1313
- ``tt replicaset status`` to show a cluster status information.
14+
- Built-in vshard cluster application template.
1415

1516
### Changed
1617

cli/cmd/create_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestCreateValidArgsFunction(t *testing.T) {
3939

4040
templates := []string{
4141
"cartridge",
42+
"vshard_cluster",
4243
"archive",
4344
"template2",
4445
tdir1Name,

cli/codegen/generate_code.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ func main() {
131131
if err != nil {
132132
log.Errorf("error while generating file modes: %s", err)
133133
}
134+
err = generateFileModeFile(
135+
"cli/create/builtin_templates/templates/vshard_cluster",
136+
"cli/create/builtin_templates/static/vshard_cluster_template_filemodes_gen.go",
137+
"VshardCluster",
138+
)
139+
if err != nil {
140+
log.Errorf("error while generating file modes: %s", err)
141+
}
134142

135143
if err = generateLuaCodeVar(); err != nil {
136144
log.Errorf("error while generating lua code string variables: %s", err)

cli/create/builtin_templates/builtin_templates.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ var TemplatesFs embed.FS
1111

1212
// FileModes contains mapping of file modes by built-in template name.
1313
var FileModes = map[string]map[string]int{
14-
"cartridge": static.CartridgeFileModes,
14+
"cartridge": static.CartridgeFileModes,
15+
"vshard_cluster": static.VshardClusterFileModes,
1516
}
1617

1718
// Names contains built-in template names.
18-
var Names = [...]string{"cartridge"}
19+
var Names = [...]string{"cartridge", "vshard_cluster"}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
description: Vshard cluster template
2+
follow-up-message: |
3+
What's next?
4+
Build and start '{{ .name }}' application:
5+
$ tt build {{ .name }}
6+
$ tt start {{ .name }}
7+
8+
Pay attention that default passwords were generated,
9+
you can change it in the config.yaml.
10+
11+
vars:
12+
- prompt: Bucket count
13+
name: bucket_count
14+
default: '3000'
15+
re: ^[1-9]\d*$
16+
17+
- prompt: Storage replication sets count
18+
name: replicasets_count
19+
default: '2'
20+
re: ^[1-9]\d*$
21+
22+
- prompt: Storage replicas per replication set count (>=2)
23+
name: replicas_count
24+
default: '2'
25+
re: ^[2-9]|[1-9]\d+$
26+
27+
- prompt: Routers count
28+
name: routers_count
29+
default: '1'
30+
re: ^[1-9]\d*$
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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: {{.bucket_count}}
22+
23+
groups:
24+
storages:
25+
app:
26+
module: storage
27+
sharding:
28+
roles: [storage]
29+
replication:
30+
failover: manual
31+
{{- $replicasets := atoi .replicasets_count}}{{$replicas := atoi .replicas_count}}
32+
replicasets: {{ range replicasets "storage" $replicasets $replicas }}
33+
{{.Name}}:
34+
leader: {{index .InstNames 0}}
35+
instances: {{range .InstNames}}
36+
{{.}}:
37+
iproto:
38+
listen:
39+
- uri: localhost:{{port}}{{end}}{{end}}
40+
routers:
41+
app:
42+
module: router
43+
sharding:
44+
roles: [router]
45+
{{- $routers := atoi .routers_count}}
46+
replicasets: {{ range replicasets "router" $routers 1}}
47+
{{.Name}}:
48+
instances: {{range .InstNames}}
49+
{{.}}:
50+
iproto:
51+
listen:
52+
- uri: localhost:{{port}}{{end}}{{end}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
{{- $replicasets := atoi .replicasets_count}}{{$replicas := atoi .replicas_count}}
3+
{{ range replicasets "storage" $replicasets $replicas }}{{range .InstNames}}{{.}}:
4+
5+
{{end}}{{end}}
6+
7+
{{- $routers := atoi .routers_count}}
8+
{{- range replicasets "router" $routers 1}}{{range .InstNames}}{{.}}:
9+
10+
{{end}}{{end}}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local vshard = require('vshard')
2+
local log = require('log')
3+
4+
-- Bootstrap the vshard router.
5+
while true do
6+
local ok, err = vshard.router.bootstrap({
7+
if_not_bootstrapped = true,
8+
})
9+
if ok then
10+
break
11+
end
12+
log.info(('Router bootstrap error: %s'):format(err))
13+
end
14+
15+
-- Put data into the cluster.
16+
function put(id, name, age)
17+
local bucket_id = vshard.router.bucket_id_mpcrc32({id})
18+
vshard.router.callrw(bucket_id, 'put', {id, bucket_id, name, age})
19+
end
20+
21+
-- Get data from the cluster.
22+
function get(id)
23+
local bucket_id = vshard.router.bucket_id_mpcrc32({id})
24+
return vshard.router.callro(bucket_id, 'get', {id})
25+
end
26+
27+
-- Put sample data.
28+
function put_sample_data()
29+
put(1, 'Elizabeth', 12)
30+
put(2, 'Mary', 46)
31+
put(3, 'David', 33)
32+
put(4, 'William', 81)
33+
put(5, 'Jack', 35)
34+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
local vshard = require('vshard')
2+
3+
-- Create 'customers' space.
4+
box.once('customers', function()
5+
box.schema.create_space('customers', {
6+
format = {{
7+
name = 'id',
8+
type = 'unsigned'
9+
}, {
10+
name = 'bucket_id',
11+
type = 'unsigned'
12+
}, {
13+
name = 'name',
14+
type = 'string'
15+
}, {
16+
name = 'age',
17+
type = 'number'
18+
}}
19+
})
20+
box.space.customers:create_index('primary_index', {
21+
parts = {{
22+
field = 1,
23+
type = 'unsigned'
24+
}}
25+
})
26+
box.space.customers:create_index('bucket_id', {
27+
parts = {{
28+
field = 2,
29+
type = 'unsigned'
30+
}},
31+
unique = false
32+
})
33+
box.space.customers:create_index('age', {
34+
parts = {{
35+
field = 4,
36+
type = 'number'
37+
}},
38+
unique = false
39+
})
40+
end)
41+
42+
-- Put data to the 'customers' space.
43+
-- Function should be called by the router.
44+
function put(id, bucket_id, name, age)
45+
box.space.customers:insert({id, bucket_id, name, age})
46+
end
47+
48+
-- Get data from the 'customers' space.
49+
-- Function should be called by the router.
50+
function get(id)
51+
local tuple = box.space.customers:get(id)
52+
if tuple == nil then
53+
return nil
54+
end
55+
return {tuple.id, tuple.name, tuple.age}
56+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package = '{{ .name }}'
2+
version = 'scm-1'
3+
source = {
4+
url = '/dev/null',
5+
}
6+
dependencies = {
7+
'vshard == 0.1.25'
8+
}
9+
build = {
10+
type = 'none';
11+
}

0 commit comments

Comments
 (0)