mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Avoid using potentially-under-aligned page buffers.
There's a project policy against using plain "char buf[BLCKSZ]" local or static variables as page buffers; preferred style is to palloc or malloc each buffer to ensure it is MAXALIGN'd. However, that policy's been ignored in an increasing number of places. We've apparently got away with it so far, probably because (a) relatively few people use platforms on which misalignment causes core dumps and/or (b) the variables chance to be sufficiently aligned anyway. But this is not something to rely on. Moreover, even if we don't get a core dump, we might be paying a lot of cycles for misaligned accesses. To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock that the compiler must allocate with sufficient alignment, and use those in place of plain char arrays. I used these types even for variables where there's no risk of a misaligned access, since ensuring proper alignment should make kernel data transfers faster. I also changed some places where we had been palloc'ing short-lived buffers, for coding style uniformity and to save palloc/pfree overhead. Since this seems to be a live portability hazard (despite the lack of field reports), back-patch to all supported versions. Patch by me; thanks to Michael Paquier for review. Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de
This commit is contained in:
		@@ -36,7 +36,7 @@ typedef struct
 | 
				
			|||||||
	int64		indtuples;		/* total number of tuples indexed */
 | 
						int64		indtuples;		/* total number of tuples indexed */
 | 
				
			||||||
	MemoryContext tmpCtx;		/* temporary memory context reset after each
 | 
						MemoryContext tmpCtx;		/* temporary memory context reset after each
 | 
				
			||||||
								 * tuple */
 | 
													 * tuple */
 | 
				
			||||||
	char		data[BLCKSZ];	/* cached page */
 | 
						PGAlignedBlock data;		/* cached page */
 | 
				
			||||||
	int			count;			/* number of tuples in cached page */
 | 
						int			count;			/* number of tuples in cached page */
 | 
				
			||||||
} BloomBuildState;
 | 
					} BloomBuildState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,7 +52,7 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	state = GenericXLogStart(index);
 | 
						state = GenericXLogStart(index);
 | 
				
			||||||
	page = GenericXLogRegisterBuffer(state, buffer, GENERIC_XLOG_FULL_IMAGE);
 | 
						page = GenericXLogRegisterBuffer(state, buffer, GENERIC_XLOG_FULL_IMAGE);
 | 
				
			||||||
	memcpy(page, buildstate->data, BLCKSZ);
 | 
						memcpy(page, buildstate->data.data, BLCKSZ);
 | 
				
			||||||
	GenericXLogFinish(state);
 | 
						GenericXLogFinish(state);
 | 
				
			||||||
	UnlockReleaseBuffer(buffer);
 | 
						UnlockReleaseBuffer(buffer);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -63,8 +63,8 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
