* Top level command to reshard a collection. */
| 212 | * Top level command to reshard a collection. |
| 213 | */ |
| 214 | Datum |
| 215 | command_reshard_collection(PG_FUNCTION_ARGS) |
| 216 | { |
| 217 | pgbson *shardArg = PG_GETARG_PGBSON_PACKED(0); |
| 218 | |
| 219 | if (!IsMetadataCoordinator()) |
| 220 | { |
| 221 | StringInfo shardCollectionQuery = makeStringInfo(); |
| 222 | appendStringInfo(shardCollectionQuery, |
| 223 | "SELECT %s.reshard_collection(%s::%s.bson)", |
| 224 | ApiSchemaNameV2, |
| 225 | quote_literal_cstr(PgbsonToHexadecimalString(shardArg)), |
| 226 | CoreSchemaNameV2); |
| 227 | DistributedRunCommandResult result = RunCommandOnMetadataCoordinator( |
| 228 | shardCollectionQuery->data); |
| 229 | |
| 230 | if (!result.success) |
| 231 | { |
| 232 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 233 | errmsg( |
| 234 | "Metadata coordinator encountered internal error while resharding the collection"), |
| 235 | errdetail_log( |
| 236 | "Metadata coordinator encountered internal error while resharding the collection via distributed call %s", |
| 237 | text_to_cstring(result.response)))); |
| 238 | } |
| 239 | |
| 240 | PG_RETURN_VOID(); |
| 241 | } |
| 242 | |
| 243 | ShardCollectionArgs args = { 0 }; |
| 244 | ParseReshardCollectionRequest(shardArg, &args); |
| 245 | ShardCollectionCore(&args); |
| 246 | PG_RETURN_VOID(); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /* |
nothing calls this directly
no test coverage detected