Skip to content

Commit 6519300

Browse files
committed
fix gpupgrade with tablespace
1 parent 0d5a39c commit 6519300

File tree

12 files changed

+162
-34
lines changed

12 files changed

+162
-34
lines changed

aclocal.m4

Lines changed: 0 additions & 19 deletions
This file was deleted.

gpAux/gpdemo/gpdemo-defaults.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ USAGE() {
2626
echo ""
2727
}
2828

29-
PORT_BASE=${PORT_BASE:=7000}
29+
PORT_BASE=${PORT_BASE:=10000}
3030
NUM_PRIMARY_MIRROR_PAIRS=${NUM_PRIMARY_MIRROR_PAIRS:=3}
3131
if [ "${NUM_PRIMARY_MIRROR_PAIRS}" -eq "0" ]; then
3232
BLDWRAP_POSTGRES_CONF_ADDONS="fsync=on ${BLDWRAP_POSTGRES_CONF_ADDONS}" # always enable fsync if singlenode

src/backend/utils/adt/pg_upgrade_support.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "catalog/pg_class.h"
2121
#include "catalog/pg_enum.h"
2222
#include "catalog/pg_namespace.h"
23+
#include "catalog/pg_tablespace.h"
2324
#include "catalog/pg_type.h"
2425
#include "cdb/cdbvars.h"
2526
#include "commands/extension.h"
@@ -38,6 +39,19 @@ do { \
3839
errmsg("function can only be called when server is in binary upgrade mode"))); \
3940
} while (0)
4041

42+
Datum
43+
binary_upgrade_set_next_pg_tablespace_oid(PG_FUNCTION_ARGS)
44+
{
45+
Oid tablespaceoid = PG_GETARG_OID(0);
46+
char *tablespacename = GET_STR(PG_GETARG_TEXT_P(1));
47+
48+
CHECK_IS_BINARY_UPGRADE;
49+
AddPreassignedOidFromBinaryUpgrade(tablespaceoid, TableSpaceRelationId, tablespacename,
50+
InvalidOid, InvalidOid, InvalidOid);
51+
52+
PG_RETURN_VOID();
53+
}
54+
4155
Datum
4256
binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
4357
{

src/bin/pg_dump/pg_backup.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ typedef struct _dumpOptions
184184
int do_nothing;
185185
} DumpOptions;
186186

187+
188+
typedef enum
189+
{
190+
Greenplum,
191+
Cloudberry
192+
} DatabaseType;
193+
194+
typedef struct
195+
{
196+
DatabaseType type;
197+
int version;
198+
} DatabaseVersion;
187199
/*
188200
* We may want to have some more user-readable data, but in the mean
189201
* time this gives us some abstraction and type checking.
@@ -216,6 +228,8 @@ typedef struct Archive
216228
bool exit_on_error; /* whether to exit on SQL errors... */
217229
int n_errors; /* number of errors (if no die) */
218230

231+
DatabaseVersion version;
232+
219233
/* The rest is private */
220234
} Archive;
221235

src/bin/pg_dump/pg_backup_db.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ _check_database_version(ArchiveHandle *AH)
3535
const char *remoteversion_str;
3636
int remoteversion;
3737
PGresult *res;
38+
char *version;
39+
char dbstring[1024];
40+
char dbstring2[1024];
41+
int v1;
3842

3943
remoteversion_str = PQparameterStatus(AH->connection, "server_version");
4044
remoteversion = PQserverVersion(AH->connection);
@@ -68,6 +72,29 @@ _check_database_version(ArchiveHandle *AH)
6872
}
6973
else
7074
AH->public.isStandby = false;
75+
76+
ExecuteSqlQueryForSingleRow((Archive *) AH, "SELECT version()");
77+
78+
version = PQgetvalue(res, 0, 0);
79+
80+
if(sscanf(version, "%*[^(](%s %s %d.%*d.%*d-%*[^)])", dbstring, dbstring2, &v1) != 3)
81+
pg_log_error("could not get version output from select version();\n");
82+
83+
if (strcasecmp("Greenplum", dbstring) == 0 && strcasecmp("Database", dbstring2) == 0)
84+
{
85+
AH->public.version.type = Greenplum;
86+
AH->public.version.version = v1;
87+
88+
} else if((strcasecmp("Cloudberry", dbstring) == 0 && strcasecmp("Database", dbstring2) == 0)
89+
|| (strcasecmp("Apache", dbstring) == 0 && strcasecmp("Cloudberry", dbstring2) == 0))
90+
{
91+
AH->public.version.type = Cloudberry;
92+
AH->public.version.version = v1;
93+
}
94+
else
95+
pg_log_error("could not upgrade from non Greenplum/Cloudberry version: %s %s\n", dbstring, dbstring2);
96+
97+
PQclear(res);
7198
}
7299

