Skip to content

Commit d7e2606

Browse files
committed
catchup update #3 (tablespace mapping fix)
1 parent 1c1a89c commit d7e2606

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

src/catchup.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,20 @@ do_catchup_instance(const char *source_pgdata, const char *dest_pgdata, PGconn *
339339
else
340340
{
341341
/* this directory located in pg_tblspc */
342-
const char *linked_path = leaked_abstraction_get_tablespace_mapping(file->name);
342+
const char *linked_path = NULL;
343343
char to_path[MAXPGPATH];
344344

345-
//elog(WARNING, "pgFile name: %s rel_path: %s linked: %s\n", file->name, file->rel_path, file->linked);
345+
{ /* get full symlink path and map this path to new location */
346+
char source_full_path[MAXPGPATH];
347+
char symlink_content[MAXPGPATH];
348+
join_path_components(source_full_path, source_pgdata, file->rel_path);
349+
fio_readlink(source_full_path, symlink_content, sizeof(symlink_content), FIO_DB_HOST);
350+
linked_path = leaked_abstraction_get_tablespace_mapping(symlink_content);
351+
elog(WARNING, "Map tablespace full_path: \"%s\" old_symlink_content: \"%s\" old_symlink_content: \"%s\"\n",
352+
source_full_path,
353+
symlink_content,
354+
linked_path);
355+
}
346356

347357
if (!is_absolute_path(linked_path))
348358
elog(ERROR, "Tablespace directory path must be an absolute path: %s\n",

src/utils/file.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,46 @@ int fio_stat(char const* path, struct stat* st, bool follow_symlink, fio_locatio
10621062
}
10631063
}
10641064

1065+
/*
1066+
* Read value of a symbolic link
1067+
* this is a wrapper about readlink() syscall
1068+
* side effects: string truncation occur (and it
1069+
* can be checked by caller by comparing
1070+
* returned value >= valsiz)
1071+
*/
1072+
ssize_t
1073+
fio_readlink(const char *path, char *value, size_t valsiz, fio_location location)
1074+
{
1075+
if (!fio_is_remote(location))
1076+
{
1077+
/* readlink don't place trailing \0 */
1078+
ssize_t len = readlink(path, value, valsiz);
1079+
value[len < valsiz ? len : valsiz] = '\0';
1080+
return len;
1081+
}
1082+
else
1083+
{
1084+
fio_header hdr;
1085+
size_t path_len = strlen(path) + 1;
1086+
1087+
hdr.cop = FIO_READLINK;
1088+
hdr.handle = -1;
1089+
Assert(valsiz <= UINT_MAX); /* max value of fio_header.arg */
1090+
hdr.arg = valsiz;
1091+
hdr.size = path_len;
1092+
1093+
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
1094+
IO_CHECK(fio_write_all(fio_stdout, path, path_len), path_len);
1095+
1096+
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
1097+
Assert(hdr.cop == FIO_READLINK);
1098+
Assert(hdr.size <= valsiz);
1099+
IO_CHECK(fio_read_all(fio_stdin, value, hdr.size), hdr.size);
1100+
value[hdr.size < valsiz ? hdr.size : valsiz] = '\0';
1101+
return hdr.size;
1102+
}
1103+
}
1104+
10651105
/* Check presence of the file */
10661106
int fio_access(char const* path, int mode, fio_location location)
10671107
{
@@ -3175,6 +3215,26 @@ void fio_communicate(int in, int out)
31753215
case FIO_GET_ASYNC_ERROR:
31763216
fio_get_async_error_impl(out);
31773217
break;
3218+
case FIO_READLINK: /* Read content of a symbolic link */
3219+
{
3220+
/*
3221+
* We need a buf for a arguments and for a result at the same time
3222+
* hdr.size = strlen(symlink_name) + 1
3223+
* hdr.arg = bufsize for a answer (symlink content)
3224+
*/
3225+
size_t filename_size = (size_t)hdr.size;
3226+
if (filename_size + hdr.arg > buf_size) {
3227+
buf_size = hdr.arg;
3228+
buf = (char*)realloc(buf, buf_size);
3229+
}
3230+
rc = readlink(buf, buf + filename_size, hdr.arg);
3231+
hdr.cop = FIO_READLINK;
3232+
hdr.size = rc > 0 ? rc : 0;
3233+
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
3234+
if (hdr.size != 0)
3235+
IO_CHECK(fio_write_all(out, buf + filename_size, hdr.size), hdr.size);
3236+
}
3237+
break;
31783238
default:
31793239
Assert(false);
31803240
}

src/utils/file.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ typedef enum
5555
FIO_LIST_DIR,
5656
FIO_CHECK_POSTMASTER,
5757
FIO_GET_ASYNC_ERROR,
58-
FIO_WRITE_ASYNC
58+
FIO_WRITE_ASYNC,
59+
FIO_READLINK
5960
} fio_operations;
6061

6162
typedef enum
@@ -128,6 +129,7 @@ extern int fio_mkdir(char const* path, int mode, fio_location location);
128129
extern int fio_chmod(char const* path, int mode, fio_location location);
129130
extern int fio_access(char const* path, int mode, fio_location location);
130131
extern int fio_stat(char const* path, struct stat* st, bool follow_symlinks, fio_location location);
132+
extern ssize_t fio_readlink(const char *path, char *value, size_t valsiz, fio_location location);
131133
extern DIR* fio_opendir(char const* path, fio_location location);
132134
extern struct dirent * fio_readdir(DIR *dirp);
133135
extern int fio_closedir(DIR *dirp);

tests/catchup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def test_local_simple_transfer_with_tablespace(self):
8585
'Different answer from copy')
8686
dest_pg.stop()
8787

88-
source_pgdata = self.pgdata_content(source_node.data_dir)
89-
dest_pgdata = self.pgdata_content(dest_node.data_dir)
88+
source_pgdata = self.pgdata_content(source_pg.data_dir)
89+
dest_pgdata = self.pgdata_content(dest_pg.data_dir)
9090
self.compare_pgdata(source_pgdata, dest_pgdata)
9191

9292
# Clean after yourself

0 commit comments

Comments
 (0)