Skip to content

Commit 258567d

Browse files
committed
Sharded cluster with crud
1 parent a5dc52c commit 258567d

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Sharded cluster with CRUD
2+
3+
```shell
4+
$ tt build sharded_cluster_crud
5+
```
6+
7+
Example requests:
8+
9+
```lua
10+
crud.insert('bands', {1, box.NULL, 'Roxette', 1986})
11+
```
12+
13+
```lua
14+
crud.insert_many('bands', {
15+
{ 1, box.NULL, 'Roxette', 1986 },
16+
{ 2, box.NULL, 'Scorpions', 1965 },
17+
{ 3, box.NULL, 'Ace of Base', 1987 },
18+
{ 4, box.NULL, 'The Beatles', 1960 },
19+
{ 5, box.NULL, 'Pink Floyd', 1965 },
20+
{ 6, box.NULL, 'The Rolling Stones', 1962 },
21+
{ 7, box.NULL, 'The Doors', 1965 },
22+
{ 8, box.NULL, 'Nirvana', 1987 },
23+
{ 9, box.NULL, 'Led Zeppelin', 1968 },
24+
{ 10, box.NULL, 'Queen', 1970 },
25+
})
26+
```
Lines changed: 60 additions & 0 deletions
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:3301'
35+
storage-a-002:
36+
iproto:
37+
listen:
38+
- uri: '127.0.0.1:3302'
39+
storage-b:
40+
leader: storage-b-001
41+
instances:
42+
storage-b-001:
43+
iproto:
44+
listen:
45+
- uri: '127.0.0.1:3303'
46+
storage-b-002:
47+
iproto:
48+
listen:
49+
- uri: '127.0.0.1:3304'
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:3300'
Lines changed: 5 additions & 0 deletions
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:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
local vshard = require('vshard')
2+
local crud = require('crud')
3+
local log = require('log')
4+
local fiber = require('fiber')
5+
6+
local M = {}
7+
8+
function M.validate()
9+
end
10+
11+
function M.bootstrap_f()
12+
for i = 1, 10 do
13+
local rc, err = vshard.router.bootstrap()
14+
log.info("Attempt to bootstrap vshard cluster")
15+
log.info(rc)
16+
if rc == nil then
17+
if string.find(tostring(err), "is already bootstrapped") ~= nil then
18+
break
19+
end
20+
log.info(err)
21+
end
22+
if rc ~= nil then
23+
break
24+
end
25+
fiber.sleep(1)
26+
end
27+
end
28+
29+
function M.apply(cfg)
30+
M.bootstrap_fiber = fiber.create(M.bootstrap_f, cfg)
31+
32+
crud.init_router()
33+
end
34+
35+
function M.stop()
36+
crud.stop_router()
37+
end
38+
39+
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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
30+

0 commit comments

Comments
 (0)