73100
/*

src/bin/pg_dump/pg_dump.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,6 @@ main(int argc, char **argv)
928928
/* Let the archiver know how noisy to be */
929929
fout->verbose = g_verbose;
930930

931-
pg_log_info("123");
932-
933931

934932
/*
935933
* We allow the server to be back to 8.3, and up to any minor release of
@@ -947,8 +945,6 @@ main(int argc, char **argv)
947945
ConnectDatabase(fout, &dopt.cparams, false, dopt.binary_upgrade);
948946
setup_connection(fout, dumpencoding, dumpsnapshot, use_role);
949947

950-
pg_log_info("123");
951-
952948
/*
953949
* Determine whether or not we're interacting with a GP backend.
954950
*/
@@ -973,8 +969,6 @@ main(int argc, char **argv)
973969
break;
974970
}
975971

976-
pg_log_info("123");
977-
978972
/*
979973
* Disable security label support if server version < v9.1.x (prevents
980974
* access to nonexistent pg_seclabel catalog)
@@ -7347,7 +7341,7 @@ getTables(Archive *fout, int *numTables)
73477341
int i_amname;
73487342
int i_amoid;
73497343
int i_isivm;
7350-
// int i_isdynamic;
7344+
int i_isdynamic;
73517345

73527346
/*
73537347
* Find all the tables and table-like objects.
@@ -7468,8 +7462,8 @@ getTables(Archive *fout, int *numTables)
74687462
"%s AS partkeydef, "
74697463
"%s AS ispartition, "
74707464
"%s AS partbound, "
7471-
"c.relisivm AS isivm "
7472-
// "c.relisdynamic AS isdynamic "
7465+
"c.relisivm AS isivm, "
7466+
"%s"
74737467
"FROM pg_class c "
74747468
"LEFT JOIN pg_depend d ON "
74757469
"(c.relkind = '%c' AND "
@@ -7499,6 +7493,7 @@ getTables(Archive *fout, int *numTables)
74997493
partkeydef,
75007494
ispartition,
75017495
partbound,
7496+
(fout->version.type == Cloudberry && fout->version.version >= 2) ? "c.relisdynamic AS isdynamic " : "false AS isdynamic ",
75027497
RELKIND_SEQUENCE,
75037498
RELKIND_PARTITIONED_TABLE,
75047499
RELKIND_RELATION, RELKIND_SEQUENCE,
@@ -7992,7 +7987,7 @@ getTables(Archive *fout, int *numTables)
79927987
i_amname = PQfnumber(res, "amname");
79937988
i_amoid = PQfnumber(res, "amoid");
79947989
i_isivm = PQfnumber(res, "isivm");
7995-
// i_isdynamic = PQfnumber(res, "isdynamic");
7990+
i_isdynamic = PQfnumber(res, "isdynamic");
79967991

79977992
if (dopt->lockWaitTimeout)
79987993
{
@@ -8127,7 +8122,7 @@ getTables(Archive *fout, int *numTables)
81278122
tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
81288123
tblinfo[i].partbound = pg_strdup(PQgetvalue(res, i, i_partbound));
81298124
tblinfo[i].isivm = (strcmp(PQgetvalue(res, i, i_isivm), "t") == 0);
8130-
// tblinfo[i].isdynamic = (strcmp(PQgetvalue(res, i, i_isdynamic), "t") == 0);
8125+
tblinfo[i].isdynamic = (strcmp(PQgetvalue(res, i, i_isdynamic), "t") == 0);
81318126

81328127
/* foreign server */
81338128
tblinfo[i].foreign_server = atooid(PQgetvalue(res, i, i_foreignserver));

src/bin/pg_dump/pg_dumpall.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,12 @@ dumpTablespaces(PGconn *conn)
17591759
/* needed for buildACLCommands() */
17601760
fspcname = pg_strdup(fmtId(spcname));
17611761

1762+
if (binary_upgrade)
1763+
{
1764+
appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_tablespace oid\n");
1765+
appendPQExpBuffer(buf, "SELECT pg_catalog.binary_upgrade_set_next_pg_tablespace_oid('%u'::pg_catalog.oid, '%s'::text);\n", spcoid, spcname);
1766+
}
1767+
17621768
appendPQExpBuffer(buf, "CREATE TABLESPACE %s", spcname);
17631769
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
17641770

