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

Function BloomNewBuffer

contrib/bloom/blutils.c:352–401  ·  view source on GitHub ↗

* Allocate a new page (either by recycling, or by extending the index file) * The returned buffer is already pinned and exclusive-locked * Caller is responsible for initializing the page by calling BloomInitPage */

Source from the content-addressed store, hash-verified

350 * Caller is responsible for initializing the page by calling BloomInitPage
351 */
352Buffer
353BloomNewBuffer(Relation index)
354{
355 Buffer buffer;
356 bool needLock;
357
358 /* First, try to get a page from FSM */
359 for (;;)
360 {
361 BlockNumber blkno = GetFreeIndexPage(index);
362
363 if (blkno == InvalidBlockNumber)
364 break;
365
366 buffer = ReadBuffer(index, blkno);
367
368 /*
369 * We have to guard against the possibility that someone else already
370 * recycled this page; the buffer may be locked if so.
371 */
372 if (ConditionalLockBuffer(buffer))
373 {
374 Page page = BufferGetPage(buffer);
375
376 if (PageIsNew(page))
377 return buffer; /* OK to use, if never initialized */
378
379 if (BloomPageIsDeleted(page))
380 return buffer; /* OK to use */
381
382 LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
383 }
384
385 /* Can't use it, so release buffer and try again */
386 ReleaseBuffer(buffer);
387 }
388
389 /* Must extend the file */
390 needLock = !RELATION_IS_LOCAL(index);
391 if (needLock)
392 LockRelationForExtension(index, ExclusiveLock);
393
394 buffer = ReadBuffer(index, P_NEW);
395 LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
396
397 if (needLock)
398 UnlockRelationForExtension(index, ExclusiveLock);
399
400 return buffer;
401}
402
403/*
404 * Initialize any page of a bloom index.

Callers 3

BloomInitMetapageFunction · 0.85
flushCachedPageFunction · 0.85
blinsertFunction · 0.85

Calls 7

GetFreeIndexPageFunction · 0.85
ReadBufferFunction · 0.85
ConditionalLockBufferFunction · 0.85
LockBufferFunction · 0.85
ReleaseBufferFunction · 0.85
LockRelationForExtensionFunction · 0.85

Tested by

no test coverage detected