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

Function ResLockCheckLimit

src/backend/utils/resscheduler/resqueue.c:874–1005  ·  view source on GitHub ↗

* ResLockCheckLimit -- test whether the given process acquiring the this lock * will cause a resource to exceed its limits. * * Notes: * Returns LIMIT_CHECK_FOUND if limit will be exhausted, LIMIT_CHECK_OK if not. * * If increment is true, then the resource counter associated with the lock * is to be incremented, if false then decremented. * * Named similarly to the LockCheckconflicts() f

Source from the content-addressed store, hash-verified

872 * them from freeing resources!
873 */
874int
875ResLockCheckLimit(LOCK *lock, PROCLOCK *proclock, ResPortalIncrement *incrementSet, bool increment)
876{
877 ResQueue queue;
878 ResLimit limits;
879 bool over_limit = false;
880 bool will_overcommit = false;
881 int status = LIMIT_CHECK_OK;
882 Cost increment_amt;
883 int i;
884
885 Assert(LWLockHeldByMeInMode(ResQueueLock, LW_EXCLUSIVE));
886
887 /* Get the queue for this lock. */
888 queue = GetResQueueFromLock(lock);
889 limits = queue->limits;
890
891 for (i = 0; i < NUM_RES_LIMIT_TYPES; i++)
892 {
893 /*
894 * Skip the default threshold, as it means 'no limit'.
895 */
896 if (limits[i].threshold_value == INVALID_RES_LIMIT_THRESHOLD)
897 continue;
898
899 switch (limits[i].type)
900 {
901 case RES_COUNT_LIMIT:
902 {
903 Assert((limits[i].threshold_is_max));
904
905 /* Setup whether to increment or decrement the # active. */
906 if (increment)
907 {
908 increment_amt = incrementSet->increments[i];
909
910 if (limits[i].current_value + increment_amt > limits[i].threshold_value)
911 over_limit = true;
912 }
913 else
914 {
915 increment_amt = -1 * incrementSet->increments[i];
916 }
917
918#ifdef RESLOCK_DEBUG
919 elog(DEBUG1, "checking count limit threshold %.0f current %.0f",
920 limits[i].threshold_value, limits[i].current_value);
921#endif
922 }
923 break;
924
925 case RES_COST_LIMIT:
926 {
927 Assert((limits[i].threshold_is_max));
928
929 /* Setup whether to increment or decrement the cost. */
930 if (increment)
931 {

Callers 2

ResLockAcquireFunction · 0.85

Calls 2

LWLockHeldByMeInModeFunction · 0.85
GetResQueueFromLockFunction · 0.85

Tested by

no test coverage detected