* Top level command to unshard a collection. */
| 251 | * Top level command to unshard a collection. |
| 252 | */ |
| 253 | Datum |
| 254 | command_unshard_collection(PG_FUNCTION_ARGS) |
| 255 | { |
| 256 | pgbson *shardArg = PG_GETARG_PGBSON_PACKED(0); |
| 257 | |
| 258 | if (!IsMetadataCoordinator()) |
| 259 | { |
| 260 | StringInfo shardCollectionQuery = makeStringInfo(); |
| 261 | appendStringInfo(shardCollectionQuery, |
| 262 | "SELECT %s.unshard_collection(%s::%s.bson)", |
| 263 | ApiSchemaNameV2, |
| 264 | quote_literal_cstr(PgbsonToHexadecimalString(shardArg)), |
| 265 | CoreSchemaNameV2); |
| 266 | DistributedRunCommandResult result = RunCommandOnMetadataCoordinator( |
| 267 | shardCollectionQuery->data); |
| 268 | |
| 269 | if (!result.success) |
| 270 | { |
| 271 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 272 | errmsg( |
| 273 | "Internal error unsharding collection in metadata coordinator"), |
| 274 | errdetail_log( |
| 275 | "Internal error unsharding collection in metadata coordinator via distributed call %s", |
| 276 | text_to_cstring(result.response)))); |
| 277 | } |
| 278 | |
| 279 | PG_RETURN_VOID(); |
| 280 | } |
| 281 | |
| 282 | ShardCollectionArgs args = { 0 }; |
| 283 | ParseUnshardCollectionRequest(shardArg, &args); |
| 284 | ShardCollectionCore(&args); |
| 285 | PG_RETURN_VOID(); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /* |
nothing calls this directly
no test coverage detected