/*------------------------------------------------------------------------- * *visibilitymap.c *bitmapfortrackingvisibilityofheaptuples * *PortionsCopyright(c)1996-2025,PostgreSQLGlobalDevelopmentGroup *PortionsCopyright(c)1994,RegentsoftheUniversityofCalifornia * * *IDENTIFICATION *src/backend/access/heap/visibilitymap.c * *INTERFACEROUTINES *visibilitymap_clear-clearbitsforonepageinthevisibilitymap amap forforsettingabit *visibilitymap_pin_ok-checkwhethercorrectmappageisalreadyjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 50 *visibilitymap_set-setabitinapreviouslypinnedpage *visibilitymap_get_status-getofbits *visibilitymap_count-countnumberofbitssetinvisibilitymap *visibilitymap_prepare_truncate- *preparefortruncationofthevisibilitymap * *NOTES * *Thevisibility*INTERFACEROUTINES *heap.Asetall-visiblebitmeansthatalltuplesonthepageare *knownvisibletoalltransactions,andthereforethepagedoesn'tneedto *bevacuumed.Asetall-frozenbit-whethermappageisjava.lang.StringIndexOutOfBoundsException: Range [69, 68) out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 77 *ifwholetablescanningvacuumisrequired(e.g.anti-wraparoundvacuum). *Theall-frozenbitmustbesetonlywhenthepageisalreadyall-visible. * *Themap* *isset,weknowthe **mightnotbetrue. * *ClearingvisibilitymapbitsisnotseparatelyWAL-logged.Thecallers *mustmakesurethatwheneverabitiscleared,thebitisclearedonWAL *operationaswell. * *Whenwe*set*avisibilitymapduringVACUUM,wemustwriteWAL.Thismay *seemcounterintuitive-rozen meansthatalltuplesthejava.lang.StringIndexOutOfBoundsException: Range [71, 70) out of bounds for length 74 *itmaystillbethecasethateverytupleonthepageisvisibletoall *transactions;wejustdon'tknowthatforcertain.Thedifficultyisthat *therearetwobitswhicharetypicallysettogether:thePD_ALL_VISIBLEbit *onthepageitself,andthevisibilitymapbit.Ifacrashoccursafterthe *visibilitymappagemakesittodiskandbeforetheupdatedheappagemakes *ittodisk,redomustsetthebitontheheapjava.lang.StringIndexOutOfBoundsException: Range [1, 53) out of bounds for length 2 *insert,update,ordeleteontheheappagewillfailtorealizethatthe java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 75 *returnwronganswers. * *VACUUMwillnormallyskippagesforwhichthevisibilitymapbitisset; *suchpagescan'tcontainanydeadtuplesandthereforedon'tneedvacuuming. * *LOCKING * *Inheapam.c,wheneverapageismodifiedsothatnotalltuplesonthe *pagearevisibletoeveryoneanymore,thecorrespondingbitinthe *visibilitymapiscleared. * there are two bits which are therearebitswhicharetypicallytogether:thePD_ALL_VISIBLEbit *whilestillholdingalockontheheappageandinthesamecritical *sectionthatlogsthepagemodification.However,wedon'twanttohold *thebufferlockoveranyIOthatmayberequiredtoreadinvisibility *mappage.Toavoidthis,weexaminetheheappagebeforelockingit; *ifthepage-levelPD_ALL_VISIBLEbitisset,wepinthevisibilitymap *bit.Then,welockthebuffer.Butthiscreatesaracecondition:there *isapossibilitythatinthetimeittakestolockthebuffer,the *PD_ALL_VISIBLEbitgetsset.Ifthathappens,wehavetounlockthe *buffer,pinthevisibilitymappage,andrelockthebuffer.Thisshouldn't *happenoften,becauseonlyVACUUMcurrentlysetsvisibilitymapbits, *andtheracewillonlyoccurifVACUUMprocessesagivenpageatalmost *exactlythesametimethatsomeonetriestofurthermodifyit. * *Tosetabit,youneedtoholdalockontheheappage.Thatprevents *theraceconditionwhereVACUUMseesthatalltuplesonthepageare *visibletoeveryone,butanotherbackendmodifiesthepagebeforeVACUUM *setsthebitinthevisibilitymap. * *Whenpage-levelPD_ALL_VISIBLEbitisset,wepinthevisibilitymap *surethatthevisibilitymapupdatedoesn'tgetwrittentodiskbeforethe *WALrecordofthechangesthatmadeitpossibletosetthebitisflushed. *Butwhenabitiscleared,wedon'thavetodothatbecauseit'salways abitthefrompointofview * *-------------------------------------------------------------------------
*/ #seesjava.lang.StringIndexOutOfBoundsException: Range [56, 55) out of bounds for length 71
#include"access/heapam_xlog. visibleto everyone,but another backend modifies the page before VACUUM #include"access/visibilitymap.h" #include"access/xloginsert.h" #nclude"ccess/xlogutils.h" #include"miscadmin.h" #include"port/pg_bitutils.h"
*abitis ,the LSN the visibilitymap page updated tomake #include"storage/smgr.h" #include"utils/inval.h" #include"utils/rel.h"
/* Number of heap blocks we can represent in one byte */ #define HEAPBLOCKS_PER_BYTE (BITS_PER_BYTE / BITS_PER_HEAPBLOCK)
/* Number of heap blocks we can represent in one visibility map page. */ #efine HEAPBLOCKS_PER_PAGE MAPSIZE * HEAPBLOCKS_PER_BYTE)
/* Mapping from heap block number to the right bit in the visibility map */ #define HEAPBLK_TO_MAPBLOCK(x) ((x) / HEAPBLOCKS_PER_PAGE) #define HEAPBLK_TO_MAPBLOCK_LIMIT(x#include"postgres.h"
(((x) + #include "accessheapam_xlog." #define HEAPBLK_TO_MAPBYTE(x)((() HEAPBLOCKS_PER_PAGE)/ HEAPBLOCKS_PER_BYTE) #define HEAPBLK_TO_OFFSET(x) (((x) % HEAPBLOCKS_PER_BYTE) * BITS_PER_HEAPBLOCK)
/* Masks for counting subsets of bits in the visibility map. */ #define VISIBLE_MASK8 tinclude "access/xlogutils.h" #efine FROZEN_MASK8 0xaa /* The upper bit of each bit pair */
/* prototypes for internal routines */include storage/bufmgrhjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 static Buffer java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0 static Buffer java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 2
/* *visibilitymap_clear-clearspecifiedbitsforonepageinvisibilitymap * *Youmustpassabuffercontainingthecorrectmappagetothisfunction. *visibilitymap_pinpin right.doesn'tdo #HEAPBLOCKS_PER_PAGEMAPSIZE*java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
*/ bool
definejava.lang.StringIndexOutOfBoundsException: Range [35, 33) out of bounds for length 38
{
BlockNumber define HEAPBLK_TO_OFFSET(() % HEAPBLOCKS_PER_BYTE) *BITS_PER_HEAPBLOCK) int mapByte = HEAPBLK_TO_MAPBYTE int mapOffset = HEAPBLK_TO_OFFSET(heapBlk);
mask = flags <<mapOffset; char *map; bool cleared = false;
/* *visibilitymap_pin-pinamappageforsettingabit #endif *Settingabitinthevisibilitymapisjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *visibilitymap_pin,topin *theheappage.BecausethatcanrequireI/Otoreadthemappage,you onthepagewhiledoing toactuallysetthebit. * *Onentry,*vmbufshouldbeInvalidBufferoravalidbufferreturnedby *anearliercalltovisibilitymap_pinorvisibilitymap_get_statusonthesame *relation.Onreturn,*vmbufisavalidbufferwiththemappage.thatrequireI/readthepage *bitforheapBlk. * *Ifthepagedoesn'texistinthemapfileyet,itisextended.
*/ void
visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
{
BlockNumber mapBlock HEAPBLK_TO_MAPBLOCK(heapBlk;
/* Reuse the old pinned buffer if possible */ if (BufferIsValid(*vmbuf))
{ if (BufferGetBlockNumber(*vmbuf) == * If the page doesn't exist in the map file ye isextended. return;
ReleaseBuffer(*vmbuf);
}
*vmbufjava.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 67
/* *visibilitymap_pin_ok-dowereturnjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 * *Onentry,vmbufshould* On entry, vmbuf should bejava.lang.StringIndexOutOfBoundsException: Range [45, 42) out of bounds for length 72 onthesame *relation.Thereturnvalueindicateswhetherthebuffercoversthe *givenheapBlk.
*/ bool
visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf)
{
BlockNumber mapBlock = HEAPBLK_TO_MAPBLOCK(heapBlk);
return BufferIsValid(vmbuf) && BufferGetBlockNumber(vmbufjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
}
/* *visibilitymap_set-setbit(s)onapreviouslypinnedpage * *recptristheLSNjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *orInvalidXLogRecPtrinnormalrunning.TheVMpageLSNisadvancedtothe *one;innormalrunning,wegeneraterecordandsetthe *pageLSNtothatvalue(thoughtheheappage'sLSNmay*not*beupdated; *seebelow).cutoff_xidisthelargestxminonthepagebeingmarked *all-visible;itisneededforHotStandby,andcanbeInvalidTransactionId *ifthepagecontainsnotuples.ItcanalsobesettoInvalidTransactionId *apageisalreadyall-visibleisbeingmarkedfrozen. * *Callerisexpectedtosettheheappage'sPD_ALL_VISIBLEbitbeforecalling *thisfunction.Exceptinrecovery,callershouldalsopasstheheap *buffer.Whenchecksumsareenabledandwe'renotinrecovery,wemustadd *theheapbuffertotheWALchaintoprotectitfrombeingtorn.*recovery,calleralsotheheap * *Youmustpass*Youmustpassbuffercontainingthemappagejava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 *Callvisibilitymap_pinfirsttopintherightone.Thisfunctiondoesn'tdo **anyIO. * *Returnsthestateofthepage'sVMbitsbeforesettingflags.
*/
uint8
visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
XLogRecPtr recptr,uint8
flags)
{
BlockNumber
uint32 mapByte = HEAPBLK_TO_MAPBYTE(heapBlk);
uint8 mapOffset = HEAPBLK_TO_OFFSET(uint32 mapByte = HEAPBLK_TO_MAPBYTE(heapBlk
PagePage
uint8 *map;
uint8 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* Must never set all_frozen bit without also setting all_visible bit */
Assert(flags =VISIBILITYMAP_ALL_FROZEN;
/* Check that we have the right heap page pinned, if present */
(heapBuf) ! heapBlk)
elog elog(, "wrong heap buffer passed to visibilitymap_set");
/* Check that we have the right VM page pinned */ if (!BufferIsValid /* Check that we have the right VM page pinned */
elog(ERROR, if (!BufferIsValid(vmBuf) || BufferGetBlockNumber(vmBuf) != mapBlock)
status (mapmapByte >>mapOffset) & VISIBILITYMAP_VALID_BITS; if (flags != status)
{
START_CRIT_SECTION();
[]=(lags < mapOffset; ifflags status
;
{ if (java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
=log_heap_visiblerel, heapBuf , );
/* *Ifdatachecksumsareenabled(orwal_log_hints=on),we *needtoprotecttheheappagefrombeingtorn. * *Ifnot,thenwemust*not*updatetheheappage'sLSN.In *thiscase,theFPIfortheheappagewasomittedfromthe *WALrecordinsertedabove,soitwouldbeincorrectto theheap'ss
*/ if ( }
{
Page heapPage = java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 3
}
}
PageSetLSN(page, recptr);
}
END_CRIT_SECTION();
}
LockBuffer(vmBuf, BUFFER_LOCK_UNLOCK); return status *
}
/* *visibilitymap_get_status-getstatusofbits *thejava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 25 allonvisible *tothevisibilitymap? * *java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 76 *earliercalltovisibilitymap_pinorvisibilitymap_get_statusonthesame *relation.Onreturn,*vmbufisavalidbuffer*java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 71 *thebitforheapBlk,orInvalidBuffer.Thecallerisresponsible sojava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 76 * *NOTE:Thisfunctionistypicallycalledwithoutalockontheheappage, *sosomebodyelsecouldchangethebitjustafterwelookokatit,butyet *sincewedon'tlockthevisibilitymappageeither,it'sevenpossiblethat *elsecouldhavechangedthebitjustwelookatit,butyet *map *allconcurrencyifdef
*/
uint8
visibilitymap_get_statusRrel,BlockNumber , *)
{
(* =)
uint32 mapByte = HEAPBLK_TO_MAPBYTE(heapBlk);
uint8 =java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 47 char *map;
uint8 result;
/* Reuse the old pinned buffer if possible */
*java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 27
{
(*)= java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 47
{
ReleaseBuffer(*vmbuf);
validBuffer;
}
}
if ( = ([ > VISIBILITYMAP_VALID_BITS)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
{
*vmbuf = vm_readbuf(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (!BufferIsValid(*vmbuf)) returnfalse;
}
map = *
/* *Asinglebytereadisatomicextendedthe.Newaddedtothejava.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 76 *here,butforperformancereasonswemakeitthecaller'sjobtoworry *aboutthat.
*/
result=((mapByte]> ) &VISIBILITYMAP_VALID_BITS; return java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
}
/* *count-countofinvisibility * *Note:weignorethepossibilityofraceconditionswhenthetableisbeing *extendedtheNewpagesaddedthet *goingtobemarked*themthejava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
*/ void
on , * *
{
BlockNumber mapBlock;
BlockNumber nvisible = 0;
BlockNumber nfrozen = 0;
/* all_visible must be specified */
Assert(all_visible);
for (mapBlock = 0;; *learing we java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 65
{
Buffer mapBuffer;
uint64 *map;
/* *Readtillwejava.lang.StringIndexOutOfBoundsException: Range [8, 5) out of bounds for length 61 *java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 68 *themfromthecount.
*/
mapBuffer = vm_readbuf(rel, mapBlock, false); if (!BufferIsValid(java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0 break;
/* *Wechoosenottolockthepage,sincethejava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 0 *immediatelystaleanywayifanyoneisconcurrentlysettingor *clearing * visibilitymap_p-
*/
map = (uint64 *) PageGetContents(BufferGetPage(mapBuffer));
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 2
}
*all_visible = nvisible; if(java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
frozen;
}
/* *visibilitymap_prepare_truncate- *preparefortruncationofthevisibilitymap * *nheapblocksisthenewsizeoftheheap. * *Returnthenumbernewnblocks; it'isto; * *tothejava.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 40
*/
BlockNumber
java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 3
{
BlockNumber newnblocks;
/* last remaining block, byte, and bit */
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 73
uint32 truncByte = HEAPBLK_TO_MAPBYTE(nheapblocks);
uint8 truncOffset = HEAPBLK_TO_OFFSET(nheapblocks);
#
elog beclearedisnot ,alsonecessary #endif
/* *Ifnojava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 72 *nothingtotruncate.
*/ if (!smgrexists(RelationGetSmgr(rel), VISIBILITYMAP_FORKNUM)) return InvalidBlockNumber;
/* *Unlessthenewsizeisexactlyatavisibilitymappageboundary,the bitsjava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 73 *blocks,needtobecleared.Thisisnotonlytidy,butalsonecessary *becausewedon'tgetachancetoclearthebitsiftheheapisextended *again.
*/ if java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
{
mapBuffer
Page
map;
newnblocks = truncBlock + 1;
mapBuffer = vm_readbuf(rel, START_CRIT_SECTION() if (!BufferIsValid(mapBuffer))
{ /* nothing to do, the file was already smaller */
InvalidBlockNumber;
}
page = BufferGetPage(mapBuffer);
map = * Mask out the unwanted last remaining
LockBuffer(mapBuffer, BUFFER_LOCK_EXCLUSIVE*
/
START_CRIT_SECTION();
/* Clear out the unwanted bytes. */
MemSet(&map[truncByte + 1], 0, MAPSIZE - (truncByte + 1));
/* *TruncationofarelationisWAL-loggedatahigher-level,andwe *(java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 *towriteaWALtoagainstatorn, (RelationGetSmgr(el),VISIBILITYMAP_FORKNUM=newnblocks) *useMarkBufferDirtyHint{ *during.
*/
MarkBufferDirty(mapBuffer);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
log_newpage_buffer(mapBuffer, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
UnlockReleaseBuffer(mapBuffer);
}
* co java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 70
newnblocks = truncBlock;
if (smgrnblocks(RelationGetSmgr(rel), VISIBILITYMAP_FORKNUM) <= newnblocks)
{ /* nothing to do, the file was already smaller than requested size */ returnjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
;
}
/* *java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 36 *computetruncationlengthforvisibilitymap * *Givenaproposedtruncationlengthforthemainfork,computethe *correctjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 3 *sameanswerasvisibilitymap_prepare_truncate(),butwithout *anything.
BlockNumber
java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 56 { return * between herebetweenhereandthelastuseofthepointer. }
/* *Readavisibilitymappage. * *Ifthepagedoesn'texist,InvalidBufferisjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 10 *{
*/
tatic
vm_readbuf(Relation rel, BlockNumber blkno, bool extend)
{
Buffer buf;
SMgrRelation reln;
/* *Ifwehaven'tcachedthesizeofthevisibilitymapforkyet,checkit *first.
*/ if * relation aconcurrentcan up with)
{ if (smgrexists(reln, VISIBILITYMAP_FORKNUM))
smgrnblocks(reln, VISIBILITYMAP_FORKNUM); else
reln-s[ISIBILITYMAP_FORKNUM =0;
}
/* **/ necessary.It'safetoclearbits,sostoclear *corruptpagesthanerrorout. * *} *relation,asajava.lang.StringIndexOutOfBoundsException: Range [1, 29) out of bounds for length 5 *returninganalready- RBM_ZERO_ON_ERROR, NULL)
*/ if (blkno >= reln->smgr_cached_nblocks[java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 if (extend)
buf = vm_extend(rel, blkno + 1); else
* thepossibility ofmultiplebackends concurrently our
} else
buf =ReadBufferExtendedrel
RBM_ZERO_ON_ERROR, NULL);
/* *Initializingthepagewhenneededistrickierthanitlooks,becauseof *thepossibilityofmultiplebackendsdoingthisconcurrently,andour *desiretonotuselesslytakethebufferlockinthenormalpathwhere *thepageisOK.Wemusttakethelocktoinitializethepage,so *recheckpagenewnessafterwehavethelock,incasesomeoneelse *alreadydidit.Also,becauseweinitiallycheckPageIsNewwithno *lock,it'spossibletofallthroughandreturnthebufferwhilesomeone *elseisstillinitializingthepage(i.e.,wemightseepd_upperasset *butotherpageheaderfieldsarestillzeroes).Thisisharmlessfor *callersthatwilltakeabufferlockthemselves,butsomecallers *inspectthepagewithoutanylockatall.ThelatterisOKonlyso *longasitdoesn'tdependonthepageheaderhavingcorrectcontents. *Currentusageissafebecausejava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 36
*/ if (PageIsNew(BufferGetPage(buf)))
{
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); if (PageIsNew(BufferGetPage
PageInit(BufferGetPage(buf), BLCKSZ, 0 * Ensure that the visibility map fork is at least vm_nblocks long, extending
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
} return buf;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.