2525 */
2626
2727#include "postgres.h"
28+
2829#include <unistd.h>
2930
3031#include "access/heapam.h"
@@ -73,9 +74,9 @@ typedef struct AutoPrewarmSharedState
7374 /* Following items are for communication with per-database worker */
7475 dsm_handle block_info_handle ;
7576 Oid database ;
76- int64 prewarm_start_idx ;
77- int64 prewarm_stop_idx ;
78- int64 prewarmed_blocks ;
77+ int prewarm_start_idx ;
78+ int prewarm_stop_idx ;
79+ int prewarmed_blocks ;
7980} AutoPrewarmSharedState ;
8081
8182void _PG_init (void );
@@ -86,7 +87,7 @@ PG_FUNCTION_INFO_V1(autoprewarm_start_worker);
8687PG_FUNCTION_INFO_V1 (autoprewarm_dump_now );
8788
8889static void apw_load_buffers (void );
89- static int64 apw_dump_now (bool is_bgworker , bool dump_unlogged );
90+ static int apw_dump_now (bool is_bgworker , bool dump_unlogged );
9091static void apw_start_master_worker (void );
9192static void apw_start_database_worker (void );
9293static bool apw_init_shmem (void );
@@ -274,7 +275,7 @@ static void
274275apw_load_buffers (void )
275276{
276277 FILE * file = NULL ;
277- int64 num_elements ,
278+ int num_elements ,
278279 i ;
279280 BlockInfoRecord * blkinfo ;
280281 dsm_segment * seg ;
@@ -317,7 +318,7 @@ apw_load_buffers(void)
317318 }
318319
319320 /* First line of the file is a record count. */
320- if (fscanf (file , "<<" INT64_FORMAT " >>\n" , & num_elements ) != 1 )
321+ if (fscanf (file , "<<%d >>\n" , & num_elements ) != 1 )
321322 ereport (ERROR ,
322323 (errcode_for_file_access (),
323324 errmsg ("could not read from file \"%s\": %m" ,
@@ -336,7 +337,7 @@ apw_load_buffers(void)
336337 & blkinfo [i ].tablespace , & blkinfo [i ].filenode ,
337338 & forknum , & blkinfo [i ].blocknum ) != 5 )
338339 ereport (ERROR ,
339- (errmsg ("autoprewarm block dump file is corrupted at line " INT64_FORMAT ,
340+ (errmsg ("autoprewarm block dump file is corrupted at line %d" ,
340341 i + 1 )));
341342 blkinfo [i ].forknum = forknum ;
342343 }
@@ -355,28 +356,28 @@ apw_load_buffers(void)
355356 /* Get the info position of the first block of the next database. */
356357 while (apw_state -> prewarm_start_idx < num_elements )
357358 {
358- uint32 i = apw_state -> prewarm_start_idx ;
359- Oid current_db = blkinfo [i ].database ;
359+ int j = apw_state -> prewarm_start_idx ;
360+ Oid current_db = blkinfo [j ].database ;
360361
361362 /*
362363 * Advance the prewarm_stop_idx to the first BlockRecordInfo that does
363364 * not belong to this database.
364365 */
365- i ++ ;
366- while (i < num_elements )
366+ j ++ ;
367+ while (j < num_elements )
367368 {
368- if (current_db != blkinfo [i ].database )
369+ if (current_db != blkinfo [j ].database )
369370 {
370371 /*
371372 * Combine BlockRecordInfos for global objects with those of
372373 * the database.
373374 */
374375 if (current_db != InvalidOid )
375376 break ;
376- current_db = blkinfo [i ].database ;
377+ current_db = blkinfo [j ].database ;
377378 }
378379
379- i ++ ;
380+ j ++ ;
380381 }
381382
382383 /*
@@ -388,7 +389,7 @@ apw_load_buffers(void)
388389 break ;
389390
390391 /* Configure stop point and database for next per-database worker. */
391- apw_state -> prewarm_stop_idx = i ;
392+ apw_state -> prewarm_stop_idx = j ;
392393 apw_state -> database = current_db ;
393394 Assert (apw_state -> prewarm_start_idx < apw_state -> prewarm_stop_idx );
394395
@@ -415,8 +416,7 @@ apw_load_buffers(void)
415416
416417 /* Report our success. */
417418 ereport (LOG ,
418- (errmsg ("autoprewarm successfully prewarmed " INT64_FORMAT
419- " of " INT64_FORMAT " previously-loaded blocks" ,
419+ (errmsg ("autoprewarm successfully prewarmed %d of %d previously-loaded blocks" ,
420420 apw_state -> prewarmed_blocks , num_elements )));
421421}
422422
@@ -427,7 +427,7 @@ apw_load_buffers(void)
427427void
428428autoprewarm_database_main (Datum main_arg )
429429{
430- uint32 pos ;
430+ int pos ;
431431 BlockInfoRecord * block_info ;
432432 Relation rel = NULL ;
433433 BlockNumber nblocks = 0 ;
@@ -557,13 +557,14 @@ autoprewarm_database_main(Datum main_arg)
557557 * Dump information on blocks in shared buffers. We use a text format here
558558 * so that it's easy to understand and even change the file contents if
559559 * necessary.
560+ * Returns the number of blocks dumped.
560561 */
561- static int64
562+ static int
562563apw_dump_now (bool is_bgworker , bool dump_unlogged )
563564{
564- uint32 i ;
565+ int num_blocks ;
566+ int i ;
565567 int ret ;
566- int64 num_blocks ;
567568 BlockInfoRecord * block_info_array ;
568569 BufferDesc * bufHdr ;
569570 FILE * file ;
@@ -630,7 +631,7 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
630631 errmsg ("could not open file \"%s\": %m" ,
631632 transient_dump_file_path )));
632633
633- ret = fprintf (file , "<<" INT64_FORMAT " >>\n" , num_blocks );
634+ ret = fprintf (file , "<<%d >>\n" , num_blocks );
634635 if (ret < 0 )
635636 {
636637 int save_errno = errno ;
@@ -691,8 +692,7 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
691692 apw_state -> pid_using_dumpfile = InvalidPid ;
692693
693694 ereport (DEBUG1 ,
694- (errmsg ("wrote block details for " INT64_FORMAT " blocks" ,
695- num_blocks )));
695+ (errmsg ("wrote block details for %d blocks" , num_blocks )));
696696 return num_blocks ;
697697}
698698
@@ -727,11 +727,14 @@ autoprewarm_start_worker(PG_FUNCTION_ARGS)
727727
728728/*
729729 * SQL-callable function to perform an immediate block dump.
730+ *
731+ * Note: this is declared to return int8, as insurance against some
732+ * very distant day when we might make NBuffers wider than int.
730733 */
731734Datum
732735autoprewarm_dump_now (PG_FUNCTION_ARGS )
733736{
734- int64 num_blocks ;
737+ int num_blocks ;
735738
736739 apw_init_shmem ();
737740
@@ -741,7 +744,7 @@ autoprewarm_dump_now(PG_FUNCTION_ARGS)
741744 }
742745 PG_END_ENSURE_ERROR_CLEANUP (apw_detach_shmem , 0 );
743746
744- PG_RETURN_INT64 (num_blocks );
747+ PG_RETURN_INT64 (( int64 ) num_blocks );
745748}
746749
747750/*
@@ -869,7 +872,7 @@ do { \
869872 return -1; \
870873 else if (a->fld > b->fld) \
871874 return 1; \
872- } while(0);
875+ } while(0)
873876
874877/*
875878 * apw_compare_blockinfo
@@ -883,8 +886,8 @@ do { \
883886static int
884887apw_compare_blockinfo (const void * p , const void * q )
885888{
886- BlockInfoRecord * a = (BlockInfoRecord * ) p ;
887- BlockInfoRecord * b = (BlockInfoRecord * ) q ;
889+ const BlockInfoRecord * a = (const BlockInfoRecord * ) p ;
890+ const BlockInfoRecord * b = (const BlockInfoRecord * ) q ;
888891
889892 cmp_member_elem (database );
890893 cmp_member_elem (tablespace );
0 commit comments