mirror of
https://github.com/postgres/postgres.git
synced 2025-12-17 00:03:29 -05:00
Simplify hash_xlog_split_allocate_page()
Instead of complicated pointer arithmetic, overlay a uint32 array and just access the array members. That's safe thanks to XLogRecGetBlockData() returning a MAXALIGNed buffer. Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/aSQy2JawavlVlEB0%40ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
parent
ec782f56b0
commit
35988b31db
@ -314,8 +314,6 @@ hash_xlog_split_allocate_page(XLogReaderState *record)
|
|||||||
Buffer oldbuf;
|
Buffer oldbuf;
|
||||||
Buffer newbuf;
|
Buffer newbuf;
|
||||||
Buffer metabuf;
|
Buffer metabuf;
|
||||||
Size datalen PG_USED_FOR_ASSERTS_ONLY;
|
|
||||||
char *data;
|
|
||||||
XLogRedoAction action;
|
XLogRedoAction action;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -375,6 +373,10 @@ hash_xlog_split_allocate_page(XLogReaderState *record)
|
|||||||
{
|
{
|
||||||
Page page;
|
Page page;
|
||||||
HashMetaPage metap;
|
HashMetaPage metap;
|
||||||
|
Size datalen;
|
||||||
|
char *data;
|
||||||
|
uint32 *uidata;
|
||||||
|
int uidatacount;
|
||||||
|
|
||||||
page = BufferGetPage(metabuf);
|
page = BufferGetPage(metabuf);
|
||||||
metap = HashPageGetMeta(page);
|
metap = HashPageGetMeta(page);
|
||||||
@ -382,34 +384,31 @@ hash_xlog_split_allocate_page(XLogReaderState *record)
|
|||||||
|
|
||||||
data = XLogRecGetBlockData(record, 2, &datalen);
|
data = XLogRecGetBlockData(record, 2, &datalen);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This cast is ok because XLogRecGetBlockData() returns a MAXALIGNed
|
||||||
|
* buffer.
|
||||||
|
*/
|
||||||
|
uidata = (uint32 *) data;
|
||||||
|
uidatacount = 0;
|
||||||
|
|
||||||
if (xlrec->flags & XLH_SPLIT_META_UPDATE_MASKS)
|
if (xlrec->flags & XLH_SPLIT_META_UPDATE_MASKS)
|
||||||
{
|
{
|
||||||
uint32 lowmask;
|
uint32 lowmask = uidata[uidatacount++];
|
||||||
uint32 *highmask;
|
uint32 highmask = uidata[uidatacount++];
|
||||||
|
|
||||||
/* extract low and high masks. */
|
|
||||||
memcpy(&lowmask, data, sizeof(uint32));
|
|
||||||
highmask = (uint32 *) ((char *) data + sizeof(uint32));
|
|
||||||
|
|
||||||
/* update metapage */
|
/* update metapage */
|
||||||
metap->hashm_lowmask = lowmask;
|
metap->hashm_lowmask = lowmask;
|
||||||
metap->hashm_highmask = *highmask;
|
metap->hashm_highmask = highmask;
|
||||||
|
|
||||||
data += sizeof(uint32) * 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xlrec->flags & XLH_SPLIT_META_UPDATE_SPLITPOINT)
|
if (xlrec->flags & XLH_SPLIT_META_UPDATE_SPLITPOINT)
|
||||||
{
|
{
|
||||||
uint32 ovflpoint;
|
uint32 ovflpoint = uidata[uidatacount++];
|
||||||
uint32 *ovflpages;
|
uint32 ovflpages = uidata[uidatacount++];
|
||||||
|
|
||||||
/* extract information of overflow pages. */
|
|
||||||
memcpy(&ovflpoint, data, sizeof(uint32));
|
|
||||||
ovflpages = (uint32 *) ((char *) data + sizeof(uint32));
|
|
||||||
|
|
||||||
/* update metapage */
|
/* update metapage */
|
||||||
metap->hashm_spares[ovflpoint] = *ovflpages;
|
|
||||||
metap->hashm_ovflpoint = ovflpoint;
|
metap->hashm_ovflpoint = ovflpoint;
|
||||||
|
metap->hashm_spares[ovflpoint] = ovflpages;
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkBufferDirty(metabuf);
|
MarkBufferDirty(metabuf);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user