src/bin/pg_upgrade/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ check_for_new_tablespace_dir(ClusterInfo *new_cluster)
576576
os_info.old_tablespaces[tblnum],
577577
new_cluster->tablespace_suffix);
578578

579-
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
579+
if (is_greenplum_dispatcher_mode() && (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT))
580580
gp_fatal_log("new cluster tablespace directory already exists: \"%s\"\n",
581581
new_tablespace_dir);
582582
}

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static void copy_xact_xlog_xid(void);
5959
static void set_frozenxids(bool minmxid_only);
6060
static void make_outputdirs(char *pgdata);
6161
static void setup(char *argv0, bool *live_check);
62+
static void get_cluster_version(ClusterInfo *cluster, bool live_check);
6263

6364
static void copy_subdir_files(const char *old_subdir, const char *new_subdir);
6465

@@ -170,6 +171,9 @@ main(int argc, char **argv)
170171
umask(pg_mode_mask);
171172
}
172173

174+
get_cluster_version(&old_cluster, live_check);
175+
get_cluster_version(&new_cluster, live_check);
176+
173177

174178
check_and_dump_old_cluster(live_check, &sequence_script_file_name);
175179

@@ -304,6 +308,74 @@ main(int argc, char **argv)
304308
return 0;
305309
}
306310

311+
312+
void
313+
get_cluster_version(ClusterInfo *cluster, bool live_check)
314+
{
315+
PGconn *conn;
316+
PGresult *res;
317+
char query[QUERY_ALLOC];
318+
char *version;
319+
int i_version;
320+
int ntups;
321+
int dbid;
322+
int i_dbid;
323+
char dbstring[MAX_STRING];
324+
char dbstring2[MAX_STRING];
325+
int v1;
326+
327+
start_postmaster(cluster, false);
328+
329+
conn = connectToServer(cluster, "template1");
330+
331+
snprintf(query, sizeof(query), "SELECT version()");
332+
333+
res = executeQueryOrDie(conn, "%s", query);
334+
335+
i_version = PQfnumber(res, "version");
336+
337+
ntups = PQntuples(res);
338+
Assert(ntups == 1);
339+
340+
version = PQgetvalue(res, 0, i_version);
341+
342+
if(sscanf(version, "%*[^(](%s %s %d.%*d.%*d-%*[^)])", dbstring, dbstring2, &v1) != 3)
343+
pg_fatal("could not get version output from select version();\n");
344+
345+
if (strcasecmp("Greenplum", dbstring) == 0 && strcasecmp("Database", dbstring2) == 0)
346+
{
347+
cluster->version.type = Greenplum;
348+
cluster->version.version = v1;
349+
350+
} else if((strcasecmp("Cloudberry", dbstring) == 0 && strcasecmp("Database", dbstring2) == 0)
351+
|| (strcasecmp("Apache", dbstring) == 0 && strcasecmp("Cloudberry", dbstring2) == 0))
352+
{
353+
cluster->version.type = Cloudberry;
354+
cluster->version.version = v1;
355+
}
356+
else
357+
pg_fatal("could not upgrade from non Greenplum/Cloudberry version: %s %s\n", dbstring, dbstring2);
358+
359+
res = executeQueryOrDie(conn, "%s", "show gp_dbid;");
360+
361+
i_dbid = PQfnumber(res, "gp_dbid");
362+
363+
ntups = PQntuples(res);
364+
Assert(ntups == 1);
365+
366+
dbid = atoi(PQgetvalue(res, 0, i_dbid));
367+
368+
cluster->dbid = dbid;
369+
370+
PQclear(res);
371+
372+
PQfinish(conn);
373+
374+
stop_postmaster(cluster);
375+
376+
return;
377+
}
378+
307379
#ifdef WIN32
308380
typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);
309381

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ typedef enum
351351

352352
typedef long pgpid_t;
353353

354+
typedef enum
355+
{
356+
Greenplum,
357+
Cloudberry
358+
} DatabaseType;
359+
360+
typedef struct
361+
{
362+
DatabaseType type;
363+
int version;
364+
} DatabaseVersion;
365+
354366

355367
/*
356368
* cluster
@@ -373,6 +385,8 @@ typedef struct
373385
char major_version_str[64]; /* string PG_VERSION of cluster */
374386
uint32 bin_version; /* version returned from pg_ctl */
375387
const char *tablespace_suffix; /* directory specification */
388+
DatabaseVersion version;
389+
int32 dbid;
376390
} ClusterInfo;
377391

378392

0 commit comments

Comments
 (0)