Skip to content

Commit bcbe992

Browse files
committed
Adjust a few pg_upgrade functions to return void.
Adjust pg_upgrade page conversion functions (which are not used) to return void so transfer_all_new_dbs can return void.
1 parent 84f6fb8 commit bcbe992

File tree

3 files changed

+25
-40
lines changed

3 files changed

+25
-40
lines changed

contrib/pg_upgrade/page.c

+20-34
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifdef PAGE_CONVERSION
1818

1919

20-
static const char *getPageVersion(
20+
static void getPageVersion(
2121
uint16 *version, const char *pathName);
2222
static pageCnvCtx *loadConverterPlugin(
2323
uint16 newPageVersion, uint16 oldPageVersion);
@@ -33,13 +33,9 @@ static pageCnvCtx *loadConverterPlugin(
3333
* to the new format. If the versions are identical, this function just
3434
* returns a NULL pageCnvCtx pointer to indicate that page-by-page conversion
3535
* is not required.
36-
*
37-
* If successful this function sets *result and returns NULL. If an error
38-
* occurs, this function returns an error message in the form of an null-terminated
39-
* string.
4036
*/
41-
const char *
42-
setupPageConverter(pageCnvCtx **result)
37+
pageCnvCtx *
38+
setupPageConverter(void)
4339
{
4440
uint16 oldPageVersion;
4541
uint16 newPageVersion;
@@ -53,35 +49,28 @@ setupPageConverter(pageCnvCtx **result)
5349
snprintf(srcName, sizeof(srcName), "%s/global/%u", old_cluster.pgdata,
5450
old_cluster.pg_database_oid);
5551

56-
if ((msg = getPageVersion(&oldPageVersion, srcName)) != NULL)
57-
return msg;
58-
59-
if ((msg = getPageVersion(&newPageVersion, dstName)) != NULL)
60-
return msg;
52+
getPageVersion(&oldPageVersion, srcName);
53+
getPageVersion(&newPageVersion, dstName);
6154

6255
/*
6356
* If the old cluster and new cluster use the same page layouts, then we
6457
* don't need a page converter.
6558
*/
66-
if (newPageVersion == oldPageVersion)
59+
if (newPageVersion != oldPageVersion)
6760
{
68-
*result = NULL;
69-
return NULL;
70-
}
71-
72-
/*
73-
* The clusters use differing page layouts, see if we can find a plugin
74-
* that knows how to convert from the old page layout to the new page
75-
* layout.
76-
*/
61+
/*
62+
* The clusters use differing page layouts, see if we can find a plugin
63+
* that knows how to convert from the old page layout to the new page
64+
* layout.
65+
*/
66+
67+
if ((converter = loadConverterPlugin(newPageVersion, oldPageVersion)) == NULL)
68+
pg_log(PG_FATAL, "could not find plugin to convert from old page layout to new page layout\n");
7769

78-
if ((converter = loadConverterPlugin(newPageVersion, oldPageVersion)) == NULL)
79-
return "could not find plugin to convert from old page layout to new page layout";
70+
return converter;
71+
}
8072
else
81-
{
82-
*result = converter;
8373
return NULL;
84-
}
8574
}
8675

8776

@@ -94,27 +83,24 @@ setupPageConverter(pageCnvCtx **result)
9483
* if an error occurs, this function returns an error message (in the form
9584
* of a null-terminated string).
9685
*/
97-
static const char *
86+
static void
9887
getPageVersion(uint16 *version, const char *pathName)
9988
{
10089
int relfd;
10190
PageHeaderData page;
10291
ssize_t bytesRead;
10392

10493
if ((relfd = open(pathName, O_RDONLY, 0)) < 0)
105-
return "could not open relation";
94+
pg_log(PG_FATAL, "could not open relation %s\n", pathName);
10695

10796
if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page))
108-
{
109-
close(relfd);
110-
return "could not read page header";
111-
}
97+
pg_log(PG_FATAL, "could not read page header of %s\n", pathName);
11298

11399
*version = PageGetPageLayoutVersion(&page);
114100

115101
close(relfd);
116102

117-
return NULL;
103+
return;
118104
}
119105

120106

contrib/pg_upgrade/pg_upgrade.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ typedef struct
359359
pluginShutdown shutdown; /* Pointer to plugin's shutdown function */
360360
} pageCnvCtx;
361361

362-
const char *setupPageConverter(pageCnvCtx **result);
362+
const pageCnvCtx *setupPageConverter(void);
363363
#else
364364
/* dummy */
365365
typedef void *pageCnvCtx;
@@ -398,7 +398,7 @@ void get_sock_dir(ClusterInfo *cluster, bool live_check);
398398
/* relfilenode.c */
399399

400400
void get_pg_database_relfilenode(ClusterInfo *cluster);
401-
const char *transfer_all_new_dbs(DbInfoArr *olddb_arr,
401+
void transfer_all_new_dbs(DbInfoArr *olddb_arr,
402402
DbInfoArr *newdb_arr, char *old_pgdata, char *new_pgdata);
403403

404404

contrib/pg_upgrade/relfilenode.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ static void transfer_relfile(pageCnvCtx *pageConverter, FileNameMap *map,
2727
* Responsible for upgrading all database. invokes routines to generate mappings and then
2828
* physically link the databases.
2929
*/
30-
const char *
30+
void
3131
transfer_all_new_dbs(DbInfoArr *old_db_arr,
3232
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata)
3333
{
3434
int old_dbnum,
3535
new_dbnum;
36-
const char *msg = NULL;
3736

3837
pg_log(PG_REPORT, "%s user relation files\n",
3938
user_opts.transfer_mode == TRANSFER_MODE_LINK ? "Linking" : "Copying");
@@ -74,7 +73,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
7473
print_maps(mappings, n_maps, new_db->db_name);
7574

7675
#ifdef PAGE_CONVERSION
77-
msg = setupPageConverter(&pageConverter);
76+
pageConverter = setupPageConverter();
7877
#endif
7978
transfer_single_new_db(pageConverter, mappings, n_maps);
8079

@@ -85,7 +84,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
8584
end_progress_output();
8685
check_ok();
8786

88-
return msg;
87+
return;
8988
}
9089

9190

0 commit comments

Comments
 (0)