@@ -94,12 +94,30 @@ Request Body Parameters
94
94
* - ``reversible``
95
95
- boolean
96
96
- Optional
97
- - If set to ``true``, enables the synchronization operation to be
98
- reversed. For more information, see the :ref:`reverse
99
- <c2c-api-reverse>` endpoint.
97
+ - If set to ``true``, enables the sync operation to be
98
+ reversed.
99
+
100
+ This option is not supported for the following configurations:
101
+
102
+ * Sync from a replica set to a sharded cluster
103
+
104
+ * Sync sharded clusters that have different numbers of shards
105
+
106
+ For more information, see the :ref:`reverse <c2c-api-reverse>` endpoint.
100
107
101
108
Default value is ``false``.
102
109
110
+ * - ``sharding``
111
+ - document
112
+ - Optional
113
+ - Configure sync between a replica set and sharded cluster.
114
+ Sync from a replica set to a sharded cluster requires this
115
+ option.
116
+
117
+ For more information, see :ref:`c2c-api-start-sharding`.
118
+
119
+ .. versionadded:: 1.1
120
+
103
121
* - ``enableUserWriteBlocking``
104
122
- boolean
105
123
- Optional
@@ -111,6 +129,69 @@ Request Body Parameters
111
129
112
130
Default value is ``false``.
113
131
132
+
133
+ .. _c2c-api-start-sharding:
134
+
135
+ Sharding Parameters
136
+ ~~~~~~~~~~~~~~~~~~~
137
+
138
+ .. versionadded:: 1.1
139
+
140
+ To sync from a replica set to a sharded cluster, set the
141
+ ``sharding`` option to shard collections on the destination cluster.
142
+
143
+ The ``sharding`` option has the following parameters:
144
+
145
+ .. list-table::
146
+ :header-rows: 1
147
+ :stub-columns: 1
148
+ :widths: 15 15 70
149
+
150
+ * - Parameter
151
+ - Type
152
+ - Description
153
+
154
+ * - ``createSupportedIndexes``
155
+ - boolean
156
+ - Optional. Sets whether sync creates a supporting index
157
+ for the shard key, if none exists. Defaults to ``false``.
158
+
159
+ * - ``shardingEntries``
160
+ - array of documents
161
+ - Required. Sets the namespace and key of collections to shard
162
+ during sync.
163
+
164
+ Collections not included in this array sync to unsharded
165
+ collections on the destination cluster. If set with an empty array,
166
+ no collections are sharded.
167
+
168
+ * - | ``shardingEntries``
169
+ | ``.collection``
170
+ - string
171
+ - Sets the collection to shard.
172
+
173
+ * - | ``shardingEntries``
174
+ | ``.database``
175
+ - string
176
+ - Sets the database of the collection to shard.
177
+
178
+ * - | ``shardingEntries``
179
+ | ``.shardCollection``
180
+ - document
181
+ - Sets the shard key to generate on the destination cluster.
182
+
183
+ * - | ``shardingEntries``
184
+ | ``.shardCollection``
185
+ | ``.key``
186
+ - array
187
+ - Sets the fields to use for the shard key.
188
+
189
+ For more information, see :ref:`shard-key`.
190
+
191
+ ``mongosync`` throws an error if the ``sharding`` option is not set when
192
+ syncing from a replica set to a sharded cluster. ``mongosync`` also
193
+ throws an error if the ``sharding`` option is set with any other configuration.
194
+
114
195
Response
115
196
--------
116
197
@@ -151,12 +232,133 @@ Request
151
232
Response
152
233
~~~~~~~~
153
234
235
+ .. literalinclude:: /includes/api/responses/success.json
236
+ :language: json
237
+ :copyable: false
238
+
239
+ Example 3 - Start Sync from Replica Set to Sharded Cluster
240
+ ----------------------------------------------------------
241
+
242
+ Request
243
+ ~~~~~~~
244
+
245
+ .. literalinclude:: /includes/api/requests/start-rs-shard.sh
246
+ :language: shell
247
+
248
+ Response
249
+ ~~~~~~~~
250
+
154
251
.. literalinclude:: /includes/api/responses/success.json
155
252
:language: json
156
253
:copyable: false
157
254
158
255
Behavior
159
256
--------
160
257
258
+ State
259
+ ~~~~~
260
+
161
261
If the ``start`` request is successful, ``mongosync`` enters the
162
262
``RUNNING`` state.
263
+
264
+ Pre-Split Chunks
265
+ ~~~~~~~~~~~~~~~~
266
+
267
+ .. versionadded:: 1.1
268
+
269
+ When ``mongosync`` syncs to a sharded cluster, it pre-splits chunks for
270
+ sharded collections on the destination cluster. This is supported in the
271
+ following configurations:
272
+
273
+ * Sync from a replica set to a sharded cluster.
274
+
275
+ * Sync between sharded clusters that differ in the number of shards.
276
+
277
+
278
+ Shard Replica Sets
279
+ ~~~~~~~~~~~~~~~~~~
280
+
281
+ .. versionadded:: 1.1
282
+
283
+ Sync from a replica set to a sharded cluster requires the
284
+ ``sharding`` option. This option configures how ``mongosync`` shards
285
+ collections.
286
+
287
+ The ``sharding.shardEntries`` array specifies the collections to shard.
288
+ Collections that are not listed in this array replicate as unsharded.
289
+
290
+ Supporting Indexes
291
+ ~~~~~~~~~~~~~~~~~~
292
+
293
+ .. versionadded:: 1.1
294
+
295
+ ``mongosync`` syncs indexes from the source cluster to the destination
296
+ cluster. But, when syncing from a replica set to a sharded cluster,
297
+ ``mongosync`` may require an additional index to support the shard key,
298
+ which may not exist on the source cluster.
299
+
300
+ ``mongosync`` can create supporting indexes for sharded collections during sync.
301
+ This is done by setting the ``sharding.createSupportingIndexes`` option.
302
+
303
+ When ``sharding.createSupportingIndexes`` is ``false`` (the default):
304
+
305
+ * Each shard key you provide for the ``sharding.shardEntries`` option
306
+ must have an existing index on the source cluster.
307
+
308
+ * One of the indexes used for the shard key must have simple collation if the
309
+ collection uses any other collation.
310
+
311
+ * To use a unique index in the shard key, you must specify its uniqueness when
312
+ you create the index on the source cluster.
313
+
314
+ * Unique indexes on the source cluster that are incompatible with the requested
315
+ shard key on the destination cluster, such as a unique index on the source
316
+ that does not contain the requested shard key as a prefix on the destination,
317
+ can cause ``mongosync`` to fail.
318
+
319
+ When ``sharding.createSupportingIndexes`` is ``true``:
320
+
321
+ * If the supporting indexes exist on the source cluster, ``mongosync``
322
+ syncs the indexes to the destination cluster and uses them
323
+ as shard keys.
324
+
325
+ * If the supporting indexes don't exist, ``mongosync`` creates them on the
326
+ destination cluster.
327
+
328
+ The ``sharding.createSupportingIndexes`` option affects all sharded collections.
329
+
330
+ Rename During Sync
331
+ ~~~~~~~~~~~~~~~~~~
332
+
333
+ .. versionadded:: 1.1
334
+
335
+ Collections listed in the ``sharding.shardEntries`` array
336
+ when synced from a replica set to a sharded cluster
337
+ become sharded collections on the destination cluster.
338
+
339
+ Renaming a collection (such as with the :dbcommand:`renameCollection` command)
340
+ on the source cluster after calling ``start`` but before ``mongosync`` begins
341
+ to copy the collection can block the collection from sharding on the destination.
342
+
343
+ .. note::
344
+
345
+ Renaming collections to use a different database while syncing from a
346
+ replica set to a sharded cluster is not supported.
347
+
348
+
349
+ To check whether it is safe to rename collections, call the
350
+ :ref:`c2c-api-progress` endpoint and check the value of the
351
+ ``collectionCopy.estimatedCopiedBytes`` field in the return document.
352
+
353
+ * A value of 0 indicates that ``mongosync`` has not started to copy the
354
+ collection.
355
+
356
+ Renaming a collection at this point may result in an unsharded collection
357
+ on the destination cluster, as the transition to copying can happen before
358
+ the rename takes effect on the source.
359
+
360
+ * A value greater than 0 indicates that ``mongosync`` has started the copy.
361
+ Renaming the collection from this point on does not block
362
+ its sharding on the destination cluster, even in the event of a crash.
363
+
364
+
0 commit comments