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

Function BuildQueueStatusContext

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

* This copies out the current state of resource queues. */

Source from the content-addressed store, hash-verified

2087 * This copies out the current state of resource queues.
2088 */
2089static void
2090BuildQueueStatusContext(QueueStatusContext *fctx)
2091{
2092 int num_calls = 0;
2093 int numRecords;
2094 int i;
2095 HASH_SEQ_STATUS status;
2096 ResQueueData *queue = NULL;
2097
2098 Assert(fctx);
2099 Assert(fctx->record);
2100
2101 /*
2102 * Take all the partition locks. This is necessary as we want to to use
2103 * the same lock order as the rest of the code - i.e. partition locks
2104 * *first* *then* the queue lock (otherwise we could deadlock ourselves).
2105 */
2106 for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
2107 LWLockAcquire(LockHashPartitionLockByIndex(i), LW_EXCLUSIVE);
2108
2109 /*
2110 * Lock resource queue structures.
2111 */
2112 LWLockAcquire(ResQueueLock, LW_EXCLUSIVE);
2113
2114 /* Initialize for a sequential scan of the resource queue hash. */
2115 hash_seq_init(&status, ResQueueHash);
2116 num_calls = hash_get_num_entries(ResQueueHash);
2117 Assert(num_calls == ResScheduler->num_queues);
2118
2119 numRecords = 0;
2120 while ((queue = (ResQueueData *) hash_seq_search(&status)) != NULL)
2121 {
2122 QueueStatusRec *record = &fctx->record[numRecords];
2123 int j;
2124 ResLimit limits = NULL;
2125 uint32 hashcode;
2126
2127 /**
2128 * Gather thresholds and current values on activestatements, cost and memory
2129 */
2130 limits = queue->limits;
2131
2132 record->queueid = queue->queueid;
2133
2134 for (j = 0; j < NUM_RES_LIMIT_TYPES; j++)
2135 {
2136 switch (limits[j].type)
2137 {
2138 case RES_COUNT_LIMIT:
2139 record->queuecountthreshold = limits[j].threshold_value;
2140 record->queuecountvalue = limits[j].current_value;
2141 break;
2142
2143 case RES_COST_LIMIT:
2144 record->queuecostthreshold = limits[j].threshold_value;
2145 record->queuecostvalue = limits[j].current_value;
2146 break;

Callers 2

pg_resqueue_statusFunction · 0.85
pg_resqueue_status_kvFunction · 0.85

Calls 7

LWLockAcquireFunction · 0.85
hash_seq_initFunction · 0.85
hash_get_num_entriesFunction · 0.85
hash_seq_searchFunction · 0.85
LockTagHashCodeFunction · 0.85
LWLockReleaseFunction · 0.85

Tested by

no test coverage detected