Skip to content

Sharding get started #4042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,73 +1,10 @@
# Sharded cluster

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

## Running

To run the cluster, go to the `sharding` directory in the terminal and perform the following steps:

1. Install dependencies defined in the `*.rockspec` file:

```console
$ tt build sharded_cluster
```

2. Run the cluster:

```console
$ tt start sharded_cluster
```

3. Connect to the router:

```console
$ tt connect sharded_cluster:router-a-001
```

4. Perform the initial cluster bootstrap:

```console
sharded_cluster:router-a-001> require('vshard').router.bootstrap()
---
- true
...
```

5. Insert test data:

```console
sharded_cluster:router-a-001> insert_data()
---
...
```

6. Connect to storages in different replica sets to see how data is distributed across nodes:

a. `storage-a-001`:

```console
sharded_cluster:storage-a-001> box.space.bands:select()
---
- - [1, 614, 'Roxette', 1986]
- [2, 986, 'Scorpions', 1965]
- [5, 755, 'Pink Floyd', 1965]
- [7, 998, 'The Doors', 1965]
- [8, 762, 'Nirvana', 1987]
...
```

b. `storage-b-001`:

```console
sharded_cluster:storage-b-001> box.space.bands:select()
---
- - [3, 11, 'Ace of Base', 1987]
- [4, 42, 'The Beatles', 1960]
- [6, 55, 'The Rolling Stones', 1962]
- [9, 299, 'Led Zeppelin', 1968]
- [10, 167, 'Queen', 1970]
...
```
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.


## Packaging
Expand All @@ -77,5 +14,3 @@ To package an application into a `.tgz` archive, use the `tt pack` command:
```console
$ tt pack tgz --app-list sharded_cluster
```

Note that the necessary `vshard` dependency is specified in the [sharded_cluster-scm-1.rockspec](sharded_cluster-scm-1.rockspec) file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ local vshard = require('vshard')

function put(id, band_name, year)
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
vshard.router.callrw(bucket_id, 'put', { id, bucket_id, band_name, year })
vshard.router.callrw(bucket_id, 'insert_band', { id, bucket_id, band_name, year })
end

function get(id)
local bucket_id = vshard.router.bucket_id_mpcrc32({ id })
return vshard.router.callro(bucket_id, 'get', { id })
return vshard.router.callro(bucket_id, 'get_band', { id })
end

function insert_data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source = {
}

dependencies = {
'vshard == 0.1.25'
'vshard == 0.1.26'
}
build = {
type = 'none';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ box.schema.create_space('bands', {
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
box.space.bands:create_index('bucket_id', { parts = { 'id' }, unique = false, if_not_exists = true })

function put(id, bucket_id, band_name, year)
function insert_band(id, bucket_id, band_name, year)
box.space.bands:insert({ id, bucket_id, band_name, year })
end

function get(id)
function get_band(id)
local tuple = box.space.bands:get(id)
if tuple == nil then
return nil
Expand Down
Loading