| 1144 | |
| 1145 | |
| 1146 | static void |
| 1147 | ShardCollectionLegacy(PG_FUNCTION_ARGS) |
| 1148 | { |
| 1149 | pgbson *shardKey = PG_GETARG_PGBSON(2); |
| 1150 | |
| 1151 | ValidateShardKey(shardKey); |
| 1152 | |
| 1153 | Datum databaseDatum = PG_GETARG_DATUM(0); |
| 1154 | Datum collectionDatum = PG_GETARG_DATUM(1); |
| 1155 | |
| 1156 | char *databaseName = TextDatumGetCString(databaseDatum); |
| 1157 | char *collectionName = TextDatumGetCString(collectionDatum); |
| 1158 | bool isReshard = PG_GETARG_BOOL(3); |
| 1159 | |
| 1160 | if (!IsMetadataCoordinator()) |
| 1161 | { |
| 1162 | StringInfo shardCollectionQuery = makeStringInfo(); |
| 1163 | appendStringInfo(shardCollectionQuery, |
| 1164 | "SELECT %s.shard_collection(%s,%s,%s::%s,%s)", |
| 1165 | ApiSchemaName, |
| 1166 | quote_literal_cstr(databaseName), |
| 1167 | quote_literal_cstr(collectionName), |
| 1168 | quote_literal_cstr(PgbsonToHexadecimalString(shardKey)), |
| 1169 | FullBsonTypeName, |
| 1170 | isReshard ? "true" : "false"); |
| 1171 | DistributedRunCommandResult result = RunCommandOnMetadataCoordinator( |
| 1172 | shardCollectionQuery->data); |
| 1173 | |
| 1174 | if (!result.success) |
| 1175 | { |
| 1176 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 1177 | errmsg( |
| 1178 | "Internal error sharding collection in metadata coordinator"), |
| 1179 | errdetail_log( |
| 1180 | "Internal error sharding collection in metadata coordinator via distributed call %s", |
| 1181 | text_to_cstring(result.response)))); |
| 1182 | } |
| 1183 | |
| 1184 | return; |
| 1185 | } |
| 1186 | |
| 1187 | ShardCollectionArgs args = { 0 }; |
| 1188 | args.databaseName = databaseName; |
| 1189 | args.collectionName = collectionName; |
| 1190 | args.shardingMode = isReshard ? ShardCollectionMode_Reshard : |
| 1191 | ShardCollectionMode_Shard; |
| 1192 | args.shardKeyDefinition = shardKey; |
| 1193 | |
| 1194 | ShardCollectionCore(&args); |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | /* |
no test coverage detected