29
29
#include <unistd.h>
30
30
#include <sys/stat.h>
31
31
32
+ #if PG_VERSION_NUM < 120000
33
+ #include "access/htup_details.h"
34
+ #endif
32
35
#include "catalog/pg_tablespace.h"
33
36
#include "catalog/pg_type.h"
34
37
#include "funcapi.h"
35
38
#include "miscadmin.h"
36
39
#include "nodes/pg_list.h"
37
40
#include "storage/copydir.h"
38
41
#include "storage/lmgr.h"
42
+ #if PG_VERSION_NUM >= 120000
39
43
#include "storage/md.h"
44
+ #endif
40
45
#include "storage/reinit.h"
41
46
#include "utils/builtins.h"
42
47
#include "utils/guc.h"
@@ -55,7 +60,9 @@ int ptrack_map_size_tmp;
55
60
static copydir_hook_type prev_copydir_hook = NULL ;
56
61
static mdwrite_hook_type prev_mdwrite_hook = NULL ;
57
62
static mdextend_hook_type prev_mdextend_hook = NULL ;
63
+ #if PG_VERSION_NUM >= 120000
58
64
static ProcessSyncRequests_hook_type prev_ProcessSyncRequests_hook = NULL ;
65
+ #endif
59
66
60
67
void _PG_init (void );
61
68
void _PG_fini (void );
@@ -65,8 +72,9 @@ static void ptrack_mdwrite_hook(RelFileNodeBackend smgr_rnode,
65
72
ForkNumber forkno , BlockNumber blkno );
66
73
static void ptrack_mdextend_hook (RelFileNodeBackend smgr_rnode ,
67
74
ForkNumber forkno , BlockNumber blkno );
75
+ #if PG_VERSION_NUM >= 120000
68
76
static void ptrack_ProcessSyncRequests_hook (void );
69
-
77
+ #endif
70
78
static void ptrack_gather_filelist (List * * filelist , char * path , Oid spcOid , Oid dbOid );
71
79
static int ptrack_filelist_getnext (PtScanCtx * ctx );
72
80
@@ -108,8 +116,10 @@ _PG_init(void)
108
116
mdwrite_hook = ptrack_mdwrite_hook ;
109
117
prev_mdextend_hook = mdextend_hook ;
110
118
mdextend_hook = ptrack_mdextend_hook ;
119
+ #if PG_VERSION_NUM >= 120000
111
120
prev_ProcessSyncRequests_hook = ProcessSyncRequests_hook ;
112
121
ProcessSyncRequests_hook = ptrack_ProcessSyncRequests_hook ;
122
+ #endif
113
123
}
114
124
115
125
/*
@@ -122,7 +132,9 @@ _PG_fini(void)
122
132
copydir_hook = prev_copydir_hook ;
123
133
mdwrite_hook = prev_mdwrite_hook ;
124
134
mdextend_hook = prev_mdextend_hook ;
135
+ #if PG_VERSION_NUM >= 120000
125
136
ProcessSyncRequests_hook = prev_ProcessSyncRequests_hook ;
137
+ #endif
126
138
}
127
139
128
140
/*
@@ -194,6 +206,7 @@ ptrack_mdextend_hook(RelFileNodeBackend smgr_rnode,
194
206
prev_mdextend_hook (smgr_rnode , forknum , blocknum );
195
207
}
196
208
209
+ #if PG_VERSION_NUM >= 120000
197
210
static void
198
211
ptrack_ProcessSyncRequests_hook ()
199
212
{
@@ -202,6 +215,7 @@ ptrack_ProcessSyncRequests_hook()
202
215
if (prev_ProcessSyncRequests_hook )
203
216
prev_ProcessSyncRequests_hook ();
204
217
}
218
+ #endif
205
219
206
220
/*
207
221
* Recursively walk through the path and add all data files to filelist.
@@ -426,7 +440,11 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
426
440
ctx -> filelist = NIL ;
427
441
428
442
/* Make tuple descriptor */
443
+ #if PG_VERSION_NUM >= 120000
429
444
tupdesc = CreateTemplateTupleDesc (2 );
445
+ #else
446
+ tupdesc = CreateTemplateTupleDesc (2 , false);
447
+ #endif
430
448
TupleDescInitEntry (tupdesc , (AttrNumber ) 1 , "path" , TEXTOID , -1 , 0 );
431
449
TupleDescInitEntry (tupdesc , (AttrNumber ) 2 , "pagemap" , BYTEAOID , -1 , 0 );
432
450
funcctx -> tuple_desc = BlessTupleDesc (tupdesc );
@@ -475,6 +493,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
475
493
char pathname [MAXPGPATH ];
476
494
bytea * result = NULL ;
477
495
Size result_sz = pagemap .bitmapsize + VARHDRSZ ;
496
+ HeapTuple htup = NULL ;
478
497
479
498
/* Create a bytea copy of our bitmap */
480
499
result = (bytea * ) palloc (result_sz );
@@ -490,7 +509,9 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
490
509
pagemap .bitmap = NULL ;
491
510
pagemap .bitmapsize = 0 ;
492
511
493
- SRF_RETURN_NEXT (funcctx , HeapTupleGetDatum (heap_form_tuple (funcctx -> tuple_desc , values , nulls )));
512
+ htup = heap_form_tuple (funcctx -> tuple_desc , values , nulls );
513
+ if (htup )
514
+ SRF_RETURN_NEXT (funcctx , HeapTupleGetDatum (htup ));
494
515
}
495
516
else
496
517
{
0 commit comments