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

Function ResLockAcquire

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

* ResLockAcquire -- acquire a resource lock. * * Notes and critisms: * * Returns LOCKACQUIRE_OK if we get the lock, * LOCKACQUIRE_NOT_AVAIL if we don't want to take the lock after all. * * Analogous to LockAcquire, but the lockmode and session boolean are not * required in the function prototype as we are *always* lockmode ExclusiveLock * and have no session locks. * * The semantics o

Source from the content-addressed store, hash-verified

165 *
166 */
167LockAcquireResult
168ResLockAcquire(LOCKTAG *locktag, ResPortalIncrement *incrementSet)
169{
170 LOCKMODE lockmode = ExclusiveLock;
171 LOCK *lock;
172 PROCLOCK *proclock;
173 PROCLOCKTAG proclocktag;
174 LOCALLOCKTAG localtag;
175 LOCALLOCK *locallock;
176 uint32 hashcode;
177 uint32 proclock_hashcode;
178 int partition;
179 LWLockId partitionLock;
180 bool found;
181 ResourceOwner owner;
182 ResQueue queue;
183 int status;
184 ResIncrementAddStatus addStatus;
185
186 if (resLockAcquireStatus != RQA_NOT_STARTED_OR_DONE)
187 {
188 elog(LOG,
189 "Resource queue %d: previous ResLockAcquire() interrupted, "
190 " status = %d, portal id = %u",
191 locktag->locktag_field1,
192 resLockAcquireStatus,
193 incrementSet->portalId);
194 }
195
196 resLockAcquireStatus = RQA_STARTED;
197
198 /* Setup the lock method bits. */
199 Assert(locktag->locktag_lockmethodid == RESOURCE_LOCKMETHOD);
200
201 /* Provide a resource owner. */
202 owner = CurrentResourceOwner;
203
204 /*
205 * Find or create a LOCALLOCK entry for this lock and lockmode
206 */
207 MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
208 localtag.lock = *locktag;
209 localtag.mode = lockmode;
210
211 locallock = (LOCALLOCK *) hash_search(LockMethodLocalHash,
212 (void *) &localtag,
213 HASH_ENTER, &found);
214
215 /*
216 * if it's a new locallock object, initialize it, if it already exists
217 * then that is enough for the resource locks.
218 */
219 if (!found)
220 {
221 locallock->lock = NULL;
222 locallock->proclock = NULL;
223 locallock->hashcode = LockTagHashCode(&(localtag.lock));
224

Callers 2

ResLockPortalFunction · 0.85
ResLockUtilityPortalFunction · 0.85

Calls 15

hash_searchFunction · 0.85
LockTagHashCodeFunction · 0.85
MemoryContextAllocFunction · 0.85
LWLockAcquireFunction · 0.85
LWLockReleaseFunction · 0.85
SHMQueueInitFunction · 0.85
ProcQueueInitFunction · 0.85
ProcLockHashCodeFunction · 0.85
SHMQueueEmptyFunction · 0.85
SHMQueueInsertBeforeFunction · 0.85
GetResQueueFromLockFunction · 0.85

Tested by

no test coverage detected