forked from mongodb/docs-cluster-to-cluster-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.txt
490 lines (333 loc) · 12.9 KB
/
start.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
.. _c2c-api-start:
=========
``start``
=========
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Description
-----------
Starts the synchronization between a source and destination cluster.
Requirements
------------
State
~~~~~
To use the ``start`` endpoint, ``mongosync`` must be in the ``IDLE``
state.
Permissions
~~~~~~~~~~~
The user specified in the ``mongosync`` connection string must have the
required permissions on the source and destination clusters. Refer to
:ref:`c2c-permissions-and-roles` to ensure that the user has the correct
permissions to start the synchronization.
Multiple ``mongosync`` Instances
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ensure that you use the configured ``mongosync`` user in the connection
strings for the :setting:`cluster0` or :setting:`cluster1` settings when
you start ``mongosync``.
.. note::
.. include:: /includes/api/facts/multiple-mongosync-endpoints
For more information, see :ref:`Start Multiple Mongosyncs
<c2c-sharded-start>`.
Request
-------
.. code-block:: http
:copyable: false
POST /api/v1/start
Request Body Parameters
~~~~~~~~~~~~~~~~~~~~~~~
.. list-table::
:header-rows: 1
:stub-columns: 1
:widths: 20 13 13 54
* - Parameter
- Type
- Necessity
- Description
* - ``source``
- string
- Required
- Name of the source cluster.
* - ``destination``
- string
- Required
- Name of the destination cluster.
* - ``buildIndexes``
- string
- Optional
- Configures index builds during sync.
Supported Options:
- ``beforeDataCopy`` (the default) causes ``mongosync`` to build indexes
on the destination cluster. These include both existing indexes and
any indexes created during migration on the source cluster.
- ``never`` causes ``mongosync`` to skip building unnecessary indexes
during sync. This can improve migration performance, especially with
index heavy workloads.
.. warning::
Do **not** manually build indexes while ``mongosync`` is
performing a migration. Wait until the migration is fully
committed.
For more information on the indexes it does build, see
:ref:`c2c-required-indexes`.
``/start`` returns an error when ``buildIndexes`` is set to ``never``
and ``reversible`` is set to ``true``.
If you call ``/start`` without specifying the ``buildIndexes`` option,
``mongosync`` builds indexes on the destination cluster.
.. versionadded:: 1.3.0
* - ``documentFilter``
- document
- Optional
- .. important::
This feature is only available in the :ref:`c2c-beta-program`.
.. include:: /includes/document-filtering-intro.rst
To learn more, see :ref:`c2c-beta-document-filtering`.
.. versionadded:: 1.8 Beta
* - ``enableUserWriteBlocking``
- boolean
- Optional
- If set to ``true``, blocks writes on the destination cluster
while the synchronization is in progress. After the
synchronization is committed to the destination cluster, the
original source cluster blocks writes and the destination cluster
accepts writes.
To reverse sync, the ``enableUserWriteBlocking`` field must be set
to ``true``. To allow the source cluster to accept writes again,
for example after running migration tests, run the following
command:
.. code-block:: shell
db.adminCommand( { setUserWriteBlockMode: 1, global: false } )
Default value is ``false``.
* - ``includeNamespaces``
- array
- Optional
- Filters the databases or collections to include in sync.
.. include:: /includes/api/facts/namespace-explanation.rst
.. versionadded:: 1.1
* - ``excludeNamespaces``
- array
- Optional
- Filters the databases or collections to exclude from sync.
.. include:: /includes/api/facts/namespace-explanation.rst
.. versionadded:: 1.6
* - ``namespaceRemap``
- array
- Optional
- .. important::
This feature is only available in the :ref:`c2c-beta-program`.
Array of documents that specify namespace changes to make during sync.
For more information, see :ref:`c2c-beta-namespace-remapping`.
.. versionadded:: 1.8 Beta
* - ``reversible``
- boolean
- Optional
- If set to ``true``, enables the sync operation to be
reversed.
To reverse sync, the ``enableUserWriteBlocking`` field must be set
to ``true``.
This option is not supported for the following configurations:
* Sync from a replica set to a sharded cluster
* Sync sharded clusters that have different numbers of shards
* Reversible sync when ``buildIndexes`` is set to ``never``.
For more information, see the :ref:`reverse <c2c-api-reverse>` endpoint.
Default value is ``false``.
* - ``sharding``
- document
- Optional
- Configures sync between a replica set and sharded cluster.
Sync from a replica set to a sharded cluster requires this
option.
For more information, see :ref:`c2c-api-start-sharding`.
.. versionadded:: 1.1
.. _c2c-api-start-sharding:
Sharding Parameters
~~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
To sync from a replica set to a sharded cluster, set the
``sharding`` option to shard collections on the destination cluster.
The ``sharding`` option has the following parameters:
.. list-table::
:header-rows: 1
:stub-columns: 1
:widths: 15 15 70
* - Parameter
- Type
- Description
* - ``createSupportingIndexes``
- boolean
- Optional. Sets whether sync creates a supporting index
for the shard key, if none exists. Defaults to ``false``.
* - ``shardingEntries``
- array of documents
- Required. Sets the namespace and key of collections to shard
during sync.
Collections not included in this array sync to unsharded
collections on the destination cluster. If set with an empty
array, no collections are sharded.
* - | ``shardingEntries``
| ``.collection``
- string
- Sets the collection to shard.
* - | ``shardingEntries``
| ``.database``
- string
- Sets the database of the collection to shard.
* - | ``shardingEntries``
| ``.shardCollection``
- document
- Sets the shard key to generate on the destination cluster.
* - | ``shardingEntries``
| ``.shardCollection``
| ``.key``
- array
- Sets the fields to use for the shard key.
For more information, see :ref:`shard-key`.
``mongosync`` throws an error if the ``sharding`` option is not set when
syncing from a replica set to a sharded cluster. ``mongosync`` also
throws an error if the ``sharding`` option is set with any other
configuration.
Response
--------
.. include:: /includes/api/tables/basic-response.rst
Example: Start a Sync Job
-------------------------
.. include:: /includes/intro-start-api-example-intro.rst
Request
~~~~~~~
.. literalinclude:: /includes/api/requests/start.sh
:language: shell
Response
~~~~~~~~
.. literalinclude:: /includes/api/responses/success.json
:language: json
:copyable: false
Example: Start a Reversible Sync Job
------------------------------------
.. include:: /includes/intro-start-api-example-intro.rst
The ``reversible`` and ``enableUserWriteBlocking`` fields allow the sync
to be reversed. To reverse the sync direction, see: :ref:`reverse
<c2c-api-reverse>`.
Request
~~~~~~~
.. literalinclude:: /includes/api/requests/start-reversible.sh
:language: shell
Response
~~~~~~~~
.. literalinclude:: /includes/api/responses/success.json
:language: json
:copyable: false
Example: Start a Filtered Sync Job
----------------------------------
.. include:: /includes/example-filter-collection.rst
The ``includeNamespaces`` option creates a filter. To filter the sync,
see: :ref:`c2c-filtered-sync`
Request
~~~~~~~
.. literalinclude:: /includes/api/requests/start-filtered.sh
:language: shell
Response
~~~~~~~~
.. literalinclude:: /includes/api/responses/success.json
:language: json
:copyable: false
Example: Start Sync from Replica Set to Sharded Cluster
-------------------------------------------------------
Request
~~~~~~~
.. literalinclude:: /includes/api/requests/start-rs-shard.sh
Response
~~~~~~~~
.. literalinclude:: /includes/api/responses/success.json
:language: json
:copyable: false
Behavior
--------
State
~~~~~
If the ``start`` request is successful, ``mongosync`` enters the
``RUNNING`` state.
Pre-Split Chunks
~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
When ``mongosync`` syncs to a sharded cluster, it pre-splits chunks for
sharded collections on the destination cluster. This is supported in the
following configurations:
* Sync from a replica set to a sharded cluster.
* Sync between sharded clusters that differ in the number of shards.
Shard Replica Sets
~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
Sync from a replica set to a sharded cluster requires the
``sharding`` option. This option configures how ``mongosync`` shards
collections.
The ``sharding.shardEntries`` array specifies the collections to shard.
Collections that are not listed in this array replicate as unsharded.
Supporting Indexes
~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
``mongosync`` syncs indexes from the source cluster to the destination
cluster. But, when syncing from a replica set to a sharded cluster,
``mongosync`` may require an additional index to support the shard key,
which may not exist on the source cluster.
``mongosync`` can create supporting indexes for sharded collections during sync.
This is done by setting the ``sharding.createSupportingIndexes`` option.
When ``sharding.createSupportingIndexes`` is ``false`` (the default):
* Each shard key you provide for the ``sharding.shardEntries`` option
must have an existing index on the source cluster.
* One of the indexes used for the shard key must have simple collation if the
collection uses any other collation.
* To use a unique index in the shard key, you must specify its uniqueness when
you create the index on the source cluster.
* Unique indexes on the source cluster that are incompatible with the requested
shard key on the destination cluster, such as a unique index on the source
that does not contain the requested shard key as a prefix on the destination,
can cause ``mongosync`` to fail.
When ``sharding.createSupportingIndexes`` is ``true``:
* If the supporting indexes exist on the source cluster, ``mongosync``
syncs the indexes to the destination cluster and uses them
as shard keys.
* If the supporting indexes don't exist, ``mongosync`` creates them on the
destination cluster.
The ``sharding.createSupportingIndexes`` option affects all sharded
collections.
.. _rename-during-sync:
Rename During Sync
~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
Collections listed in the ``sharding.shardEntries`` array
when synced from a replica set to a sharded cluster
become sharded collections on the destination cluster.
Renaming a collection (such as with the :dbcommand:`renameCollection` command)
on the source cluster after calling ``start`` but before ``mongosync`` begins
to copy the collection can block the collection from sharding on the destination.
.. note::
Renaming collections to use a different database while syncing from a
replica set to a sharded cluster is not supported.
To check whether it is safe to rename collections, call the
:ref:`c2c-api-progress` endpoint and check the value of the
``collectionCopy.estimatedCopiedBytes`` field in the return document.
* A value of 0 indicates that ``mongosync`` has not started to copy the
collection.
Renaming a collection at this point may result in an unsharded collection
on the destination cluster, as the transition to copying can happen before
the rename takes effect on the source.
* A value greater than 0 indicates that ``mongosync`` has started the copy.
Renaming the collection from this point on does not block
its sharding on the destination cluster, even in the event of a crash.
.. _c2c-required-indexes:
Required Indexes
~~~~~~~~~~~~~~~~
When you call ``/start`` with the ``buildIndexes`` option set to ``never``,
``mongosync`` skips building unnecessary indexes.
Indexes that are always built include:
* ``mongosync`` builds an index on the ``_id`` field of every
collection it copies.
* ``mongosync`` builds dummy indexes that support the shard key for each
sharded collection, which are removed after commit. When ``buildIndexes`` is
set to ``never``, ``mongosync`` retains this index after commit.
Endpoint Protection
~~~~~~~~~~~~~~~~~~~
.. |endpoint| replace:: ``start``
.. include:: /includes/fact-api-endpoint