Skip to content

Commit 8e0247d

Browse files
committed
Sharding config
1 parent 5d06f39 commit 8e0247d

File tree

9 files changed

+375
-330
lines changed

9 files changed

+375
-330
lines changed

doc/book/admin/vshard_admin.rst

Lines changed: 293 additions & 244 deletions
Large diffs are not rendered by default.

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
box.schema.create_space('bands', {
2-
format = {
3-
{ name = 'id', type = 'unsigned' },
4-
{ name = 'bucket_id', type = 'unsigned' },
5-
{ name = 'band_name', type = 'string' },
6-
{ name = 'year', type = 'unsigned' }
7-
},
8-
if_not_exists = true
9-
})
10-
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
11-
box.space.bands:create_index('bucket_id', { parts = { 'bucket_id' }, unique = false, if_not_exists = true })
1+
box.once('bands', function()
2+
box.schema.create_space('bands', {
3+
format = {
4+
{ name = 'id', type = 'unsigned' },
5+
{ name = 'bucket_id', type = 'unsigned' },
6+
{ name = 'band_name', type = 'string' },
7+
{ name = 'year', type = 'unsigned' }
8+
},
9+
if_not_exists = true
10+
})
11+
box.space.bands:create_index('id', { parts = { 'id' }, if_not_exists = true })
12+
box.space.bands:create_index('bucket_id', { parts = { 'bucket_id' }, unique = false, if_not_exists = true })
13+
end)
1214

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

doc/concepts/sharding/vshard_architecture.rst

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,10 @@ buckets.
7070
Each replica set stores a unique subset of buckets. One bucket cannot belong to
7171
multiple replica sets at a time.
7272

73-
The total number of buckets is determined by the administrator who sets up the
74-
initial cluster configuration.
73+
The total :ref:`number of buckets <vshard_config_bucket_count>` is determined by the administrator who sets up the initial cluster configuration.
7574

7675
Every space you plan to shard must have a numeric field containing bucket id-s.
77-
This field must comply with the following requirements:
78-
79-
* The field's data type can be: unsigned, number or integer.
80-
* The field must be not nullable.
81-
* The field must be indexed by the :ref:`shard_index <cfg_basic-shard_index>`.
82-
The default name for this index is ``bucket_id``.
83-
84-
See the :ref:`configuration example <vshard-define-spaces>`.
76+
You can learn more from :ref:`vshard-define-spaces`.
8577

8678
.. _vshard-structure:
8779

@@ -90,9 +82,16 @@ Structure
9082

9183
A sharded cluster in Tarantool consists of:
9284

93-
* storages,
94-
* routers,
95-
* and a rebalancer.
85+
* One or more replica sets.
86+
87+
Each replica set should contain at least two storage instances.
88+
For redundancy, it is recommended to have 3 or more storage instances in a replica set.
89+
90+
* One or more router instances.
91+
92+
The number of router instances is not limited and should be increased if the existing router instances become CPU or I/O bound.
93+
94+
* Rebalancer.
9695

9796
.. image:: schema.svg
9897
:align: center
@@ -231,8 +230,7 @@ While a bucket is being migrated, it can have different states:
231230
* RECEIVING – the bucket is currently being filled; all requests to it are rejected.
232231
* SENT – the bucket was migrated to the destination replica set. The `router`
233232
uses the SENT state to calculate the new location of the bucket. A bucket in
234-
the SENT state goes to the GARBAGE state automatically after BUCKET_SENT_GARBAGE_DELAY
235-
seconds, which by default is :ref:`0.5 seconds <cfg_basic-collect_bucket_garbage_interval>`.
233+
the SENT state goes to the GARBAGE state automatically after 0.5 seconds.
236234
* GARBAGE – the bucket was already migrated to the destination replica set during
237235
rebalancing; or the bucket was initially in the RECEIVING state, but some error
238236
occurred during the migration.

doc/how-to/vshard_quick.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,34 +217,28 @@ The resulting ``config.yaml`` file should look as follows:
217217
Adding storage code
218218
~~~~~~~~~~~~~~~~~~~
219219

220-
1. Open the ``storage.lua`` file and create a space using the :ref:`box.schema.space.create() <box_schema-space_create>` function:
220+
1. Open the ``storage.lua`` file and define a space and indexes inside :ref:`box.once() <box-once>`:
221221

