MCPcopy Create free account
hub / github.com/apache/cloudberry / SerializationNeededForRead

Function SerializationNeededForRead

src/backend/storage/lmgr/predicate.c:513–551  ·  view source on GitHub ↗

* When a public interface method is called for a read, this is the test to * see if we should do a quick return. * * Note: this function has side-effects! If this transaction has been flagged * as RO-safe since the last call, we release all predicate locks and reset * MySerializableXact. That makes subsequent calls to return quickly. * * This is marked as 'inline' to eliminate the function

Source from the content-addressed store, hash-verified

511 * common case that serialization is not needed.
512 */
513static inline bool
514SerializationNeededForRead(Relation relation, Snapshot snapshot)
515{
516 /* Nothing to do if this is not a serializable transaction */
517 if (MySerializableXact == InvalidSerializableXact)
518 return false;
519
520 /*
521 * Don't acquire locks or conflict when scanning with a special snapshot.
522 * This excludes things like CLUSTER and REINDEX. They use the wholesale
523 * functions TransferPredicateLocksToHeapRelation() and
524 * CheckTableForSerializableConflictIn() to participate in serialization,
525 * but the scans involved don't need serialization.
526 */
527 if (!IsMVCCSnapshot(snapshot))
528 return false;
529
530 /*
531 * Check if we have just become "RO-safe". If we have, immediately release
532 * all locks as they're not needed anymore. This also resets
533 * MySerializableXact, so that subsequent calls to this function can exit
534 * quickly.
535 *
536 * A transaction is flagged as RO_SAFE if all concurrent R/W transactions
537 * commit without having conflicts out to an earlier snapshot, thus
538 * ensuring that no conflicts are possible for this transaction.
539 */
540 if (SxactIsROSafe(MySerializableXact))
541 {
542 ReleasePredicateLocks(false, true);
543 return false;
544 }
545
546 /* Check if the relation doesn't participate in predicate locking */
547 if (!PredicateLockingNeededForRelation(relation))
548 return false;
549
550 return true; /* no excuse to skip predicate locking */
551}
552
553/*
554 * Like SerializationNeededForRead(), but called on writes.

Callers 5

PredicateLockRelationFunction · 0.85
PredicateLockPageFunction · 0.85
PredicateLockTIDFunction · 0.85

Calls 2

ReleasePredicateLocksFunction · 0.85

Tested by

no test coverage detected