Skip to content

Commit fa26dc6

Browse files
Sharding get started (#4042)
1 parent cf763a2 commit fa26dc6

File tree

5 files changed

+509
-199
lines changed

5 files changed

+509
-199
lines changed
Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,10 @@
11
# Sharded cluster
22

3-
A sample application demonstrating how to configure a [sharded](https://www.tarantool.io/en/doc/latest/concepts/sharding/) cluster.
3+
A sample application created in the [Creating a sharded cluster](https://www.tarantool.io/en/doc/latest/how-to/vshard_quick/) tutorial.
44

55
## Running
66

7-
To run the cluster, go to the `sharding` directory in the terminal and perform the following steps:
8-
9-
1. Install dependencies defined in the `*.rockspec` file:
10-
11-
```console
12-
$ tt build sharded_cluster
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. Perform the initial cluster bootstrap:
28-
29-
```console
30-
sharded_cluster:router-a-001> require('vshard').router.bootstrap()
31-
---
32-
- true
33-
...
34-
```
35-
36-
5. Insert test data:
37-
38-
```console
39-
sharded_cluster:router-a-001> insert_data()
40-
---
41-
...
42-
```
43-
44-
6. Connect to storages in different replica sets to see how data is distributed across nodes:
45-
46-
a. `storage-a-001`:
47-
48-
```console
49-
sharded_cluster:storage-a-001> box.space.bands:select()
50-
---
51-
- - [1, 614, 'Roxette', 1986]
52-
- [2, 986, 'Scorpions', 1965]
53-
- [5, 755, 'Pink Floyd', 1965]
54-
- [7, 998, 'The Doors', 1965]
55-
- [8, 762, 'Nirvana', 1987]
56-
...
57-
```
58-
59-
b. `storage-b-001`:
60-
61-
```console
62-
sharded_cluster:storage-b-001> box.space.bands:select()
63-
---
64-
- - [3, 11, 'Ace of Base', 1987]
65-
- [4, 42, 'The Beatles', 1960]
66-
- [6, 55, 'The Rolling Stones', 1962]
67-
- [9, 299, 'Led Zeppelin', 1968]
68-
- [10, 167, 'Queen', 1970]
69-
...
70-
```
7+
To learn how to run the cluster, see the [Working with the cluster](https://www.tarantool.io/en/doc/latest/how-to/vshard_quick/#working-with-the-cluster) section.
718

729

7310
## Packaging
@@ -77,5 +14,3 @@ To package an application into a `.tgz` archive, use the `tt pack` command:
7714
```console
7815
$ tt pack tgz --app-list sharded_cluster
7916
```
80-
81-
Note that the necessary `vshard` dependency is specified in the [sharded_cluster-scm-1.rockspec](sharded_cluster-scm-1.rockspec) file.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ local vshard = require('vshard')
22

33
function put(id, band_name, year)
44
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
5-
vshard.router.callrw(bucket_id, 'put', { id, bucket_id, band_name, year })
5+
vshard.router.callrw(bucket_id, 'insert_band', { id, bucket_id, band_name, year })
66
end
77

88
function get(id)
99
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
10-
return vshard.router.callro(bucket_id, 'get', { id })
10+
return vshard.router.callro(bucket_id, 'get_band', { id })
1111
end
1212

1313
function insert_data()

doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster/sharded_cluster-scm-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source = {
55
}
66

77
dependencies = {
8-
'vshard == 0.1.25'
8+
'vshard == 0.1.26'
99
}
1010
build = {
1111
type = 'none';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ box.schema.create_space('bands', {
1010
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
1111
box.space.bands:create_index('bucket_id', { parts = { 'id' }, unique = false, if_not_exists = true })
1212

13-
function put(id, bucket_id, band_name, year)
13+
function insert_band(id, bucket_id, band_name, year)
1414
box.space.bands:insert({ id, bucket_id, band_name, year })
1515
end
1616

17-
function get(id)
17+
function get_band(id)
1818
local tuple = box.space.bands:get(id)
1919
if tuple == nil then
2020
return nil

0 commit comments

Comments
 (0)