@@ -47,7 +47,14 @@ extern char *DataDir;
47
47
/* Entry point for the recovery. */
48
48
extern int LoaderRecoveryMain (void );
49
49
50
- static void GetSegmentPath (char path [MAXPGPATH ], RelFileNode rnode , int segno );
50
+
51
+ static void GetSegmentPath (char path [MAXPGPATH ],
52
+ #if PG_VERSION_NUM >= 160000
53
+ RelFileLocator rLocator ,
54
+ #else
55
+ RelFileNode rnode ,
56
+ #endif
57
+ int segno );
51
58
52
59
/* Determins if the recovery is necessary, and then overwrites data file pages with the vacant one if needed. */
53
60
static void StartLoaderRecovery (void );
@@ -62,7 +69,13 @@ static DBState GetDBClusterState(const char *fname);
62
69
static void GetLoadStatusInfo (const char * lsfpath , LoadStatus * ls );
63
70
64
71
/* Overwrite data pages with a vacant page. */
65
- static void ClearLoadedPage (RelFileNode rnode ,
72
+ static void ClearLoadedPage (
73
+ #if PG_VERSION_NUM >= 160000
74
+ RelFileLocator rLocator ,
75
+ #else
76
+ RelFileNode rnode ,
77
+ #endif
78
+
66
79
BlockNumber blkbeg ,
67
80
BlockNumber blkend );
68
81
@@ -78,7 +91,7 @@ static void LoaderCreateLockFile(const char *filename,
78
91
bool isDDLock , const char * refName );
79
92
80
93
/* Check that the header fields of a page appear valid. */
81
- bool PageHeaderIsValid (PageHeader page );
94
+ bool PageHeaderIsValid (Page page );
82
95
83
96
84
97
/**
@@ -189,7 +202,12 @@ StartLoaderRecovery(void)
189
202
/*
190
203
* overwrite pages created by the loader by blank pages
191
204
*/
192
- ClearLoadedPage (ls .ls .rnode ,
205
+ ClearLoadedPage (
206
+ #if PG_VERSION_NUM >= 160000
207
+ ls .ls .rLocator ,
208
+ #else
209
+ ls .ls .rnode ,
210
+ #endif
193
211
ls .ls .exist_cnt ,
194
212
ls .ls .exist_cnt + ls .ls .create_cnt );
195
213
@@ -392,7 +410,13 @@ GetLoadStatusInfo(const char *lsfpath, LoadStatus * ls)
392
410
* @return void
393
411
*/
394
412
static void
395
- ClearLoadedPage (RelFileNode rnode , BlockNumber blkbeg , BlockNumber blkend )
413
+ ClearLoadedPage (
414
+ #if PG_VERSION_NUM >= 160000
415
+ RelFileLocator rLocator ,
416
+ #else
417
+ RelFileNode rnode ,
418
+ #endif
419
+ BlockNumber blkbeg , BlockNumber blkend )
396
420
{
397
421
BlockNumber segno ; /* data file segment no */
398
422
char segpath [MAXPGPATH ]; /* data file name to open */
@@ -423,7 +447,13 @@ ClearLoadedPage(RelFileNode rnode, BlockNumber blkbeg, BlockNumber blkend)
423
447
* set proper extension.
424
448
*/
425
449
segno = blkbeg / RELSEG_SIZE ;
426
- GetSegmentPath (segpath , rnode , segno );
450
+ GetSegmentPath (segpath ,
451
+ #if PG_VERSION_NUM >= 160000
452
+ rLocator ,
453
+ #else
454
+ rnode ,
455
+ #endif
456
+ segno );
427
457
428
458
/*
429
459
* TODO: consider to use truncate instead of zero-fill to end of file.
@@ -516,7 +546,13 @@ ClearLoadedPage(RelFileNode rnode, BlockNumber blkbeg, BlockNumber blkend)
516
546
segpath , strerror (errno ));
517
547
518
548
++ segno ;
519
- GetSegmentPath (segpath , rnode , segno );
549
+ GetSegmentPath (segpath ,
550
+ #if PG_VERSION_NUM >= 160000
551
+ rLocator ,
552
+ #else
553
+ rnode ,
554
+ #endif
555
+ segno );
520
556
521
557
fd = open (segpath , O_RDWR | PG_BINARY , S_IRUSR | S_IWUSR );
522
558
if (fd == -1 )
@@ -557,7 +593,7 @@ IsPageCreatedByLoader(Page page)
557
593
{
558
594
PageHeader targetBlock = (PageHeader ) page ;
559
595
560
- if (!PageHeaderIsValid (targetBlock ))
596
+ if (!PageHeaderIsValid (page ))
561
597
return true;
562
598
563
599
if (targetBlock -> pd_lsn .xlogid == 0 && targetBlock -> pd_lsn .xrecoff == 0 )
@@ -909,28 +945,34 @@ PageInit(Page page, Size pageSize, Size specialSize)
909
945
* treat such a page as empty and without free space. Eventually, VACUUM
910
946
* will clean up such a page and make it usable.
911
947
*/
948
+
912
949
bool
913
- PageHeaderIsValid (PageHeader page )
950
+ PageHeaderIsValid (Page page )
914
951
{
915
952
char * pagebytes ;
916
953
int i ;
917
-
954
+ PageHeader phdr = ( PageHeader ) page ;
918
955
/*
919
956
* Check normal case
920
957
*/
921
- if (PageGetPageSize (page ) == BLCKSZ &&
922
- PageGetPageLayoutVersion (page ) == PG_PAGE_LAYOUT_VERSION &&
923
- page -> pd_lower >= SizeOfPageHeaderData &&
924
- page -> pd_lower <= page -> pd_upper &&
925
- page -> pd_upper <= page -> pd_special &&
926
- page -> pd_special <= BLCKSZ &&
927
- page -> pd_special == MAXALIGN (page -> pd_special ))
958
+ if (PageGetPageSize (
959
+ #if PG_VERSION_NUM >= 160000
960
+ page ) == BLCKSZ && PageGetPageLayoutVersion (page
961
+ #else
962
+ phdr ) == BLCKSZ && PageGetPageLayoutVersion (phdr
963
+ #endif
964
+ ) == PG_PAGE_LAYOUT_VERSION &&
965
+ phdr -> pd_lower >= SizeOfPageHeaderData &&
966
+ phdr -> pd_lower <= phdr -> pd_upper &&
967
+ phdr -> pd_upper <= phdr -> pd_special &&
968
+ phdr -> pd_special <= BLCKSZ &&
969
+ phdr -> pd_special == MAXALIGN (phdr -> pd_special ))
928
970
return true;
929
971
930
972
/*
931
973
* Check all-zeroes case
932
974
*/
933
- pagebytes = (char * ) page ;
975
+ pagebytes = (char * ) phdr ;
934
976
for (i = 0 ; i < BLCKSZ ; i ++ )
935
977
{
936
978
if (pagebytes [i ] != 0 )
@@ -940,24 +982,49 @@ PageHeaderIsValid(PageHeader page)
940
982
}
941
983
942
984
static void
943
- GetSegmentPath (char path [MAXPGPATH ], RelFileNode rnode , int segno )
985
+ GetSegmentPath (char path [MAXPGPATH ],
986
+ #if PG_VERSION_NUM >= 160000
987
+ RelFileLocator rLocator ,
988
+ #else
989
+ RelFileNode rnode ,
990
+ #endif
991
+ int segno )
944
992
{
993
+ #if PG_VERSION_NUM >= 160000
994
+ if (rLocator .spcOid == GLOBALTABLESPACE_OID )
995
+ #else
945
996
if (rnode .spcNode == GLOBALTABLESPACE_OID )
997
+ #endif
946
998
{
947
999
/* Shared system relations live in {datadir}/global */
1000
+ #if PG_VERSION_NUM >= 160000
1001
+ snprintf (path , MAXPGPATH , "global/%u" , rLocator .relNumber );
1002
+ #else
948
1003
snprintf (path , MAXPGPATH , "global/%u" , rnode .relNode );
1004
+ #endif
949
1005
}
1006
+ #if PG_VERSION_NUM >= 160000
1007
+ else if (rLocator .spcOid == DEFAULTTABLESPACE_OID )
1008
+ #else
950
1009
else if (rnode .spcNode == DEFAULTTABLESPACE_OID )
1010
+ #endif
1011
+
951
1012
{
952
1013
/* The default tablespace is {datadir}/base */
953
- snprintf (path , MAXPGPATH , "base/%u/%u" ,
954
- rnode .dbNode , rnode .relNode );
1014
+ #if PG_VERSION_NUM >= 160000
1015
+ snprintf (path , MAXPGPATH , "base/%u/%u" , rLocator .dbOid , rLocator .relNumber );
1016
+ #else
1017
+ snprintf (path , MAXPGPATH , "base/%u/%u" , rnode .dbNode , rnode .relNode );
1018
+ #endif
955
1019
}
956
1020
else
957
1021
{
958
1022
/* All other tablespaces are accessed via symlinks */
959
- snprintf (path , MAXPGPATH , "pg_tblspc/%u/%u/%u" ,
960
- rnode .spcNode , rnode .dbNode , rnode .relNode );
1023
+ #if PG_VERSION_NUM >= 160000
1024
+ snprintf (path , MAXPGPATH , "pg_tblspc/%u/%u/%u" , rLocator .spcOid , rLocator .dbOid , rLocator .relNumber );
1025
+ #else
1026
+ snprintf (path , MAXPGPATH , "pg_tblspc/%u/%u/%u" , rnode .spcNode , rnode .dbNode , rnode .relNode );
1027
+ #endif
961
1028
}
962
1029
963
1030
if (segno > 0 )
0 commit comments