222222
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/storage.lua
223223
:language: lua
224-
:start-at: box.schema.create_space
225-
:end-before: box.space.bands:create_index('id'
224+
:start-at: box.once
225+
:end-before: function insert_band
226226
:dedent:
227227

228-
Note that the created ``bands`` spaces includes the ``bucket_id`` field.
229-
This field represents a sharding key used to partition a dataset across different storage instances.
228+
* The :ref:`box.schema.create_space() <box_schema-space_create>` function is used to create a space.
229+
Note that the created ``bands`` spaces includes the ``bucket_id`` field.
230+
This field represents a sharding key used to partition a dataset across different storage instances.
231+
* :ref:`space_object:create_index() <box_space-create_index>` is used to create two indexes based on the ``id`` and ``bucket_id`` fields.
230232

231-
2. Create two indexes based on the ``id`` and ``bucket_id`` fields:
232-
233-
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/storage.lua
234-
:language: lua
235-
:start-at: box.space.bands:create_index('id'
236-
:end-at: box.space.bands:create_index('bucket_id'
237-
:dedent:
238-
239-
3. Define the ``insert_band`` function that inserts a tuple into the created space:
233+
2. Define the ``insert_band`` function that inserts a tuple into the created space:
240234

241235
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/storage.lua
242236
:language: lua
243237
:start-at: function insert_band
244238
:end-before: function get_band
245239
:dedent:
246240

247-
4. Define the ``get_band`` function that returns data without the ``bucket_id`` value:
241+
3. Define the ``get_band`` function that returns data without the ``bucket_id`` value:
248242

249243
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/storage.lua
250244
:language: lua

doc/reference/configuration/configuration_reference.rst

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,11 +3140,13 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
31403140
- :ref:`sharding.rebalancer_disbalance_threshold <configuration_reference_sharding_rebalancer_disbalance_threshold>`
31413141
- :ref:`sharding.rebalancer_max_receiving <configuration_reference_sharding_rebalancer_max_receiving>`
31423142
- :ref:`sharding.rebalancer_max_sending <configuration_reference_sharding_rebalancer_max_sending>`
3143+
- :ref:`sharding.rebalancer_mode <configuration_reference_sharding_rebalancer_mode>`
31433144
- :ref:`sharding.roles <configuration_reference_sharding_roles>`
31443145
- :ref:`sharding.sched_move_quota <configuration_reference_sharding_sched_move_quota>`
31453146
- :ref:`sharding.sched_ref_quota <configuration_reference_sharding_sched_ref_quota>`
31463147
- :ref:`sharding.shard_index <configuration_reference_sharding_shard_index>`
31473148
- :ref:`sharding.sync_timeout <configuration_reference_sharding_sync_timeout>`
3149+
- :ref:`sharding.weight <configuration_reference_sharding_weight>`
31483150
- :ref:`sharding.zone <configuration_reference_sharding_zone>`
31493151

31503152

@@ -3154,14 +3156,7 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
31543156
.. confval:: sharding.bucket_count
31553157

31563158
The total number of buckets in a cluster.
3157-
3158-
``sharding.bucket_count`` should be several orders of magnitude larger than the potential number of cluster nodes, considering potential scaling out in the future.
3159-
3160-
If the estimated number of nodes in a cluster is M, then the data set should be divided into 100M or even 1000M buckets, depending on the planned scaling out.
3161-
This number is greater than the potential number of cluster nodes in the system being designed.
3162-
3163-
Keep in mind that too many buckets can cause a need to allocate more memory to store routing information.
3164-
On the other hand, an insufficient number of buckets can lead to decreased granularity when :ref:`rebalancing <vshard-rebalancing>`.
3159+
Learn more in :ref:`vshard_config_bucket_count`.
31653160

31663161
.. NOTE::
31673162

@@ -3180,22 +3175,6 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
31803175
| Default: 3000
31813176
| Environment variable: TT_SHARDING_BUCKET_COUNT
31823177
3183-
.. TODO: Remove - for internal use
3184-
.. _configuration_reference_sharding_connection_outdate_delay:
3185-
3186-
.. confval:: sharding.connection_outdate_delay
3187-
3188-
The delay (in seconds) to outdate old replica set and replica objects after reconfiguration.
3189-
3190-
.. NOTE::
3191-
3192-
This option should be defined at the :ref:`global level <configuration_scopes>`.
3193-
3194-
|
3195-
| Type: number
3196-
| Default: nil
3197-
| Environment variable: TT_SHARDING_CONNECTION_OUTDATE_DELAY
3198-
31993178

32003179
.. _configuration_reference_sharding_discovery_mode:
32013180

@@ -3312,25 +3291,27 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
33123291
| Maximum: 15
33133292
| Environment variable: TT_SHARDING_REBALANCER_MAX_SENDING
33143293
3315-
.. TODO: https://github.com/tarantool/doc/issues/3865
3316-
.. _configuration_reference_sharding_rebalancer_mode:
33173294

3318-
.. confval:: sharding.rebalancer_mode
3295+
.. _configuration_reference_sharding_rebalancer_mode:
33193296

3320-
[TODO] A rebalancer mode:
3297+
.. confval:: sharding.rebalancer_mode
33213298

3322-
* ``manual``
3323-
* ``auto``
3324-
* ``off``
3299+
**Since:** :doc:`3.1.0 </release/3.1.0>`.
33253300

3326-
.. NOTE::
3301+
Configure how a rebalancer is selected:
33273302

3328-
This option should be defined at the :ref:`global level <configuration_scopes>`.
3303+
* ``auto`` (default): if there are no replica sets with the ``rebalancer`` sharding role (:ref:`sharding.roles <configuration_reference_sharding_roles>`), a replica set with the rebalancer is selected automatically among all replica sets.
3304+
* ``manual``: one of the replica sets should have the ``rebalancer`` sharding role. The rebalancer is in this replica set.
3305+
* ``off``: rebalancing is turned off regardless of whether a replica set with the ``rebalancer`` sharding role exists or not.
33293306

3330-
|
3331-
| Type: string
3332-
| Default: 'auto'
3333-
| Environment variable: TT_SHARDING_REBALANCER_MODE
3307+
.. NOTE::
3308+
3309+
This option should be defined at the :ref:`global level <configuration_scopes>`.
3310+
3311+
|
3312+
| Type: string
3313+
| Default: 'auto'
3314+
| Environment variable: TT_SHARDING_REBALANCER_MODE
33343315
33353316

33363317
.. _configuration_reference_sharding_roles:
@@ -3359,6 +3340,8 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
33593340
sharding:
33603341
roles: [storage, rebalancer]
33613342
3343+
See also: :ref:`vshard_config_sharding_roles`
3344+
33623345
.. NOTE::
33633346

33643347
``sharding.roles`` can be specified at the :ref:`replica set level <configuration_scopes>` or higher.
@@ -3425,6 +3408,8 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
34253408

34263409
This option should be defined at the :ref:`global level <configuration_scopes>`.
34273410

3411+
See also: :ref:`vshard-define-spaces`
3412+
34283413
|
34293414
| Type: string
34303415
| Default: 'bucket_id'
@@ -3448,11 +3433,30 @@ The ``sharding`` section defines configuration parameters related to :ref:`shard
34483433
| Environment variable: TT_SHARDING_SYNC_TIMEOUT
34493434
34503435

3436+
.. _configuration_reference_sharding_weight:
3437+
3438+
.. confval:: sharding.weight
3439+
3440+
**Since:** :doc:`3.1.0 </release/3.1.0>`.
3441+
3442+
The relative amount of data that a replica set can store.
3443+
Learn more at :ref:`vshard-replica-set-weights`.
3444+
3445+
.. NOTE::
3446+
3447+
``sharding.weight`` can be specified at the :ref:`replica set level <configuration_scopes>`.
3448+
3449+
|
3450+
| Type: number
3451+
| Default: 1
3452+
| Environment variable: TT_SHARDING_WEIGHT
3453+
3454+
34513455
.. _configuration_reference_sharding_zone:
34523456

34533457
.. confval:: sharding.zone
34543458

3455-
A :ref:`zone <vshard-replica-weights>` that can be set for routers and replicas.
3459+
A zone that can be set for routers and replicas.
34563460
This allows sending read-only requests not only to a master instance but to any available replica that is the nearest to the router.
34573461

34583462
.. NOTE::

doc/reference/reference_lua/box_once.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
been executed before, nothing happens. If it has not been executed before,
1212
the function is invoked.
1313

14-
See an example of using ``box.once()`` while
15-
:ref:`bootstrapping a replica set <replication-bootstrap>`.
14+
See an example of using ``box.once()`` in :ref:`vshard-quick-start-storage-code`.
1615

1716
**Warning:** If an error occurs inside ``box.once()`` when initializing a
1817
database, you can re-execute the failed ``box.once()`` block without

doc/reference/reference_rock/vshard/vshard_ref.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Basic parameters
4343
.. confval:: weights
4444

4545
A field defining the configuration of relative weights for each zone pair in a
46-
replica set. See the :ref:`Replica weights <vshard-replica-weights>` section.
46+
replica set.
4747

4848
| Type: table
4949
| Default: false

locale/en/reference/reference_rock/vshard/vshard_ref.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ msgid "Dynamic: yes"
9696
msgstr ""
9797

9898
#: ../../doc/reference/reference_rock/vshard/vshard_ref.rst:39
99-
msgid "A field defining the configuration of relative weights for each zone pair in a replica set. See the :ref:`Replica weights <vshard-replica-weights>` section."
99+
msgid "A field defining the configuration of relative weights for each zone pair in a replica set."
100100
msgstr ""
101101

102102
#: ../../doc/reference/reference_rock/vshard/vshard_ref.rst:50

locale/ru/LC_MESSAGES/reference/reference_rock/vshard/vshard_ref.po

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ msgstr "Динамический: да"
6363

6464
msgid ""
6565
"A field defining the configuration of relative weights for each zone pair in"
66-
" a replica set. See the :ref:`Replica weights <vshard-replica-weights>` "
67-
"section."
66+
" a replica set."
6867
msgstr ""
6968
"Поле, которое определяет конфигурацию относительного веса для каждой пары "
70-
"зон в наборе реплик. См. раздел :ref:`Вес реплики <vshard-replica-weights>`."
69+
"зон в наборе реплик."
7170

7271
msgid ""
7372
"Name or id of a TREE index over the :ref:`bucket id <vshard-vbuckets>`. "

0 commit comments

Comments
 (0)