Skip to content

Commit 8734300

Browse files
authored
To support PostgreSQL v16 (#155)
* added nbtsort-16.c
1 parent 90da084 commit 8734300

File tree

17 files changed

+2299
-66
lines changed

17 files changed

+2299
-66
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
PGVERSION: # TODO: build with master branch
20+
- "16"
2021
- "15"
2122
- "14"
2223
- "13"

.github/workflows/test.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ jobs:
1717
strategy:
1818
matrix:
1919
PGVERSION: # TODO: build with master branch
20-
- "15.1"
21-
- "14.6"
22-
- "13.9"
23-
- "12.13"
24-
- "11.18"
20+
- "16.1"
21+
- "15.5"
22+
- "14.10"
23+
- "13.13"
24+
- "12.17"
25+
- "11.22"
2526
- "10.23"
2627
- "9.6.24"
2728
env:

bin/Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ sql/init-14.sql:
6666
cp sql/init-extension-v2.sql sql/init-14.sql
6767
sql/init-15.sql:
6868
cp sql/init-extension-v3.sql sql/init-15.sql
69+
sql/init-16.sql:
70+
cp sql/init-extension-v3.sql sql/init-16.sql
6971

7072
sql/load_bin.sql: sql/load_bin-$(MAJORVERSION).sql
7173
cp sql/load_bin-$(MAJORVERSION).sql sql/load_bin.sql
@@ -89,6 +91,8 @@ sql/load_bin-14.sql:
8991
cp sql/load_bin-v2.sql sql/load_bin-14.sql
9092
sql/load_bin-15.sql:
9193
cp sql/load_bin-v2.sql sql/load_bin-15.sql
94+
sql/load_bin-16.sql:
95+
cp sql/load_bin-v2.sql sql/load_bin-16.sql
9296

9397
sql/load_csv.sql: sql/load_csv-$(MAJORVERSION).sql
9498
cp sql/load_csv-$(MAJORVERSION).sql sql/load_csv.sql
@@ -112,6 +116,8 @@ sql/load_csv-14.sql:
112116
cp sql/load_csv-v2.sql sql/load_csv-14.sql
113117
sql/load_csv-15.sql:
114118
cp sql/load_csv-v3.sql sql/load_csv-15.sql
119+
sql/load_csv-16.sql:
120+
cp sql/load_csv-v3.sql sql/load_csv-16.sql
115121

116122
sql/load_filter.sql: sql/load_filter-$(MAJORVERSION).sql
117123
cp sql/load_filter-$(MAJORVERSION).sql sql/load_filter.sql
@@ -135,6 +141,8 @@ sql/load_filter-14.sql:
135141
cp sql/load_filter-v3.sql sql/load_filter-14.sql
136142
sql/load_filter-15.sql:
137143
cp sql/load_filter-v3.sql sql/load_filter-15.sql
144+
sql/load_filter-16.sql:
145+
cp sql/load_filter-v3.sql sql/load_filter-16.sql
138146

139147
sql/load_function.sql: sql/load_function-$(MAJORVERSION).sql
140148
cp sql/load_function-$(MAJORVERSION).sql sql/load_function.sql
@@ -158,6 +166,8 @@ sql/load_function-14.sql:
158166
cp sql/load_function-v3.sql sql/load_function-14.sql
159167
sql/load_function-15.sql:
160168
cp sql/load_function-v3.sql sql/load_function-15.sql
169+
sql/load_function-16.sql:
170+
cp sql/load_function-v3.sql sql/load_function-16.sql
161171

162172
sql/write_bin.sql: sql/write_bin-$(MAJORVERSION).sql
163173
cp sql/write_bin-$(MAJORVERSION).sql sql/write_bin.sql
@@ -181,17 +191,19 @@ sql/write_bin-14.sql:
181191
cp sql/write_bin-v2.sql sql/write_bin-14.sql
182192
sql/write_bin-15.sql:
183193
cp sql/write_bin-v2.sql sql/write_bin-15.sql
194+
sql/write_bin-16.sql:
195+
cp sql/write_bin-v2.sql sql/write_bin-16.sql
184196

185197
.PHONY: subclean
186198
clean: subclean
187199

188200
subclean:
189-
rm -f sql/init.sql sql/init-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
190-
rm -f sql/load_bin.sql sql/load_bin-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
191-
rm -f sql/load_csv.sql sql/load_csv-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
192-
rm -f sql/load_filter.sql sql/load_filter-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
193-
rm -f sql/load_function.sql sql/load_function-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
194-
rm -f sql/write_bin.sql sql/write_bin-{9.3,9.4,9.5,9.6,10,11,12,13,14,15}.sql
201+
rm -f sql/init.sql sql/init-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
202+
rm -f sql/load_bin.sql sql/load_bin-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
203+
rm -f sql/load_csv.sql sql/load_csv-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
204+
rm -f sql/load_filter.sql sql/load_filter-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
205+
rm -f sql/load_function.sql sql/load_function-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
206+
rm -f sql/write_bin.sql sql/write_bin-{9.3,9.4,9.5,9.6,10,11,12,13,14,15,16}.sql
195207

196208
installcheck: sql/init.sql sql/load_bin.sql sql/load_csv.sql sql/load_function.sql sql/load_filter.sql sql/write_bin.sql
197209

bin/recovery.c

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ extern char *DataDir;
4747
/* Entry point for the recovery. */
4848
extern int LoaderRecoveryMain(void);
4949

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);
5158

