MCPcopy Create free account
hub / github.com/documentdb/documentdb / TryGetCollectionShardTable

Function TryGetCollectionShardTable

pg_documentdb/src/metadata/collection.c:570–597  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

568 * and returns it to the caller.
569 */
570Oid
571TryGetCollectionShardTable(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
600static void

Callers 5

CommandInsertCoreFunction · 0.85
command_deleteFunction · 0.85
PerformUpdateCoreFunction · 0.85
ProcessBatchUpdateFunction · 0.85
GenerateBaseTableQueryFunction · 0.85

Tested by

no test coverage detected