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

Function GetPrivateRefCountEntry

src/backend/storage/buffer/bufmgr.c:322–395  ·  view source on GitHub ↗

* Return the PrivateRefCount entry for the passed buffer. * * Returns NULL if a buffer doesn't have a refcount entry. Otherwise, if * do_move is true, and the entry resides in the hashtable the entry is * optimized for frequent access by moving it to the array. */

Source from the content-addressed store, hash-verified

320 * optimized for frequent access by moving it to the array.
321 */
322static PrivateRefCountEntry *
323GetPrivateRefCountEntry(Buffer buffer, bool do_move)
324{
325 PrivateRefCountEntry *res;
326 int i;
327
328 Assert(BufferIsValid(buffer));
329 Assert(!BufferIsLocal(buffer));
330
331 /*
332 * First search for references in the array, that'll be sufficient in the
333 * majority of cases.
334 */
335 for (i = 0; i < REFCOUNT_ARRAY_ENTRIES; i++)
336 {
337 res = &PrivateRefCountArray[i];
338
339 if (res->buffer == buffer)
340 return res;
341 }
342
343 /*
344 * By here we know that the buffer, if already pinned, isn't residing in
345 * the array.
346 *
347 * Only look up the buffer in the hashtable if we've previously overflowed
348 * into it.
349 */
350 if (PrivateRefCountOverflowed == 0)
351 return NULL;
352
353 res = hash_search(PrivateRefCountHash,
354 (void *) &buffer,
355 HASH_FIND,
356 NULL);
357
358 if (res == NULL)
359 return NULL;
360 else if (!do_move)
361 {
362 /* caller doesn't want us to move the hash entry into the array */
363 return res;
364 }
365 else
366 {
367 /* move buffer from hashtable into the free array slot */
368 bool found;
369 PrivateRefCountEntry *free;
370
371 /* Ensure there's a free array slot */
372 ReservePrivateRefCountEntry();
373
374 /* Use up the reserved slot */
375 Assert(ReservedRefCountEntry != NULL);
376 free = ReservedRefCountEntry;
377 ReservedRefCountEntry = NULL;
378 Assert(free->buffer == InvalidBuffer);
379

Callers 5

GetPrivateRefCountFunction · 0.85
PinBufferFunction · 0.85
PinBuffer_LockedFunction · 0.85
UnpinBufferFunction · 0.85
IncrBufferRefCountFunction · 0.85

Calls 2

hash_searchFunction · 0.85

Tested by

no test coverage detected