5259
/* Determins if the recovery is necessary, and then overwrites data file pages with the vacant one if needed. */
5360
static void StartLoaderRecovery(void);
@@ -62,7 +69,13 @@ static DBState GetDBClusterState(const char *fname);
6269
static void GetLoadStatusInfo(const char *lsfpath, LoadStatus * ls);
6370

6471
/* 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+
6679
BlockNumber blkbeg,
6780
BlockNumber blkend);
6881

@@ -78,7 +91,7 @@ static void LoaderCreateLockFile(const char *filename,
7891
bool isDDLock, const char *refName);
7992

8093
/* Check that the header fields of a page appear valid. */
81-
bool PageHeaderIsValid(PageHeader page);
94+
bool PageHeaderIsValid(Page page);
8295

8396

8497
/**
@@ -189,7 +202,12 @@ StartLoaderRecovery(void)
189202
/*
190203
* overwrite pages created by the loader by blank pages
191204
*/
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
193211
ls.ls.exist_cnt,
194212
ls.ls.exist_cnt + ls.ls.create_cnt);
195213

@@ -392,7 +410,13 @@ GetLoadStatusInfo(const char *lsfpath, LoadStatus * ls)
392410
* @return void
393411
*/
394412
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)
396420
{
397421
BlockNumber segno; /* data file segment no */
398422
char segpath[MAXPGPATH]; /* data file name to open */
@@ -423,7 +447,13 @@ ClearLoadedPage(RelFileNode rnode, BlockNumber blkbeg, BlockNumber blkend)
423447
* set proper extension.
424448
*/
425449
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);
427457

428458
/*
429459
* TODO: consider to use truncate instead of zero-fill to end of file.
@@ -516,7 +546,13 @@ ClearLoadedPage(RelFileNode rnode, BlockNumber blkbeg, BlockNumber blkend)
516546
segpath, strerror(errno));
517547

518548
++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);
520556

521557
fd = open(segpath, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR);
522558
if (fd == -1)
@@ -557,7 +593,7 @@ IsPageCreatedByLoader(Page page)
557593
{
558594
PageHeader targetBlock = (PageHeader) page;
559595

560-
if (!PageHeaderIsValid(targetBlock))
596+
if (!PageHeaderIsValid(page))
561597
return true;
562598

563599
if (targetBlock->pd_lsn.xlogid == 0 && targetBlock->pd_lsn.xrecoff == 0)
@@ -909,28 +945,34 @@ PageInit(Page page, Size pageSize, Size specialSize)
909945
* treat such a page as empty and without free space. Eventually, VACUUM
910946
* will clean up such a page and make it usable.
911947
*/
948+
912949
bool
913-
PageHeaderIsValid(PageHeader page)
950+
PageHeaderIsValid(Page page)
914951
{
915952
char *pagebytes;
916953
int i;
917-
954+
PageHeader phdr = (PageHeader) page;
918955
/*
919956
* Check normal case
920957
*/
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))
928970
return true;
929971

