Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "postgres_fe.h"
00011
00012 #include "pg_upgrade.h"
00013
00014 #include "storage/bufpage.h"
00015
00016
00017 #ifdef PAGE_CONVERSION
00018
00019
00020 static void getPageVersion(
00021 uint16 *version, const char *pathName);
00022 static pageCnvCtx *loadConverterPlugin(
00023 uint16 newPageVersion, uint16 oldPageVersion);
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 pageCnvCtx *
00038 setupPageConverter(void)
00039 {
00040 uint16 oldPageVersion;
00041 uint16 newPageVersion;
00042 pageCnvCtx *converter;
00043 const char *msg;
00044 char dstName[MAXPGPATH];
00045 char srcName[MAXPGPATH];
00046
00047 snprintf(dstName, sizeof(dstName), "%s/global/%u", new_cluster.pgdata,
00048 new_cluster.pg_database_oid);
00049 snprintf(srcName, sizeof(srcName), "%s/global/%u", old_cluster.pgdata,
00050 old_cluster.pg_database_oid);
00051
00052 getPageVersion(&oldPageVersion, srcName);
00053 getPageVersion(&newPageVersion, dstName);
00054
00055
00056
00057
00058
00059 if (newPageVersion != oldPageVersion)
00060 {
00061
00062
00063
00064
00065
00066
00067 if ((converter = loadConverterPlugin(newPageVersion, oldPageVersion)) == NULL)
00068 pg_log(PG_FATAL, "could not find plugin to convert from old page layout to new page layout\n");
00069
00070 return converter;
00071 }
00072 else
00073 return NULL;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 static void
00087 getPageVersion(uint16 *version, const char *pathName)
00088 {
00089 int relfd;
00090 PageHeaderData page;
00091 ssize_t bytesRead;
00092
00093 if ((relfd = open(pathName, O_RDONLY, 0)) < 0)
00094 pg_log(PG_FATAL, "could not open relation %s\n", pathName);
00095
00096 if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page))
00097 pg_log(PG_FATAL, "could not read page header of %s\n", pathName);
00098
00099 *version = PageGetPageLayoutVersion(&page);
00100
00101 close(relfd);
00102
00103 return;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 static pageCnvCtx *
00119 loadConverterPlugin(uint16 newPageVersion, uint16 oldPageVersion)
00120 {
00121 char pluginName[MAXPGPATH];
00122 void *plugin;
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 snprintf(pluginName, sizeof(pluginName), "./plugins/convertLayout_%d_to_%d%s",
00136 oldPageVersion, newPageVersion, DLSUFFIX);
00137
00138 if ((plugin = pg_dlopen(pluginName)) == NULL)
00139 return NULL;
00140 else
00141 {
00142 pageCnvCtx *result = (pageCnvCtx *) pg_malloc(sizeof(*result));
00143
00144 result->old.PageVersion = oldPageVersion;
00145 result->new.PageVersion = newPageVersion;
00146
00147 result->startup = (pluginStartup) pg_dlsym(plugin, "init");
00148 result->convertFile = (pluginConvertFile) pg_dlsym(plugin, "convertFile");
00149 result->convertPage = (pluginConvertPage) pg_dlsym(plugin, "convertPage");
00150 result->shutdown = (pluginShutdown) pg_dlsym(plugin, "fini");
00151 result->pluginData = NULL;
00152
00153
00154
00155
00156 if (result->startup)
00157 result->startup(MIGRATOR_API_VERSION, &result->pluginVersion,
00158 newPageVersion, oldPageVersion, &result->pluginData);
00159
00160 return result;
00161 }
00162 }
00163
00164
00165
00166 #endif