Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d938eb

Browse files
committed
Change the way pg_basebackup's tablespace mapping is implemented.
Previously, we would first create the symlinks the way they are in theoriginal system, and at the end replace them with the mapped symlinks.That never really made much sense, so now we create the symlink pointingto the correct location to begin with, so that there's no need to fixthem at the end.The old coding didn't work correctly on Windows, because Windows junctionpoints look more like directories than files, and ought to be removed withrmdir rather than unlink. Also, it incorrectly used "%d" rather than "%u"to print an Oid, but that's gone now.Report and patch by Amit Kapila, with minor changes by me. Reviewed byMauMau. Backpatch to 9.4, where the --tablespace feature was added.
1 parent3feda1b commit8d938eb

File tree

1 file changed

+20
-44
lines changed

1 file changed

+20
-44
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline,
109109
boolsegment_finished);
110110

111111
staticconstchar*get_tablespace_mapping(constchar*dir);
112-
staticvoidupdate_tablespace_symlink(Oidoid,constchar*old_dir);
113112
staticvoidtablespace_list_append(constchar*arg);
114113

115114

@@ -1109,34 +1108,6 @@ get_tablespace_mapping(const char *dir)
11091108
}
11101109

11111110

1112-
/*
1113-
* Update symlinks to reflect relocated tablespace.
1114-
*/
1115-
staticvoid
1116-
update_tablespace_symlink(Oidoid,constchar*old_dir)
1117-
{
1118-
constchar*new_dir=get_tablespace_mapping(old_dir);
1119-
1120-
if (strcmp(old_dir,new_dir)!=0)
1121-
{
1122-
char*linkloc=psprintf("%s/pg_tblspc/%d",basedir,oid);
1123-
1124-
if (unlink(linkloc)!=0&&errno!=ENOENT)
1125-
{
1126-
fprintf(stderr,_("%s: could not remove symbolic link \"%s\": %s\n"),
1127-
progname,linkloc,strerror(errno));
1128-
disconnect_and_exit(1);
1129-
}
1130-
if (symlink(new_dir,linkloc)!=0)
1131-
{
1132-
fprintf(stderr,_("%s: could not create symbolic link \"%s\": %s\n"),
1133-
progname,linkloc,strerror(errno));
1134-
disconnect_and_exit(1);
1135-
}
1136-
}
1137-
}
1138-
1139-
11401111
/*
11411112
* Receive a tar format stream from the connection to the server, and unpack
11421113
* the contents of it into a directory. Only files, directories and
@@ -1151,16 +1122,20 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
11511122
{
11521123
charcurrent_path[MAXPGPATH];
11531124
charfilename[MAXPGPATH];
1125+
constchar*mapped_tblspc_path;
11541126
intcurrent_len_left;
11551127
intcurrent_padding=0;
1156-
boolbasetablespace=PQgetisnull(res,rownum,0);
1128+
boolbasetablespace;
11571129
char*copybuf=NULL;
11581130
FILE*file=NULL;
11591131

1132+
basetablespace=PQgetisnull(res,rownum,0);
11601133
if (basetablespace)
11611134
strlcpy(current_path,basedir,sizeof(current_path));
11621135
else
1163-
strlcpy(current_path,get_tablespace_mapping(PQgetvalue(res,rownum,1)),sizeof(current_path));
1136+
strlcpy(current_path,
1137+
get_tablespace_mapping(PQgetvalue(res,rownum,1)),
1138+
sizeof(current_path));
11641139

11651140
/*
11661141
* Get the COPY data
@@ -1284,13 +1259,25 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
12841259
{
12851260
/*
12861261
* Symbolic link
1262+
*
1263+
* It's most likely a link in pg_tblspc directory, to
1264+
* the location of a tablespace. Apply any tablespace
1265+
* mapping given on the command line (--tablespace).
1266+
* (We blindly apply the mapping without checking that
1267+
* the link really is inside pg_tblspc. We don't expect
1268+
* there to be other symlinks in a data directory, but
1269+
* if there are, you can call it an undocumented feature
1270+
* that you can map them too.)
12871271
*/
12881272
filename[strlen(filename)-1]='\0';/* Remove trailing slash */
1289-
if (symlink(&copybuf[157],filename)!=0)
1273+
1274+
mapped_tblspc_path=get_tablespace_mapping(&copybuf[157]);
1275+
if (symlink(mapped_tblspc_path,filename)!=0)
12901276
{
12911277
fprintf(stderr,
12921278
_("%s: could not create symbolic link from \"%s\" to \"%s\": %s\n"),
1293-
progname,filename,&copybuf[157],strerror(errno));
1279+
progname,filename,mapped_tblspc_path,
1280+
strerror(errno));
12941281
disconnect_and_exit(1);
12951282
}
12961283
}
@@ -1793,17 +1780,6 @@ BaseBackup(void)
17931780
fprintf(stderr,"\n");/* Need to move to next line */
17941781
}
17951782

1796-
if (format=='p'&&tablespace_dirs.head!=NULL)
1797-
{
1798-
for (i=0;i<PQntuples(res);i++)
1799-
{
1800-
Oidtblspc_oid=atooid(PQgetvalue(res,i,0));
1801-
1802-
if (tblspc_oid)
1803-
update_tablespace_symlink(tblspc_oid,PQgetvalue(res,i,1));
1804-
}
1805-
}
1806-
18071783
PQclear(res);
18081784

18091785
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp