Skip to content

Commit 4b30f69

Browse files
committed
Migration tutorial draft
1 parent 0463c1c commit 4b30f69

File tree

2 files changed

+106
-54
lines changed

2 files changed

+106
-54
lines changed

doc/platform/ddl_dml/centralized_migrations_tt.rst

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ implemented in the Enterprise Edition of the :ref:`tt <tt-cli>` utility.
1010

1111
See also:
1212

13-
- :ref:`tt migrations <tt-migrations>` reference to see the full list of command-line options.
13+
- :ref:`tt migrations <tt-migrations>` for the full list of command-line options.
1414
- :ref:`tcm_cluster_migrations` to learn about managing migrations from |tcm_full_name|.
1515

1616
.. _centralized_migrations_tt_prereq:
@@ -46,7 +46,7 @@ First, start up an etcd instance to use as a configuration storage:
4646
4747
etcd runs on the default port 2379.
4848

49-
Optionally, you can enable etcd authentication by running the following script:
49+
Optionally, enable etcd authentication by executing the following script:
5050

5151
.. code-block:: bash
5252
@@ -93,17 +93,17 @@ Creating a cluster
9393
:language: yaml
9494
:dedent:
9595

96-
- ``app-scm-1.rockspec``:
96+
- ``myapp-scm-1.rockspec``:
9797

98-
.. literalinclude:: /code_snippets/snippets/migrations/instances.enabled/myapp/pp-scm-1.rockspec
98+
.. literalinclude:: /code_snippets/snippets/migrations/instances.enabled/myapp/myapp-scm-1.rockspec
9999
:dedent:
100100

101101
4. Create the ``source.yaml`` with a cluster configuration to publish to etcd:
102102

103103
.. note::
104104

105105
This configuration describes a typical CRUD-enabled sharded cluster with
106-
one router and two storages, each including one master and one read-only replica.
106+
one router and two storage replica sets, each including one master and one read-only replica.
107107

108108
.. literalinclude:: /code_snippets/snippets/migrations/instances.enabled/myapp/source.yaml
109109
:language: yaml
@@ -322,7 +322,7 @@ tuples into the space before proceeding to the next steps:
322322
The next migration changes the space format incompatibly: instead of one ``name``
323323
field, the new format includes two fields ``first_name`` and ``last_name``.
324324
To apply this migration, you need to change each tuple's structure preserving the stored
325-
data. The :ref:`space.upgrade <enterprise-space_upgrade>` helps with this task.
325+
data. The :ref:`space.upgrade <enterprise-space_upgrade>` function helps with this task.
326326

327327
Create a new file ``000003_alter_writers_space.lua`` in ``/migrations/scenario``.
328328
Prepare its initial structure the same way as in previous migrations:
@@ -370,7 +370,7 @@ as its arguments. Here is the complete migration code:
370370
:language: lua
371371
:dedent:
372372

