| 2288 | |
| 2289 | |
| 2290 | static Datum |
| 2291 | CallUpdateWorker(MongoCollection *collection, pgbson *serializedSpec, |
| 2292 | pgbsonsequence *updateDocs, int64 shardKeyHash, text *transactionId) |
| 2293 | { |
| 2294 | int argCount = 6; |
| 2295 | Datum argValues[6]; |
| 2296 | |
| 2297 | /* whitespace means not null, n means null */ |
| 2298 | char argNulls[6] = { ' ', ' ', ' ', ' ', 'n', 'n' }; |
| 2299 | Oid argTypes[6] = { INT8OID, INT8OID, REGCLASSOID, BYTEAOID, BYTEAOID, TEXTOID }; |
| 2300 | |
| 2301 | const char *updateQuery = FormatSqlQuery( |
| 2302 | " SELECT %s.update_worker($1, $2, $3, $4::%s.bson, $5::%s.bsonsequence, $6) FROM %s.documents_" |
| 2303 | UINT64_FORMAT " WHERE shard_key_value = %ld", |
| 2304 | DocumentDBApiInternalSchemaName, CoreSchemaNameV2, CoreSchemaNameV2, |
| 2305 | ApiDataSchemaName, collection->collectionId, |
| 2306 | shardKeyHash); |
| 2307 | |
| 2308 | argValues[0] = UInt64GetDatum(collection->collectionId); |
| 2309 | |
| 2310 | /* p_shard_key_value */ |
| 2311 | argValues[1] = Int64GetDatum(shardKeyHash); |
| 2312 | |
| 2313 | /* p_shard_oid: We set this to InvalidOid here. The planner hook on the worker node will set this to |
| 2314 | * non-InvalidOid before the actual function is executed. |
| 2315 | */ |
| 2316 | argValues[2] = ObjectIdGetDatum(InvalidOid); |
| 2317 | argValues[3] = PointerGetDatum(serializedSpec); |
| 2318 | |
| 2319 | if (updateDocs != NULL) |
| 2320 | { |
| 2321 | argValues[4] = PointerGetDatum(updateDocs); |
| 2322 | argNulls[4] = ' '; |
| 2323 | } |
| 2324 | |
| 2325 | if (transactionId != NULL) |
| 2326 | { |
| 2327 | argValues[5] = PointerGetDatum(transactionId); |
| 2328 | argNulls[5] = ' '; |
| 2329 | } |
| 2330 | |
| 2331 | bool readOnly = false; |
| 2332 | |
| 2333 | Datum resultDatum[1] = { 0 }; |
| 2334 | bool isNulls[1] = { false }; |
| 2335 | int numResults = 1; |
| 2336 | |
| 2337 | /* forceDelegation assumes nested distribution */ |
| 2338 | RunMultiValueQueryWithNestedDistribution(updateQuery, argCount, argTypes, argValues, |
| 2339 | argNulls, |
| 2340 | readOnly, SPI_OK_SELECT, resultDatum, |
| 2341 | isNulls, numResults); |
| 2342 | |
| 2343 | if (isNulls[0]) |
| 2344 | { |
| 2345 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 2346 | errmsg("update_worker should not return null"))); |
| 2347 | } |
no test coverage detected