* Given a collection, tries to get a shardOID if one is applicable (there is * a single shard corresponding to that collection) and if it's available * locally. If such a shard is found, locks it with the given lock mode * and returns it to the caller. */
| 568 | * and returns it to the caller. |
| 569 | */ |
| 570 | Oid |
| 571 | TryGetCollectionShardTable(MongoCollection *collection, LOCKMODE lockMode) |
| 572 | { |
| 573 | /* Cannot proceed without a local shard available. */ |
| 574 | if (collection->shardTableName[0] == '\0') |
| 575 | { |
| 576 | return InvalidOid; |
| 577 | } |
| 578 | |
| 579 | if (!UseLocalExecutionShardQueries) |
| 580 | { |
| 581 | return InvalidOid; |
| 582 | } |
| 583 | |
| 584 | /* Don't allow direct shard access in a multi-statement transaction |
| 585 | * This is because switching states between remote execution and local execution can produce |
| 586 | * isolation issues. So only support this if we're a single command. |
| 587 | */ |
| 588 | if (IsTransactionBlock() && !ForceLocalExecutionShardQueries) |
| 589 | { |
| 590 | return InvalidOid; |
| 591 | } |
| 592 | |
| 593 | Oid relationShardOid = GetRelationIdForCollectionTableName(collection->shardTableName, |
| 594 | lockMode); |
| 595 | ereport(DEBUG3, (errmsg("Has relation shard: %d", relationShardOid != InvalidOid))); |
| 596 | return relationShardOid; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | static void |
no test coverage detected