initCachedPage(BloomBuildState *buildstate)
 | 
					initCachedPage(BloomBuildState *buildstate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	memset(buildstate->data, 0, BLCKSZ);
 | 
						memset(buildstate->data.data, 0, BLCKSZ);
 | 
				
			||||||
	BloomInitPage(buildstate->data, 0);
 | 
						BloomInitPage(buildstate->data.data, 0);
 | 
				
			||||||
	buildstate->count = 0;
 | 
						buildstate->count = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -84,7 +84,7 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
 | 
				
			|||||||
	itup = BloomFormTuple(&buildstate->blstate, &htup->t_self, values, isnull);
 | 
						itup = BloomFormTuple(&buildstate->blstate, &htup->t_self, values, isnull);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Try to add next item to cached page */
 | 
						/* Try to add next item to cached page */
 | 
				
			||||||
	if (BloomPageAddItem(&buildstate->blstate, buildstate->data, itup))
 | 
						if (BloomPageAddItem(&buildstate->blstate, buildstate->data.data, itup))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* Next item was added successfully */
 | 
							/* Next item was added successfully */
 | 
				
			||||||
		buildstate->count++;
 | 
							buildstate->count++;
 | 
				
			||||||
@@ -98,7 +98,7 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		initCachedPage(buildstate);
 | 
							initCachedPage(buildstate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!BloomPageAddItem(&buildstate->blstate, buildstate->data, itup))
 | 
							if (!BloomPageAddItem(&buildstate->blstate, buildstate->data.data, itup))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			/* We shouldn't be here since we're inserting to the empty page */
 | 
								/* We shouldn't be here since we're inserting to the empty page */
 | 
				
			||||||
			elog(ERROR, "could not add new bloom tuple to empty page");
 | 
								elog(ERROR, "could not add new bloom tuple to empty page");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,7 @@ typedef enum
 | 
				
			|||||||
	PREWARM_BUFFER
 | 
						PREWARM_BUFFER
 | 
				
			||||||
} PrewarmType;
 | 
					} PrewarmType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char blockbuffer[BLCKSZ];
 | 
					static PGAlignedBlock blockbuffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * pg_prewarm(regclass, mode text, fork text,
 | 
					 * pg_prewarm(regclass, mode text, fork text,
 | 
				
			||||||
@@ -179,7 +179,7 @@ pg_prewarm(PG_FUNCTION_ARGS)
 | 
				
			|||||||
		for (block = first_block; block <= last_block; ++block)
 | 
							for (block = first_block; block <= last_block; ++block)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			CHECK_FOR_INTERRUPTS();
 | 
								CHECK_FOR_INTERRUPTS();
 | 
				
			||||||
			smgrread(rel->rd_smgr, forkNumber, block, blockbuffer);
 | 
								smgrread(rel->rd_smgr, forkNumber, block, blockbuffer.data);
 | 
				
			||||||
			++blocks_done;
 | 
								++blocks_done;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -616,7 +616,7 @@ entrySplitPage(GinBtree btree, Buffer origbuf,
 | 
				
			|||||||
	Page		lpage = PageGetTempPageCopy(BufferGetPage(origbuf));
 | 
						Page		lpage = PageGetTempPageCopy(BufferGetPage(origbuf));
 | 
				
			||||||
	Page		rpage = PageGetTempPageCopy(BufferGetPage(origbuf));
 | 
						Page		rpage = PageGetTempPageCopy(BufferGetPage(origbuf));
 | 
				
			||||||
	Size		pageSize = PageGetPageSize(lpage);
 | 
						Size		pageSize = PageGetPageSize(lpage);
 | 
				
			||||||
	char		tupstore[2 * BLCKSZ];
 | 
						PGAlignedBlock tupstore[2]; /* could need 2 pages' worth of tuples */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entryPreparePage(btree, lpage, off, insertData, updateblkno);
 | 
						entryPreparePage(btree, lpage, off, insertData, updateblkno);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -625,7 +625,7 @@ entrySplitPage(GinBtree btree, Buffer origbuf,
 | 
				
			|||||||
	 * one after another in a temporary workspace.
 | 
						 * one after another in a temporary workspace.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	maxoff = PageGetMaxOffsetNumber(lpage);
 | 
						maxoff = PageGetMaxOffsetNumber(lpage);
 | 
				
			||||||
	ptr = tupstore;
 | 
						ptr = tupstore[0].data;
 | 
				
			||||||
	for (i = FirstOffsetNumber; i <= maxoff; i++)
 | 
						for (i = FirstOffsetNumber; i <= maxoff; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (i == off)
 | 
							if (i == off)
 | 
				
			||||||
@@ -658,7 +658,7 @@ entrySplitPage(GinBtree btree, Buffer origbuf,
 | 
				
			|||||||
	GinInitPage(rpage, GinPageGetOpaque(lpage)->flags, pageSize);
 | 
						GinInitPage(rpage, GinPageGetOpaque(lpage)->flags, pageSize);
 | 
				
			||||||
	GinInitPage(lpage, GinPageGetOpaque(rpage)->flags, pageSize);
 | 
						GinInitPage(lpage, GinPageGetOpaque(rpage)->flags, pageSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ptr = tupstore;
 | 
						ptr = tupstore[0].data;
 | 
				
			||||||
	maxoff++;
 | 
						maxoff++;
 | 
				
			||||||
	lsize = 0;
 | 
						lsize = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,18 +63,15 @@ writeListPage(Relation index, Buffer buffer,
 | 
				
			|||||||
				size = 0;
 | 
									size = 0;
 | 
				
			||||||
	OffsetNumber l,
 | 
						OffsetNumber l,
 | 
				
			||||||
				off;
 | 
									off;
 | 
				
			||||||
	char	   *workspace;
 | 
						PGAlignedBlock workspace;
 | 
				
			||||||
	char	   *ptr;
 | 
						char	   *ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* workspace could be a local array; we use palloc for alignment */
 | 
					 | 
				
			||||||
	workspace = palloc(BLCKSZ);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	START_CRIT_SECTION();
 | 
						START_CRIT_SECTION();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GinInitBuffer(buffer, GIN_LIST);
 | 
						GinInitBuffer(buffer, GIN_LIST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	off = FirstOffsetNumber;
 | 
						off = FirstOffsetNumber;
 | 
				
			||||||
	ptr = workspace;
 | 
						ptr = workspace.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ntuples; i++)
 | 
						for (i = 0; i < ntuples; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -126,7 +123,7 @@ writeListPage(Relation index, Buffer buffer,
 | 
				
			|||||||
		XLogRegisterData((char *) &data, sizeof(ginxlogInsertListPage));
 | 
							XLogRegisterData((char *) &data, sizeof(ginxlogInsertListPage));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		XLogRegisterBuffer(0, buffer, REGBUF_WILL_INIT);
 | 
							XLogRegisterBuffer(0, buffer, REGBUF_WILL_INIT);
 | 
				
			||||||
		XLogRegisterBufData(0, workspace, size);
 | 
							XLogRegisterBufData(0, workspace.data, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_INSERT_LISTPAGE);
 | 
							recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_INSERT_LISTPAGE);
 | 
				
			||||||
		PageSetLSN(page, recptr);
 | 
							PageSetLSN(page, recptr);
 | 
				
			||||||
@@ -139,8 +136,6 @@ writeListPage(Relation index, Buffer buffer,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	END_CRIT_SECTION();
 | 
						END_CRIT_SECTION();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pfree(workspace);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return freesize;
 | 
						return freesize;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -998,7 +998,7 @@ static bool
 | 
				
			|||||||
_hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
 | 
					_hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	BlockNumber lastblock;
 | 
						BlockNumber lastblock;
 | 
				
			||||||
	char		zerobuf[BLCKSZ];
 | 
						PGAlignedBlock zerobuf;
 | 
				
			||||||
	Page		page;
 | 
						Page		page;
 | 
				
			||||||
	HashPageOpaque ovflopaque;
 | 
						HashPageOpaque ovflopaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1011,7 +1011,7 @@ _hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
 | 
				
			|||||||
	if (lastblock < firstblock || lastblock == InvalidBlockNumber)
 | 
						if (lastblock < firstblock || lastblock == InvalidBlockNumber)
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	page = (Page) zerobuf;
 | 
						page = (Page) zerobuf.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Initialize the page.  Just zeroing the page won't work; see
 | 
						 * Initialize the page.  Just zeroing the page won't work; see
 | 
				
			||||||
@@ -1032,11 +1032,11 @@ _hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
 | 
				
			|||||||
		log_newpage(&rel->rd_node,
 | 
							log_newpage(&rel->rd_node,
 | 
				
			||||||
					MAIN_FORKNUM,
 | 
										MAIN_FORKNUM,
 | 
				
			||||||
					lastblock,
 | 
										lastblock,
 | 
				
			||||||
					zerobuf,
 | 
										zerobuf.data,
 | 
				
			||||||
					true);
 | 
										true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RelationOpenSmgr(rel);
 | 
						RelationOpenSmgr(rel);
 | 
				
			||||||
	smgrextend(rel->rd_smgr, MAIN_FORKNUM, lastblock, zerobuf, false);
 | 
						smgrextend(rel->rd_smgr, MAIN_FORKNUM, lastblock, zerobuf.data, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2662,7 +2662,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
 | 
				
			|||||||
	HeapTuple  *heaptuples;
 | 
						HeapTuple  *heaptuples;
 | 
				
			||||||
	int			i;
 | 
						int			i;
 | 
				
			||||||
	int			ndone;
 | 
						int			ndone;
 | 
				
			||||||
	char	   *scratch = NULL;
 | 
						PGAlignedBlock scratch;
 | 
				
			||||||
	Page		page;
 | 
						Page		page;
 | 
				
			||||||
	bool		needwal;
 | 
						bool		needwal;
 | 
				
			||||||
	Size		saveFreeSpace;
 | 
						Size		saveFreeSpace;
 | 
				
			||||||
@@ -2679,14 +2679,6 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
 | 
				
			|||||||
		heaptuples[i] = heap_prepare_insert(relation, tuples[i],
 | 
							heaptuples[i] = heap_prepare_insert(relation, tuples[i],
 | 
				
			||||||
											xid, cid, options);
 | 
																xid, cid, options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * Allocate some memory to use for constructing the WAL record. Using
 | 
					 | 
				
			||||||
	 * palloc() within a critical section is not safe, so we allocate this
 | 
					 | 
				
			||||||
	 * beforehand.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	if (needwal)
 | 
					 | 
				
			||||||
		scratch = palloc(BLCKSZ);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * We're about to do the actual inserts -- but check for conflict first,
 | 
						 * We're about to do the actual inserts -- but check for conflict first,
 | 
				
			||||||
	 * to minimize the possibility of having to roll back work we've just
 | 
						 * to minimize the possibility of having to roll back work we've just
 | 
				
			||||||
@@ -2779,7 +2771,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
 | 
				
			|||||||
			uint8		info = XLOG_HEAP2_MULTI_INSERT;
 | 
								uint8		info = XLOG_HEAP2_MULTI_INSERT;
 | 
				
			||||||
			char	   *tupledata;
 | 
								char	   *tupledata;
 | 
				
			||||||
			int			totaldatalen;
 | 
								int			totaldatalen;
 | 
				
			||||||
			char	   *scratchptr = scratch;
 | 
								char	   *scratchptr = scratch.data;
 | 
				
			||||||
			bool		init;
 | 
								bool		init;
 | 
				
			||||||
			int			bufflags = 0;
 | 
								int			bufflags = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2838,7 +2830,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
 | 
				
			|||||||
				scratchptr += datalen;
 | 
									scratchptr += datalen;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			totaldatalen = scratchptr - tupledata;
 | 
								totaldatalen = scratchptr - tupledata;
 | 
				
			||||||
			Assert((scratchptr - scratch) < BLCKSZ);
 | 
								Assert((scratchptr - scratch.data) < BLCKSZ);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (need_tuple_data)
 | 
								if (need_tuple_data)
 | 
				
			||||||
				xlrec->flags |= XLH_INSERT_CONTAINS_NEW_TUPLE;
 | 
									xlrec->flags |= XLH_INSERT_CONTAINS_NEW_TUPLE;
 | 
				
			||||||
@@ -2865,7 +2857,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
 | 
				
			|||||||
				bufflags |= REGBUF_KEEP_DATA;
 | 
									bufflags |= REGBUF_KEEP_DATA;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			XLogBeginInsert();
 | 
								XLogBeginInsert();
 | 
				
			||||||
			XLogRegisterData((char *) xlrec, tupledata - scratch);
 | 
								XLogRegisterData((char *) xlrec, tupledata - scratch.data);
 | 
				
			||||||
			XLogRegisterBuffer(0, buffer, REGBUF_STANDARD | bufflags);
 | 
								XLogRegisterBuffer(0, buffer, REGBUF_STANDARD | bufflags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			XLogRegisterBufData(0, tupledata, totaldatalen);
 | 
								XLogRegisterBufData(0, tupledata, totaldatalen);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -645,10 +645,9 @@ static void
 | 
				
			|||||||
vm_extend(Relation rel, BlockNumber vm_nblocks)
 | 
					vm_extend(Relation rel, BlockNumber vm_nblocks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	BlockNumber vm_nblocks_now;
 | 
						BlockNumber vm_nblocks_now;
 | 
				
			||||||
	Page		pg;
 | 
						PGAlignedBlock pg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pg = (Page) palloc(BLCKSZ);
 | 
						PageInit((Page) pg.data, BLCKSZ, 0);
 | 
				
			||||||
	PageInit(pg, BLCKSZ, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * We use the relation extension lock to lock out other backends trying to
 | 
						 * We use the relation extension lock to lock out other backends trying to
 | 
				
			||||||
@@ -679,10 +678,10 @@ vm_extend(Relation rel, BlockNumber vm_nblocks)
 | 
				
			|||||||
	/* Now extend the file */
 | 
						/* Now extend the file */
 | 
				
			||||||
	while (vm_nblocks_now < vm_nblocks)
 | 
						while (vm_nblocks_now < vm_nblocks)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		PageSetChecksumInplace(pg, vm_nblocks_now);
 | 
							PageSetChecksumInplace((Page) pg.data, vm_nblocks_now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		smgrextend(rel->rd_smgr, VISIBILITYMAP_FORKNUM, vm_nblocks_now,
 | 
							smgrextend(rel->rd_smgr, VISIBILITYMAP_FORKNUM, vm_nblocks_now,
 | 
				
			||||||
				   (char *) pg, false);
 | 
									   pg.data, false);
 | 
				
			||||||
		vm_nblocks_now++;
 | 
							vm_nblocks_now++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -699,6 +698,4 @@ vm_extend(Relation rel, BlockNumber vm_nblocks)
 | 
				
			|||||||
	rel->rd_smgr->smgr_vm_nblocks = vm_nblocks_now;
 | 
						rel->rd_smgr->smgr_vm_nblocks = vm_nblocks_now;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UnlockRelationForExtension(rel, ExclusiveLock);
 | 
						UnlockRelationForExtension(rel, ExclusiveLock);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	pfree(pg);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,14 +61,11 @@ typedef struct
 | 
				
			|||||||
/* State of generic xlog record construction */
 | 
					/* State of generic xlog record construction */
 | 
				
			||||||
struct GenericXLogState
 | 
					struct GenericXLogState
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/*
 | 
						/* Info about each page, see above */
 | 
				
			||||||
	 * page's images. Should be first in this struct to have MAXALIGN'ed
 | 
					 | 
				
			||||||
	 * images addresses, because some code working with pages directly aligns
 | 
					 | 
				
			||||||
	 * addresses, not offsets from beginning of page
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	char		images[MAX_GENERIC_XLOG_PAGES * BLCKSZ];
 | 
					 | 
				
			||||||
	PageData	pages[MAX_GENERIC_XLOG_PAGES];
 | 
						PageData	pages[MAX_GENERIC_XLOG_PAGES];
 | 
				
			||||||
	bool		isLogged;
 | 
						bool		isLogged;
 | 
				
			||||||
 | 
						/* Page images (properly aligned) */
 | 
				
			||||||
 | 
						PGAlignedBlock images[MAX_GENERIC_XLOG_PAGES];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void writeFragment(PageData *pageData, OffsetNumber offset,
 | 
					static void writeFragment(PageData *pageData, OffsetNumber offset,
 | 
				
			||||||
@@ -251,12 +248,12 @@ computeDelta(PageData *pageData, Page curpage, Page targetpage)
 | 
				
			|||||||
#ifdef WAL_DEBUG
 | 
					#ifdef WAL_DEBUG
 | 
				
			||||||
	if (XLOG_DEBUG)
 | 
						if (XLOG_DEBUG)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char		tmp[BLCKSZ];
 | 
							PGAlignedBlock tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		memcpy(tmp, curpage, BLCKSZ);
 | 
							memcpy(tmp.data, curpage, BLCKSZ);
 | 
				
			||||||
		applyPageRedo(tmp, pageData->delta, pageData->deltaLen);
 | 
							applyPageRedo(tmp.data, pageData->delta, pageData->deltaLen);
 | 
				
			||||||
		if (memcmp(tmp, targetpage, targetLower) != 0 ||
 | 
							if (memcmp(tmp.data, targetpage, targetLower) != 0 ||
 | 
				
			||||||
			memcmp(tmp + targetUpper, targetpage + targetUpper,
 | 
								memcmp(tmp.data + targetUpper, targetpage + targetUpper,
 | 
				
			||||||
				   BLCKSZ - targetUpper) != 0)
 | 
									   BLCKSZ - targetUpper) != 0)
 | 
				
			||||||
			elog(ERROR, "result of generic xlog apply does not match");
 | 
								elog(ERROR, "result of generic xlog apply does not match");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -277,7 +274,7 @@ GenericXLogStart(Relation relation)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
 | 
						for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		state->pages[i].image = state->images + BLCKSZ * i;
 | 
							state->pages[i].image = state->images[i].data;
 | 
				
			||||||
		state->pages[i].buffer = InvalidBuffer;
 | 
							state->pages[i].buffer = InvalidBuffer;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3182,8 +3182,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	char		path[MAXPGPATH];
 | 
						char		path[MAXPGPATH];
 | 
				
			||||||
	char		tmppath[MAXPGPATH];
 | 
						char		tmppath[MAXPGPATH];
 | 
				
			||||||
	char		zbuffer_raw[XLOG_BLCKSZ + MAXIMUM_ALIGNOF];
 | 
						PGAlignedXLogBlock zbuffer;
 | 
				
			||||||
	char	   *zbuffer;
 | 
					 | 
				
			||||||
	XLogSegNo	installed_segno;
 | 
						XLogSegNo	installed_segno;
 | 
				
			||||||
	XLogSegNo	max_segno;
 | 
						XLogSegNo	max_segno;
 | 
				
			||||||
	int			fd;
 | 
						int			fd;
 | 
				
			||||||
@@ -3237,17 +3236,13 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
 | 
				
			|||||||
	 * fsync below) that all the indirect blocks are down on disk.  Therefore,
 | 
						 * fsync below) that all the indirect blocks are down on disk.  Therefore,
 | 
				
			||||||
	 * fdatasync(2) or O_DSYNC will be sufficient to sync future writes to the
 | 
						 * fdatasync(2) or O_DSYNC will be sufficient to sync future writes to the
 | 
				
			||||||
	 * log file.
 | 
						 * log file.
 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * Note: ensure the buffer is reasonably well-aligned; this may save a few
 | 
					 | 
				
			||||||
	 * cycles transferring data to the kernel.
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	zbuffer = (char *) MAXALIGN(zbuffer_raw);
 | 
						memset(zbuffer.data, 0, XLOG_BLCKSZ);
 | 
				
			||||||
	memset(zbuffer, 0, XLOG_BLCKSZ);
 | 
					 | 
				
			||||||
	for (nbytes = 0; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
 | 
						for (nbytes = 0; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		errno = 0;
 | 
							errno = 0;
 | 
				
			||||||
		pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_WRITE);
 | 
							pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_WRITE);
 | 
				
			||||||
		if ((int) write(fd, zbuffer, XLOG_BLCKSZ) != (int) XLOG_BLCKSZ)
 | 
							if ((int) write(fd, zbuffer.data, XLOG_BLCKSZ) != (int) XLOG_BLCKSZ)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			int			save_errno = errno;
 | 
								int			save_errno = errno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3355,7 +3350,7 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	char		path[MAXPGPATH];
 | 
						char		path[MAXPGPATH];
 | 
				
			||||||
	char		tmppath[MAXPGPATH];
 | 
						char		tmppath[MAXPGPATH];
 | 
				
			||||||
	char		buffer[XLOG_BLCKSZ];
 | 
						PGAlignedXLogBlock buffer;
 | 
				
			||||||
	int			srcfd;
 | 
						int			srcfd;
 | 
				
			||||||
	int			fd;
 | 
						int			fd;
 | 
				
			||||||
	int			nbytes;
 | 
						int			nbytes;
 | 
				
			||||||
@@ -3399,7 +3394,7 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
 | 
				
			|||||||
		 * zeros.
 | 
							 * zeros.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (nread < sizeof(buffer))
 | 
							if (nread < sizeof(buffer))
 | 
				
			||||||
			memset(buffer, 0, sizeof(buffer));
 | 
								memset(buffer.data, 0, sizeof(buffer));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (nread > 0)
 | 
							if (nread > 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -3407,7 +3402,7 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
 | 
				
			|||||||
				nread = sizeof(buffer);
 | 
									nread = sizeof(buffer);
 | 
				
			||||||
			errno = 0;
 | 
								errno = 0;
 | 
				
			||||||
			pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ);
 | 
								pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ);
 | 
				
			||||||
			if (read(srcfd, buffer, nread) != nread)
 | 
								if (read(srcfd, buffer.data, nread) != nread)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (errno != 0)
 | 
									if (errno != 0)
 | 
				
			||||||
					ereport(ERROR,
 | 
										ereport(ERROR,
 | 
				
			||||||
@@ -3423,7 +3418,7 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		errno = 0;
 | 
							errno = 0;
 | 
				
			||||||
		pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE);
 | 
							pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE);
 | 
				
			||||||
		if ((int) write(fd, buffer, sizeof(buffer)) != (int) sizeof(buffer))
 | 
							if ((int) write(fd, buffer.data, sizeof(buffer)) != (int) sizeof(buffer))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			int			save_errno = errno;
 | 
								int			save_errno = errno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -6410,8 +6405,11 @@ StartupXLOG(void)
 | 
				
			|||||||
	xlogreader->system_identifier = ControlFile->system_identifier;
 | 
						xlogreader->system_identifier = ControlFile->system_identifier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Allocate pages dedicated to WAL consistency checks, those had better be
 | 
						 * Allocate two page buffers dedicated to WAL consistency checks.  We do
 | 
				
			||||||
	 * aligned.
 | 
						 * it this way, rather than just making static arrays, for two reasons:
 | 
				
			||||||
 | 
						 * (1) no need to waste the storage in most instantiations of the backend;
 | 
				
			||||||
 | 
						 * (2) a static char array isn't guaranteed to have any particular
 | 
				
			||||||
 | 
						 * alignment, whereas palloc() will provide MAXALIGN'd storage.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	replay_image_masked = (char *) palloc(BLCKSZ);
 | 
						replay_image_masked = (char *) palloc(BLCKSZ);
 | 
				
			||||||
	master_image_masked = (char *) palloc(BLCKSZ);
 | 
						master_image_masked = (char *) palloc(BLCKSZ);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -809,12 +809,12 @@ XLogCompressBackupBlock(char *page, uint16 hole_offset, uint16 hole_length,
 | 
				
			|||||||
	int32		len;
 | 
						int32		len;
 | 
				
			||||||
	int32		extra_bytes = 0;
 | 
						int32		extra_bytes = 0;
 | 
				
			||||||
	char	   *source;
 | 
						char	   *source;
 | 
				
			||||||
	char		tmp[BLCKSZ];
 | 
						PGAlignedBlock tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (hole_length != 0)
 | 
						if (hole_length != 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* must skip the hole */
 | 
							/* must skip the hole */
 | 
				
			||||||
		source = tmp;
 | 
							source = tmp.data;
 | 
				
			||||||
		memcpy(source, page, hole_offset);
 | 
							memcpy(source, page, hole_offset);
 | 
				
			||||||
		memcpy(source + hole_offset,
 | 
							memcpy(source + hole_offset,
 | 
				
			||||||
			   page + (hole_offset + hole_length),
 | 
								   page + (hole_offset + hole_length),
 | 
				
			||||||
@@ -917,7 +917,7 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
 | 
				
			|||||||
	if (lsn <= RedoRecPtr)
 | 
						if (lsn <= RedoRecPtr)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		int			flags;
 | 
							int			flags;
 | 
				
			||||||
		char		copied_buffer[BLCKSZ];
 | 
							PGAlignedBlock copied_buffer;
 | 
				
			||||||
		char	   *origdata = (char *) BufferGetBlock(buffer);
 | 
							char	   *origdata = (char *) BufferGetBlock(buffer);
 | 
				
			||||||
		RelFileNode rnode;
 | 
							RelFileNode rnode;
 | 
				
			||||||
		ForkNumber	forkno;
 | 
							ForkNumber	forkno;
 | 
				
			||||||
@@ -935,11 +935,11 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
 | 
				
			|||||||
			uint16		lower = ((PageHeader) page)->pd_lower;
 | 
								uint16		lower = ((PageHeader) page)->pd_lower;
 | 
				
			||||||
			uint16		upper = ((PageHeader) page)->pd_upper;
 | 
								uint16		upper = ((PageHeader) page)->pd_upper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			memcpy(copied_buffer, origdata, lower);
 | 
								memcpy(copied_buffer.data, origdata, lower);
 | 
				
			||||||
			memcpy(copied_buffer + upper, origdata + upper, BLCKSZ - upper);
 | 
								memcpy(copied_buffer.data + upper, origdata + upper, BLCKSZ - upper);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			memcpy(copied_buffer, origdata, BLCKSZ);
 | 
								memcpy(copied_buffer.data, origdata, BLCKSZ);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		XLogBeginInsert();
 | 
							XLogBeginInsert();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -948,7 +948,7 @@ XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
 | 
				
			|||||||
			flags |= REGBUF_STANDARD;
 | 
								flags |= REGBUF_STANDARD;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		BufferGetTag(buffer, &rnode, &forkno, &blkno);
 | 
							BufferGetTag(buffer, &rnode, &forkno, &blkno);
 | 
				
			||||||
		XLogRegisterBlock(0, &rnode, forkno, blkno, copied_buffer, flags);
 | 
							XLogRegisterBlock(0, &rnode, forkno, blkno, copied_buffer.data, flags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
 | 
							recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1404,7 +1404,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	DecodedBkpBlock *bkpb;
 | 
						DecodedBkpBlock *bkpb;
 | 
				
			||||||
	char	   *ptr;
 | 
						char	   *ptr;
 | 
				
			||||||
	char		tmp[BLCKSZ];
 | 
						PGAlignedBlock tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!record->blocks[block_id].in_use)
 | 
						if (!record->blocks[block_id].in_use)
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
@@ -1417,7 +1417,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
 | 
				
			|||||||
	if (bkpb->bimg_info & BKPIMAGE_IS_COMPRESSED)
 | 
						if (bkpb->bimg_info & BKPIMAGE_IS_COMPRESSED)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* If a backup block image is compressed, decompress it */
 | 
							/* If a backup block image is compressed, decompress it */
 | 
				
			||||||
		if (pglz_decompress(ptr, bkpb->bimg_len, tmp,
 | 
							if (pglz_decompress(ptr, bkpb->bimg_len, tmp.data,
 | 
				
			||||||
							BLCKSZ - bkpb->hole_length) < 0)
 | 
												BLCKSZ - bkpb->hole_length) < 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			report_invalid_record(record, "invalid compressed image at %X/%X, block %d",
 | 
								report_invalid_record(record, "invalid compressed image at %X/%X, block %d",
 | 
				
			||||||
@@ -1426,7 +1426,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
 | 
				
			|||||||
								  block_id);
 | 
													  block_id);
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ptr = tmp;
 | 
							ptr = tmp.data;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* generate page, taking into account hole if necessary */
 | 
						/* generate page, taking into account hole if necessary */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10820,21 +10820,14 @@ static void
 | 
				
			|||||||
copy_relation_data(SMgrRelation src, SMgrRelation dst,
 | 
					copy_relation_data(SMgrRelation src, SMgrRelation dst,
 | 
				
			||||||
				   ForkNumber forkNum, char relpersistence)
 | 
									   ForkNumber forkNum, char relpersistence)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char	   *buf;
 | 
						PGAlignedBlock buf;
 | 
				
			||||||
	Page		page;
 | 
						Page		page;
 | 
				
			||||||
	bool		use_wal;
 | 
						bool		use_wal;
 | 
				
			||||||
	bool		copying_initfork;
 | 
						bool		copying_initfork;
 | 
				
			||||||
	BlockNumber nblocks;
 | 
						BlockNumber nblocks;
 | 
				
			||||||
	BlockNumber blkno;
 | 
						BlockNumber blkno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						page = (Page) buf.data;
 | 
				
			||||||
	 * palloc the buffer so that it's MAXALIGN'd.  If it were just a local
 | 
					 | 
				
			||||||
	 * char[] array, the compiler might align it on any byte boundary, which
 | 
					 | 
				
			||||||
	 * can seriously hurt transfer speed to and from the kernel; not to
 | 
					 | 
				
			||||||
	 * mention possibly making log_newpage's accesses to the page header fail.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	buf = (char *) palloc(BLCKSZ);
 | 
					 | 
				
			||||||
	page = (Page) buf;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * The init fork for an unlogged relation in many respects has to be
 | 
						 * The init fork for an unlogged relation in many respects has to be
 | 
				
			||||||
@@ -10858,7 +10851,7 @@ copy_relation_data(SMgrRelation src, SMgrRelation dst,
 | 
				
			|||||||
		/* If we got a cancel signal during the copy of the data, quit */
 | 
							/* If we got a cancel signal during the copy of the data, quit */
 | 
				
			||||||
		CHECK_FOR_INTERRUPTS();
 | 
							CHECK_FOR_INTERRUPTS();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		smgrread(src, forkNum, blkno, buf);
 | 
							smgrread(src, forkNum, blkno, buf.data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!PageIsVerified(page, blkno))
 | 
							if (!PageIsVerified(page, blkno))
 | 
				
			||||||
			ereport(ERROR,
 | 
								ereport(ERROR,
 | 
				
			||||||
@@ -10884,11 +10877,9 @@ copy_relation_data(SMgrRelation src, SMgrRelation dst,
 | 
				
			|||||||
		 * rel, because there's no need for smgr to schedule an fsync for this
 | 
							 * rel, because there's no need for smgr to schedule an fsync for this
 | 
				
			||||||
		 * write; we'll do it ourselves below.
 | 
							 * write; we'll do it ourselves below.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		smgrextend(dst, forkNum, blkno, buf, true);
 | 
							smgrextend(dst, forkNum, blkno, buf.data, true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pfree(buf);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * If the rel is WAL-logged, must fsync before commit.  We use heap_sync
 | 
						 * If the rel is WAL-logged, must fsync before commit.  We use heap_sync
 | 
				
			||||||
	 * to ensure that the toast table gets fsync'd too.  (For a temp or
 | 
						 * to ensure that the toast table gets fsync'd too.  (For a temp or
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -498,18 +498,18 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
 | 
				
			|||||||
	bytesleft = histfilelen;
 | 
						bytesleft = histfilelen;
 | 
				
			||||||
	while (bytesleft > 0)
 | 
						while (bytesleft > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char		rbuf[BLCKSZ];
 | 
							PGAlignedBlock rbuf;
 | 
				
			||||||
		int			nread;
 | 
							int			nread;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ);
 | 
							pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ);
 | 
				
			||||||
		nread = read(fd, rbuf, sizeof(rbuf));
 | 
							nread = read(fd, rbuf.data, sizeof(rbuf));
 | 
				
			||||||
		pgstat_report_wait_end();
 | 
							pgstat_report_wait_end();
 | 
				
			||||||
		if (nread <= 0)
 | 
							if (nread <= 0)
 | 
				
			||||||
			ereport(ERROR,
 | 
								ereport(ERROR,
 | 
				
			||||||
					(errcode_for_file_access(),
 | 
										(errcode_for_file_access(),
 | 
				
			||||||
					 errmsg("could not read file \"%s\": %m",
 | 
										 errmsg("could not read file \"%s\": %m",
 | 
				
			||||||
							path)));
 | 
												path)));
 | 
				
			||||||
		pq_sendbytes(&buf, rbuf, nread);
 | 
							pq_sendbytes(&buf, rbuf.data, nread);
 | 
				
			||||||
		bytesleft -= nread;
 | 
							bytesleft -= nread;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	CloseTransientFile(fd);
 | 
						CloseTransientFile(fd);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,7 +87,7 @@ struct BufFile
 | 
				
			|||||||
	off_t		curOffset;		/* offset part of current pos */
 | 
						off_t		curOffset;		/* offset part of current pos */
 | 
				
			||||||
	int			pos;			/* next read/write position in buffer */
 | 
						int			pos;			/* next read/write position in buffer */
 | 
				
			||||||
	int			nbytes;			/* total # of valid bytes in buffer */
 | 
						int			nbytes;			/* total # of valid bytes in buffer */
 | 
				
			||||||
	char		buffer[BLCKSZ];
 | 
						PGAlignedBlock buffer;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static BufFile *makeBufFile(File firstfile);
 | 
					static BufFile *makeBufFile(File firstfile);
 | 
				
			||||||
@@ -256,7 +256,7 @@ BufFileLoadBuffer(BufFile *file)
 | 
				
			|||||||
	 * Read whatever we can get, up to a full bufferload.
 | 
						 * Read whatever we can get, up to a full bufferload.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	file->nbytes = FileRead(thisfile,
 | 
						file->nbytes = FileRead(thisfile,
 | 
				
			||||||
							file->buffer,
 | 
												file->buffer.data,
 | 
				
			||||||
							sizeof(file->buffer),
 | 
												sizeof(file->buffer),
 | 
				
			||||||
							WAIT_EVENT_BUFFILE_READ);
 | 
												WAIT_EVENT_BUFFILE_READ);
 | 
				
			||||||
	if (file->nbytes < 0)
 | 
						if (file->nbytes < 0)
 | 
				
			||||||
@@ -322,7 +322,7 @@ BufFileDumpBuffer(BufFile *file)
 | 
				
			|||||||
			file->offsets[file->curFile] = file->curOffset;
 | 
								file->offsets[file->curFile] = file->curOffset;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		bytestowrite = FileWrite(thisfile,
 | 
							bytestowrite = FileWrite(thisfile,
 | 
				
			||||||
								 file->buffer + wpos,
 | 
													 file->buffer.data + wpos,
 | 
				
			||||||
								 bytestowrite,
 | 
													 bytestowrite,
 | 
				
			||||||
								 WAIT_EVENT_BUFFILE_WRITE);
 | 
													 WAIT_EVENT_BUFFILE_WRITE);
 | 
				
			||||||
		if (bytestowrite <= 0)
 | 
							if (bytestowrite <= 0)
 | 
				
			||||||
@@ -392,7 +392,7 @@ BufFileRead(BufFile *file, void *ptr, size_t size)
 | 
				
			|||||||
			nthistime = size;
 | 
								nthistime = size;
 | 
				
			||||||
		Assert(nthistime > 0);
 | 
							Assert(nthistime > 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		memcpy(ptr, file->buffer + file->pos, nthistime);
 | 
							memcpy(ptr, file->buffer.data + file->pos, nthistime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		file->pos += nthistime;
 | 
							file->pos += nthistime;
 | 
				
			||||||
		ptr = (void *) ((char *) ptr + nthistime);
 | 
							ptr = (void *) ((char *) ptr + nthistime);
 | 
				
			||||||
@@ -439,7 +439,7 @@ BufFileWrite(BufFile *file, void *ptr, size_t size)
 | 
				
			|||||||
			nthistime = size;
 | 
								nthistime = size;
 | 
				
			||||||
		Assert(nthistime > 0);
 | 
							Assert(nthistime > 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		memcpy(file->buffer + file->pos, ptr, nthistime);
 | 
							memcpy(file->buffer.data + file->pos, ptr, nthistime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		file->dirty = true;
 | 
							file->dirty = true;
 | 
				
			||||||
		file->pos += nthistime;
 | 
							file->pos += nthistime;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -628,10 +628,9 @@ static void
 | 
				
			|||||||
fsm_extend(Relation rel, BlockNumber fsm_nblocks)
 | 
					fsm_extend(Relation rel, BlockNumber fsm_nblocks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	BlockNumber fsm_nblocks_now;
 | 
						BlockNumber fsm_nblocks_now;
 | 
				
			||||||
	Page		pg;
 | 
						PGAlignedBlock pg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pg = (Page) palloc(BLCKSZ);
 | 
						PageInit((Page) pg.data, BLCKSZ, 0);
 | 
				
			||||||
	PageInit(pg, BLCKSZ, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * We use the relation extension lock to lock out other backends trying to
 | 
						 * We use the relation extension lock to lock out other backends trying to
 | 
				
			||||||
@@ -661,10 +660,10 @@ fsm_extend(Relation rel, BlockNumber fsm_nblocks)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	while (fsm_nblocks_now < fsm_nblocks)
 | 
						while (fsm_nblocks_now < fsm_nblocks)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		PageSetChecksumInplace(pg, fsm_nblocks_now);
 | 
							PageSetChecksumInplace((Page) pg.data, fsm_nblocks_now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		smgrextend(rel->rd_smgr, FSM_FORKNUM, fsm_nblocks_now,
 | 
							smgrextend(rel->rd_smgr, FSM_FORKNUM, fsm_nblocks_now,
 | 
				
			||||||
				   (char *) pg, false);
 | 
									   pg.data, false);
 | 
				
			||||||
		fsm_nblocks_now++;
 | 
							fsm_nblocks_now++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -672,8 +671,6 @@ fsm_extend(Relation rel, BlockNumber fsm_nblocks)
 | 
				
			|||||||
	rel->rd_smgr->smgr_fsm_nblocks = fsm_nblocks_now;
 | 
						rel->rd_smgr->smgr_fsm_nblocks = fsm_nblocks_now;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UnlockRelationForExtension(rel, ExclusiveLock);
 | 
						UnlockRelationForExtension(rel, ExclusiveLock);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	pfree(pg);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -215,11 +215,11 @@ ltsWriteBlock(LogicalTapeSet *lts, long blocknum, void *buffer)
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	while (blocknum > lts->nBlocksWritten)
 | 
						while (blocknum > lts->nBlocksWritten)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char		zerobuf[BLCKSZ];
 | 
							PGAlignedBlock zerobuf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		MemSet(zerobuf, 0, sizeof(zerobuf));
 | 
							MemSet(zerobuf.data, 0, sizeof(zerobuf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ltsWriteBlock(lts, lts->nBlocksWritten, zerobuf);
 | 
							ltsWriteBlock(lts, lts->nBlocksWritten, zerobuf.data);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Write the requested block */
 | 
						/* Write the requested block */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,18 +115,17 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
 | 
				
			|||||||
	/* Do pre-padding on non-compressed files */
 | 
						/* Do pre-padding on non-compressed files */
 | 
				
			||||||
	if (pad_to_size && dir_data->compression == 0)
 | 
						if (pad_to_size && dir_data->compression == 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char	   *zerobuf;
 | 
							PGAlignedXLogBlock zerobuf;
 | 
				
			||||||
		int			bytes;
 | 
							int			bytes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		zerobuf = pg_malloc0(XLOG_BLCKSZ);
 | 
							memset(zerobuf.data, 0, XLOG_BLCKSZ);
 | 
				
			||||||
		for (bytes = 0; bytes < pad_to_size; bytes += XLOG_BLCKSZ)
 | 
							for (bytes = 0; bytes < pad_to_size; bytes += XLOG_BLCKSZ)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			errno = 0;
 | 
								errno = 0;
 | 
				
			||||||
			if (write(fd, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
								if (write(fd, zerobuf.data, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				int			save_errno = errno;
 | 
									int			save_errno = errno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				pg_free(zerobuf);
 | 
					 | 
				
			||||||
				close(fd);
 | 
									close(fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				/*
 | 
									/*
 | 
				
			||||||
@@ -136,7 +135,6 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
 | 
				
			|||||||
				return NULL;
 | 
									return NULL;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		pg_free(zerobuf);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (lseek(fd, 0, SEEK_SET) != 0)
 | 
							if (lseek(fd, 0, SEEK_SET) != 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -512,24 +510,20 @@ tar_write(Walfile f, const void *buf, size_t count)
 | 
				
			|||||||
static bool
 | 
					static bool
 | 
				
			||||||
tar_write_padding_data(TarMethodFile *f, size_t bytes)
 | 
					tar_write_padding_data(TarMethodFile *f, size_t bytes)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char	   *zerobuf = pg_malloc0(XLOG_BLCKSZ);
 | 
						PGAlignedXLogBlock zerobuf;
 | 
				
			||||||
	size_t		bytesleft = bytes;
 | 
						size_t		bytesleft = bytes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(zerobuf.data, 0, XLOG_BLCKSZ);
 | 
				
			||||||
	while (bytesleft)
 | 
						while (bytesleft)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		size_t		bytestowrite = bytesleft > XLOG_BLCKSZ ? XLOG_BLCKSZ : bytesleft;
 | 
							size_t		bytestowrite = Min(bytesleft, XLOG_BLCKSZ);
 | 
				
			||||||
 | 
							ssize_t		r = tar_write(f, zerobuf.data, bytestowrite);
 | 
				
			||||||
		ssize_t		r = tar_write(f, zerobuf, bytestowrite);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (r < 0)
 | 
							if (r < 0)
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			pg_free(zerobuf);
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		bytesleft -= r;
 | 
							bytesleft -= r;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pg_free(zerobuf);
 | 
					 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1129,7 +1129,7 @@ KillExistingArchiveStatus(void)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
WriteEmptyXLOG(void)
 | 
					WriteEmptyXLOG(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char	   *buffer;
 | 
						PGAlignedXLogBlock buffer;
 | 
				
			||||||
	XLogPageHeader page;
 | 
						XLogPageHeader page;
 | 
				
			||||||
	XLogLongPageHeader longpage;
 | 
						XLogLongPageHeader longpage;
 | 
				
			||||||
	XLogRecord *record;
 | 
						XLogRecord *record;
 | 
				
			||||||
@@ -1139,12 +1139,10 @@ WriteEmptyXLOG(void)
 | 
				
			|||||||
	int			nbytes;
 | 
						int			nbytes;
 | 
				
			||||||
	char	   *recptr;
 | 
						char	   *recptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Use malloc() to ensure buffer is MAXALIGNED */
 | 
						memset(buffer.data, 0, XLOG_BLCKSZ);
 | 
				
			||||||
	buffer = (char *) pg_malloc(XLOG_BLCKSZ);
 | 
					 | 
				
			||||||
	page = (XLogPageHeader) buffer;
 | 
					 | 
				
			||||||
	memset(buffer, 0, XLOG_BLCKSZ);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set up the XLOG page header */
 | 
						/* Set up the XLOG page header */
 | 
				
			||||||
 | 
						page = (XLogPageHeader) buffer.data;
 | 
				
			||||||
	page->xlp_magic = XLOG_PAGE_MAGIC;
 | 
						page->xlp_magic = XLOG_PAGE_MAGIC;
 | 
				
			||||||
	page->xlp_info = XLP_LONG_HEADER;
 | 
						page->xlp_info = XLP_LONG_HEADER;
 | 
				
			||||||
	page->xlp_tli = ControlFile.checkPointCopy.ThisTimeLineID;
 | 
						page->xlp_tli = ControlFile.checkPointCopy.ThisTimeLineID;
 | 
				
			||||||
@@ -1190,7 +1188,7 @@ WriteEmptyXLOG(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	errno = 0;
 | 
						errno = 0;
 | 
				
			||||||
	if (write(fd, buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
						if (write(fd, buffer.data, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* if write didn't set errno, assume problem is no disk space */
 | 
							/* if write didn't set errno, assume problem is no disk space */
 | 
				
			||||||
		if (errno == 0)
 | 
							if (errno == 0)
 | 
				
			||||||
@@ -1201,11 +1199,11 @@ WriteEmptyXLOG(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Fill the rest of the file with zeroes */
 | 
						/* Fill the rest of the file with zeroes */
 | 
				
			||||||
	memset(buffer, 0, XLOG_BLCKSZ);
 | 
						memset(buffer.data, 0, XLOG_BLCKSZ);
 | 
				
			||||||
	for (nbytes = XLOG_BLCKSZ; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
 | 
						for (nbytes = XLOG_BLCKSZ; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		errno = 0;
 | 
							errno = 0;
 | 
				
			||||||
		if (write(fd, buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
							if (write(fd, buffer.data, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (errno == 0)
 | 
								if (errno == 0)
 | 
				
			||||||
				errno = ENOSPC;
 | 
									errno = ENOSPC;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -158,7 +158,7 @@ recurse_dir(const char *datadir, const char *parentpath,
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
rewind_copy_file_range(const char *path, off_t begin, off_t end, bool trunc)
 | 
					rewind_copy_file_range(const char *path, off_t begin, off_t end, bool trunc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char		buf[BLCKSZ];
 | 
						PGAlignedBlock buf;
 | 
				
			||||||
	char		srcpath[MAXPGPATH];
 | 
						char		srcpath[MAXPGPATH];
 | 
				
			||||||
	int			srcfd;
 | 
						int			srcfd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -184,7 +184,7 @@ rewind_copy_file_range(const char *path, off_t begin, off_t end, bool trunc)
 | 
				
			|||||||
		else
 | 
							else
 | 
				
			||||||
			len = end - begin;
 | 
								len = end - begin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		readlen = read(srcfd, buf, len);
 | 
							readlen = read(srcfd, buf.data, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (readlen < 0)
 | 
							if (readlen < 0)
 | 
				
			||||||
			pg_fatal("could not read file \"%s\": %s\n",
 | 
								pg_fatal("could not read file \"%s\": %s\n",
 | 
				
			||||||
@@ -192,7 +192,7 @@ rewind_copy_file_range(const char *path, off_t begin, off_t end, bool trunc)
 | 
				
			|||||||
		else if (readlen == 0)
 | 
							else if (readlen == 0)
 | 
				
			||||||
			pg_fatal("unexpected EOF while reading file \"%s\"\n", srcpath);
 | 
								pg_fatal("unexpected EOF while reading file \"%s\"\n", srcpath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		write_target_range(buf, begin, readlen);
 | 
							write_target_range(buf.data, begin, readlen);
 | 
				
			||||||
		begin += readlen;
 | 
							begin += readlen;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -131,8 +131,8 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	int			src_fd;
 | 
						int			src_fd;
 | 
				
			||||||
	int			dst_fd;
 | 
						int			dst_fd;
 | 
				
			||||||
	char	   *buffer;
 | 
						PGAlignedBlock buffer;
 | 
				
			||||||
	char	   *new_vmbuf;
 | 
						PGAlignedBlock new_vmbuf;
 | 
				
			||||||
	ssize_t		totalBytesRead = 0;
 | 
						ssize_t		totalBytesRead = 0;
 | 
				
			||||||
	ssize_t		src_filesize;
 | 
						ssize_t		src_filesize;
 | 
				
			||||||
	int			rewriteVmBytesPerPage;
 | 
						int			rewriteVmBytesPerPage;
 | 
				
			||||||
@@ -158,13 +158,6 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
	/* Save old file size */
 | 
						/* Save old file size */
 | 
				
			||||||
	src_filesize = statbuf.st_size;
 | 
						src_filesize = statbuf.st_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * Malloc the work buffers, rather than making them local arrays, to
 | 
					 | 
				
			||||||
	 * ensure adequate alignment.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	buffer = (char *) pg_malloc(BLCKSZ);
 | 
					 | 
				
			||||||
	new_vmbuf = (char *) pg_malloc(BLCKSZ);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Turn each visibility map page into 2 pages one by one. Each new page
 | 
						 * Turn each visibility map page into 2 pages one by one. Each new page
 | 
				
			||||||
	 * has the same page header as the old one.  If the last section of the
 | 
						 * has the same page header as the old one.  If the last section of the
 | 
				
			||||||
@@ -180,7 +173,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
		PageHeaderData pageheader;
 | 
							PageHeaderData pageheader;
 | 
				
			||||||
		bool		old_lastblk;
 | 
							bool		old_lastblk;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((bytesRead = read(src_fd, buffer, BLCKSZ)) != BLCKSZ)
 | 
							if ((bytesRead = read(src_fd, buffer.data, BLCKSZ)) != BLCKSZ)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (bytesRead < 0)
 | 
								if (bytesRead < 0)
 | 
				
			||||||
				pg_fatal("error while copying relation \"%s.%s\": could not read file \"%s\": %s\n",
 | 
									pg_fatal("error while copying relation \"%s.%s\": could not read file \"%s\": %s\n",
 | 
				
			||||||
@@ -194,7 +187,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
		old_lastblk = (totalBytesRead == src_filesize);
 | 
							old_lastblk = (totalBytesRead == src_filesize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Save the page header data */
 | 
							/* Save the page header data */
 | 
				
			||||||
		memcpy(&pageheader, buffer, SizeOfPageHeaderData);
 | 
							memcpy(&pageheader, buffer.data, SizeOfPageHeaderData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * These old_* variables point to old visibility map page. old_cur
 | 
							 * These old_* variables point to old visibility map page. old_cur
 | 
				
			||||||
@@ -202,8 +195,8 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
		 * old block.  old_break is the end+1 position on the old page for the
 | 
							 * old block.  old_break is the end+1 position on the old page for the
 | 
				
			||||||
		 * data that will be transferred to the current new page.
 | 
							 * data that will be transferred to the current new page.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		old_cur = buffer + SizeOfPageHeaderData;
 | 
							old_cur = buffer.data + SizeOfPageHeaderData;
 | 
				
			||||||
		old_blkend = buffer + bytesRead;
 | 
							old_blkend = buffer.data + bytesRead;
 | 
				
			||||||
		old_break = old_cur + rewriteVmBytesPerPage;
 | 
							old_break = old_cur + rewriteVmBytesPerPage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		while (old_break <= old_blkend)
 | 
							while (old_break <= old_blkend)
 | 
				
			||||||
@@ -213,12 +206,12 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
			bool		old_lastpart;
 | 
								bool		old_lastpart;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* First, copy old page header to new page */
 | 
								/* First, copy old page header to new page */
 | 
				
			||||||
			memcpy(new_vmbuf, &pageheader, SizeOfPageHeaderData);
 | 
								memcpy(new_vmbuf.data, &pageheader, SizeOfPageHeaderData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Rewriting the last part of the last old page? */
 | 
								/* Rewriting the last part of the last old page? */
 | 
				
			||||||
			old_lastpart = old_lastblk && (old_break == old_blkend);
 | 
								old_lastpart = old_lastblk && (old_break == old_blkend);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			new_cur = new_vmbuf + SizeOfPageHeaderData;
 | 
								new_cur = new_vmbuf.data + SizeOfPageHeaderData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Process old page bytes one by one, and turn it into new page. */
 | 
								/* Process old page bytes one by one, and turn it into new page. */
 | 
				
			||||||
			while (old_cur < old_break)
 | 
								while (old_cur < old_break)
 | 
				
			||||||
@@ -252,11 +245,11 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			/* Set new checksum for visibility map page, if enabled */
 | 
								/* Set new checksum for visibility map page, if enabled */
 | 
				
			||||||
			if (new_cluster.controldata.data_checksum_version != 0)
 | 
								if (new_cluster.controldata.data_checksum_version != 0)
 | 
				
			||||||
				((PageHeader) new_vmbuf)->pd_checksum =
 | 
									((PageHeader) new_vmbuf.data)->pd_checksum =
 | 
				
			||||||
					pg_checksum_page(new_vmbuf, new_blkno);
 | 
										pg_checksum_page(new_vmbuf.data, new_blkno);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			errno = 0;
 | 
								errno = 0;
 | 
				
			||||||
			if (write(dst_fd, new_vmbuf, BLCKSZ) != BLCKSZ)
 | 
								if (write(dst_fd, new_vmbuf.data, BLCKSZ) != BLCKSZ)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				/* if write didn't set errno, assume problem is no disk space */
 | 
									/* if write didn't set errno, assume problem is no disk space */
 | 
				
			||||||
				if (errno == 0)
 | 
									if (errno == 0)
 | 
				
			||||||
@@ -272,8 +265,6 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Clean up */
 | 
						/* Clean up */
 | 
				
			||||||
	pg_free(buffer);
 | 
					 | 
				
			||||||
	pg_free(new_vmbuf);
 | 
					 | 
				
			||||||
	close(dst_fd);
 | 
						close(dst_fd);
 | 
				
			||||||
	close(src_fd);
 | 
						close(src_fd);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -969,6 +969,32 @@ typedef NameData *Name;
 | 
				
			|||||||
 * ----------------------------------------------------------------
 | 
					 * ----------------------------------------------------------------
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Use this, not "char buf[BLCKSZ]", to declare a field or local variable
 | 
				
			||||||
 | 
					 * holding a page buffer, if that page might be accessed as a page and not
 | 
				
			||||||
 | 
					 * just a string of bytes.  Otherwise the variable might be under-aligned,
 | 
				
			||||||
 | 
					 * causing problems on alignment-picky hardware.  (In some places, we use
 | 
				
			||||||
 | 
					 * this to declare buffers even though we only pass them to read() and
 | 
				
			||||||
 | 
					 * write(), because copying to/from aligned buffers is usually faster than
 | 
				
			||||||
 | 
					 * using unaligned buffers.)  We include both "double" and "int64" in the
 | 
				
			||||||
 | 
					 * union to ensure that the compiler knows the value must be MAXALIGN'ed
 | 
				
			||||||
 | 
					 * (cf. configure's computation of MAXIMUM_ALIGNOF).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					typedef union PGAlignedBlock
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char		data[BLCKSZ];
 | 
				
			||||||
 | 
						double		force_align_d;
 | 
				
			||||||
 | 
						int64		force_align_i64;
 | 
				
			||||||
 | 
					} PGAlignedBlock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Same, but for an XLOG_BLCKSZ-sized buffer */
 | 
				
			||||||
 | 
					typedef union PGAlignedXLogBlock
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char		data[XLOG_BLCKSZ];
 | 
				
			||||||
 | 
						double		force_align_d;
 | 
				
			||||||
 | 
						int64		force_align_i64;
 | 
				
			||||||
 | 
					} PGAlignedXLogBlock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* msb for char */
 | 
					/* msb for char */
 | 
				
			||||||
#define HIGHBIT					(0x80)
 | 
					#define HIGHBIT					(0x80)
 | 
				
			||||||
#define IS_HIGHBIT_SET(ch)		((unsigned char)(ch) & HIGHBIT)
 | 
					#define IS_HIGHBIT_SET(ch)		((unsigned char)(ch) & HIGHBIT)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user