MCPcopy Create free account
hub / github.com/documentdb/documentdb / command_shard_collection

Function command_shard_collection

pg_documentdb/src/sharding/sharding.c:168–208  ·  view source on GitHub ↗

* Top level command to shard a collection. */

Source from the content-addressed store, hash-verified

166 * Top level command to shard a collection.
167 */
168Datum
169command_shard_collection(PG_FUNCTION_ARGS)
170{
171 if (PG_NARGS() > 1)
172 {
173 ShardCollectionLegacy(fcinfo);
174 PG_RETURN_VOID();
175 }
176
177 /* New function with 1 arg. */
178 pgbson *shardArg = PG_GETARG_PGBSON_PACKED(0);
179
180 if (!IsMetadataCoordinator())
181 {
182 StringInfo shardCollectionQuery = makeStringInfo();
183 appendStringInfo(shardCollectionQuery,
184 "SELECT %s.shard_collection(%s::%s.bson)",
185 ApiSchemaNameV2,
186 quote_literal_cstr(PgbsonToHexadecimalString(shardArg)),
187 CoreSchemaNameV2);
188 DistributedRunCommandResult result = RunCommandOnMetadataCoordinator(
189 shardCollectionQuery->data);
190
191 if (!result.success)
192 {
193 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
194 errmsg(
195 "Internal error sharding collection in metadata coordinator"),
196 errdetail_log(
197 "Internal error sharding collection in metadata coordinator via distributed call %s",
198 text_to_cstring(result.response))));
199 }
200
201 PG_RETURN_VOID();
202 }
203
204 ShardCollectionArgs args = { 0 };
205 ParseShardCollectionRequest(shardArg, &args);
206 ShardCollectionCore(&args);
207 PG_RETURN_VOID();
208}
209
210
211/*

Callers

nothing calls this directly

Calls 6

ShardCollectionLegacyFunction · 0.85
IsMetadataCoordinatorFunction · 0.85
ShardCollectionCoreFunction · 0.85

Tested by

no test coverage detected