930972
/*
931973
* Check all-zeroes case
932974
*/
933-
pagebytes = (char *) page;
975+
pagebytes = (char *) phdr;
934976
for (i = 0; i < BLCKSZ; i++)
935977
{
936978
if (pagebytes[i] != 0)
@@ -940,24 +982,49 @@ PageHeaderIsValid(PageHeader page)
940982
}
941983

942984
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)
944992
{
993+
#if PG_VERSION_NUM >= 160000
994+
if (rLocator.spcOid == GLOBALTABLESPACE_OID)
995+
#else
945996
if (rnode.spcNode == GLOBALTABLESPACE_OID)
997+
#endif
946998
{
947999
/* Shared system relations live in {datadir}/global */
1000+
#if PG_VERSION_NUM >= 160000
1001+
snprintf(path, MAXPGPATH, "global/%u", rLocator.relNumber);
1002+
#else
9481003
snprintf(path, MAXPGPATH, "global/%u", rnode.relNode);
1004+
#endif
9491005
}
1006+
#if PG_VERSION_NUM >= 160000
1007+
else if (rLocator.spcOid == DEFAULTTABLESPACE_OID)
1008+
#else
9501009
else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
1010+
#endif
1011+
9511012
{
9521013
/* 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
9551019
}
9561020
else
9571021
{
9581022
/* 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
9611028
}
9621029

9631030
if (segno > 0)

include/pg_loadstatus.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
#define LOADSTATUS_H
1414

1515
#include "storage/block.h"
16+
#if PG_VERSION_NUM >= 160000
17+
#include "storage/relfilelocator.h"
18+
#else
1619
#include "storage/relfilenode.h"
20+
#endif
1721

1822
#ifndef MAXPGPATH
1923
#define MAXPGPATH 1024
@@ -24,11 +28,17 @@
2428
/* typical sector size is 512 byte */
2529
#define BULKLOAD_LSF_BLCKSZ 512
2630

31+
#if PG_VERSION_NUM >= 160000
32+
#define BULKLOAD_LSF_PATH(buffer, ls) \
33+
snprintf((buffer), MAXPGPATH, \
34+
BULKLOAD_LSF_DIR "/%d.%d.loadstatus", \
35+
(ls)->ls.rLocator.dbOid, (ls)->ls.relid)
36+
#else
2737
#define BULKLOAD_LSF_PATH(buffer, ls) \
2838
snprintf((buffer), MAXPGPATH, \
2939
BULKLOAD_LSF_DIR "/%d.%d.loadstatus", \
3040
(ls)->ls.rnode.dbNode, (ls)->ls.relid)
31-
41+
#endif
3242
/**
3343
* @brief Loading status information
3444
*/
@@ -37,7 +47,11 @@ typedef union LoadStatus
3747
struct
3848
{
3949
Oid relid; /**< target relation oid */
50+
#if PG_VERSION_NUM >= 160000
51+
RelFileLocator rLocator;
52+
#else
4053
RelFileNode rnode; /**< target relation node */
54+
#endif
4155
BlockNumber exist_cnt; /**< number of blocks already existing */
4256
BlockNumber create_cnt; /**< number of blocks pg_bulkload creates */
4357
} ls;

0 commit comments

Comments
 (0)