373-
Learn more about ``space.upgrade()` execution in :ref:`enterprise-space_upgrade`.
373+
Learn more about ``space.upgrade()`` execution in :ref:`enterprise-space_upgrade`.
374374

375375
Publish the new migration to etcd. Migrations that already exist in the storage are skipped.
376376

@@ -392,7 +392,7 @@ Publish the new migration to etcd. Migrations that already exist in the storage
392392
393393
Apply the migrations:
394394

395-
.. code-block::
395+
.. code-block:: console
396396
397397
$ tt migrations apply http://app_user:config_pass@localhost:2379/myapp \
398398
--tarantool-username=client --tarantool-password=secret
@@ -414,12 +414,13 @@ Connect to the router instance and check that the space and its tuples have the
414414
415415
.. _centralized_migrations_tt_new_instances:
416416

417-
Applying migrations on new instances
418-
------------------------------------
417+
Extending the cluster
418+
---------------------
419419

420-
Having all migrations in a centralized etcd storage, you can apply
420+
Having all migrations in a centralized etcd storage, you can extend the cluster
421+
and consistently define the data schema on new instances on the fly.
421422

422-
To add one more storage, edit the cluster files in ``instances.enabled/myapp``:
423+
Add one more storage replica set to the cluster. To do this, edit the cluster files in ``instances.enabled/myapp``:
423424

424425
- ``instances.yml``: add the lines below to the end.
425426

@@ -430,7 +431,7 @@ To add one more storage, edit the cluster files in ``instances.enabled/myapp``:
430431

431432
- ``source.yaml``: add the lines below to the end.
432433

433-
.. literalinclude:: /code_snippets/snippets/migrations/instances.enabled/myapp/source-3-storages.yml
434+
.. literalinclude:: /code_snippets/snippets/migrations/instances.enabled/myapp/source-3-storages.yaml
434435
:language: yaml
435436
:start-at: storage-003:
436437
:dedent:
@@ -491,3 +492,40 @@ and check ``box.space.writers``:
491492
---
492493
- true
493494
...
495+
496+
.. _centralized_migrations_tt_troubleshoot:
497+
498+
Troubleshooting migrations
499+
--------------------------
500+
501+
.. warning::
502+
503+
The options used for migration troubleshooting can cause migration inconsistency in the cluster.
504+
505+
Incorrect migration published
506+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507+
508+
Problem: an incorrect migration is published to etcd.
509+
Solution: fix the migration file and publish it again with the ``--overwrite`` option:
510+
511+
.. code-block:: console
512+
513+
$ tt migrations publish http://app_user:config_pass@localhost:2379/myapp --overwrite
514+
515+
If there are several migrations and the erroneous one isn't the last, add also ``--ignore-order-violation``:
516+
517+
.. code-block:: console
518+
519+
$ tt migrations publish http://app_user:config_pass@localhost:2379/myapp --overwrite --ignore-order-violation
520+
521+
Incorrect migration applied
522+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
523+
524+
If the migration is already applied, publish the fixed version and apply it with
525+
the ``--force-reapply`` option:
526+
527+
.. code-block:: console
528+
529+
$ tt migrations apply http://app_user:config_pass@localhost:2379/myapp \
530+
--tarantool-username=client --tarantool-password=secret \
531+
--force-reapply

doc/tooling/tt_cli/migrations.rst

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Managing centralized migrations
1212
1313
$ tt migrations COMMAND [COMMAND_OPTION ...]
1414
15-
``tt migrations`` manages :ref:`centralized migrations <centralized_migrations_tt>` in a Tarantool EE cluster.
16-
See :ref:`centralized_migrations_tt` for a detailed guide on using centralized migrations.
15+
``tt migrations`` manages :ref:`centralized migrations <centralized_migrations_tt>`
16+
in a Tarantool EE cluster. See :ref:`centralized_migrations_tt` for a detailed guide
17+
on using the centralized migrations mechanism.
1718

1819
.. important::
1920

@@ -37,32 +38,32 @@ apply
3738
3839
$ tt migrations apply ETCD_URI [OPTION ...]
3940
40-
``tt migrations apply`` applies migrations :ref:`published <tt-migrations-publish>`
41-
to the cluster to the cluster. It executes all migrations from the cluster's centralized
41+
``tt migrations apply`` applies :ref:`published <tt-migrations-publish>` migrations
42+
to the cluster. It executes all migrations from the cluster's centralized
4243
configuration storage on all its read-write instances (replica set leaders).
4344

4445
.. code-block:: console
4546
4647
tt migrations apply https://user:pass@localhost:2379/myapp \
4748
-tarantool-username=admin --tarantool-password=pass
4849
49-
You can select a single migration for execution by adding the ``--migration`` option:
50+
To apply a single published migration, pass its name in the ``--migration`` option:
5051

5152
.. code-block:: console
5253
5354
tt migrations apply https://user:pass@localhost:2379/myapp \
5455
--tarantool-username=admin --tarantool-password=pass \
5556
--migration=000001_create_space.lua
5657
57-
You can select a single replica set to apply migrations to:
58+
To apply migrations on a single replica set, specify the ``replicaset`` option:
5859

5960
.. code-block:: console
6061
6162
tt migrations apply https://user:pass@localhost:2379/myapp \
6263
--tarantool-username=admin --tarantool-password=pass \
6364
--replicaset=storage-001
6465
65-
-- migration - single migration. --order violation
66+
--order violation
6667

6768

6869
?? diff --force-reapply --ignore-preceding-status
@@ -101,14 +102,14 @@ To publish a single migration from a file, use its name or path as the command a
101102
102103
$ tt migrations publish https://user:pass@localhost:2379/myapp migrations/000001_create_space.lua
103104
104-
Optionally, you can provide a key to use as a migration identifier instead of the file name:
105+
Optionally, you can provide a key to use as a migration identifier instead of the filename:
105106

106107
.. code-block:: console
107108
108109
$ tt migrations publish https://user:pass@localhost:2379/myapp file.lua \
109110
--key=000001_create_space.lua
110111
111-
When publishing migrations, ``tt`` performs several checks for:
112+
When publishing migrations, ``tt`` performs checks for:
112113

113114
- Syntax errors in migration files. To skip syntax check, add the ``--skip-syntax-check`` option.
114115
- Existence of migrations with same names. To overwrite an existing migration with
@@ -246,7 +247,7 @@ stop
246247
247248
$ tt migrations stop ETCD_URI [OPTION ...]
248249
249-
``tt migrations stop`` stops the execution of migrations in the cluster
250+
``tt migrations stop`` stops the execution of migrations in the cluster.
250251

251252
.. warning::
252253

@@ -284,15 +285,12 @@ If the cluster uses SSL traffic encryption, provide the necessary connection
284285
parameters in the ``--tarantool-ssl*`` options: ``--tarantool-sslcertfile``,
285286
``--tarantool-sslkeyfile``, and other. All options are listed in :ref:`tt-migrations-options`.
286287

287-
?auth type
288-
?example
289-
290288
.. _tt-migrations-options:
291289

292290
Options
293291
-------
294292

295-
.. option:: --acquire-lock-timeout int
293+
.. option:: --acquire-lock-timeout INT
296294

297295
**Applicable to:** ``apply``
298296

@@ -321,7 +319,7 @@ Options
321319

322320
See also: :ref:`tt-migrations-status`.
323321

324-
.. option:: --execution-timeout int
322+
.. option:: --execution-timeout INT
325323

326324
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
327325

@@ -359,21 +357,29 @@ Options
359357

360358
**Applicable to:** ``apply``, ``publish``
361359

362-
Skip migration scenarios order check before publish. Using this flag may result in cluster migrations inconsistency
360+
Skip migration scenarios order check before publish.
361+
362+
.. warning::
363+
364+
Using this option may result in cluster migrations inconsistency.
363365

364366
.. option:: --ignore-preceding-status
365367

366368
**Applicable to:** ``apply``
367369

368-
skip preceding migrations status check on apply. Using this flag may result in cluster migrations inconsistency
370+
Skip preceding migrations status check on apply.
371+
372+
.. warning::
373+
374+
Using this option may result in cluster migrations inconsistency.
369375

370376
.. option:: --key STRING
371377

372378
**Applicable to:** ``publish``
373379

374380
put scenario to /<prefix>/migrations/scenario/<key> etcd key instead. Only for single file publish
375381

376-
.. option:: --migration string
382+
.. option:: --migration STRING
377383

378384
**Applicable to:** ``apply``, ``remove``, ``status``
379385

@@ -383,9 +389,13 @@ Options
383389

384390
**Applicable to:** ``publish``
385391

386-
overwrite existing migration storage keys. Using this flag may result in cluster migrations inconsistency
392+
overwrite existing migration storage keys.
393+
394+
.. warning::
395+
396+
Using this option may result in cluster migrations inconsistency.
387397

388-
.. option:: --replicaset string
398+
.. option:: --replicaset STRING
389399

390400
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
391401

@@ -395,69 +405,73 @@ Options
395405

396406
**Applicable to:** ``publish``
397407

398-
Skip syntax check before publish. Using this flag may cause other tt migrations operations to fail
408+
Skip syntax check before publish.
409+
410+
.. warning::
411+
412+
Using this option may cause further ``tt migrations`` calls to fail.
399413

400-
.. option:: --tarantool-auth string
414+
.. option:: --tarantool-auth STRING
401415

402416
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
403417

404-
authentication type (used only to connect to Tarantool cluster instances)
418+
Authentication type used to connect to the cluster instances.
405419

406-
.. option:: --tarantool-connect-timeout int
420+
.. option:: --tarantool-connect-timeout INT
407421

408422
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
409423

410-
Tarantool cluster instances connection timeout,in seconds. Default: 3.
424+
Tarantool cluster instances connection timeout, in seconds. Default: 3.
411425

412-
.. option:: --tarantool-password string
426+
.. option:: --tarantool-password STRING
413427

414428
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
415429

416-
A password used for connecting to the Tarantool cluster instances.
430+
A password used to connect to the cluster instances.
417431

418-
.. option:: --tarantool-sslcafile string
432+
.. option:: --tarantool-sslcafile STRING
419433

420434
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
421435

422-
SSL CA file (used only to connect to Tarantool cluster instances)
436+
SSL CA file used to connect to the cluster instances.
423437

424-
.. option:: --tarantool-sslcertfile string
438+
.. option:: --tarantool-sslcertfile STRING
425439

426440
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
427441

428-
SSL cert file (used only to connect to Tarantool cluster instances)
442+
SSL cert file used to connect to the cluster instances.
429443

430-
.. option:: --tarantool-sslciphers string
444+
.. option:: --tarantool-sslciphers STRING
431445

432446
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
433447

434-
Colon-separated list of SSL ciphers (used only to connect to Tarantool cluster instances)
448+
Colon-separated list of SSL ciphers used to connect to the cluster instances.
435449

436-
.. option:: --tarantool-sslkeyfile string
450+
.. option:: --tarantool-sslkeyfile STRING
437451

438452
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
439453

440-
SSL key file (used only to connect to Tarantool cluster instances)
454+
SSL key file used to connect to the cluster instances.
441455

442-
.. option:: --tarantool-sslpassword string
456+
.. option:: --tarantool-sslpassword STRING
443457

444458
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
445459

446-
SSL key file password (used only to connect to Tarantool cluster instances)
460+
SSL key file password used to connect to the cluster instances.
447461

448-
.. option:: --tarantool-sslpasswordfile string
462+
.. option:: --tarantool-sslpasswordfile STRING
449463

450464
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
451465

452-
File with list of password to SSL key file (used only to connect to Tarantool cluster instances)
466+
File with list of password to SSL key file used to connect to the cluster instances.
453467

454468
.. option:: --tarantool-use-ssl
455469

456470
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
457471

458-
use SSL without providing any additional SSL info (used only to connect to Tarantool cluster instances)
472+
Whether SSL is used to connect to the cluster instances.
459473

460-
.. option:: --tarantool-username string
474+
.. option:: --tarantool-username STRING
461475

462476
**Applicable to:** ``apply``, ``remove``, ``status``, ``stop``
463477

0 commit comments

Comments
 (0)