* Top level command to shard a collection. */
| 166 | * Top level command to shard a collection. |
| 167 | */ |
| 168 | Datum |
| 169 | command_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 | /* |
nothing calls this directly
no test coverage detected