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

Commit5b36e8f

Browse files
committed
Change struct tablespaceinfo's oid member from 'char *' to 'Oid'
This shouldn't change behavior except in the unusual case wherethere are file in the tablespace directory that have entirelynumeric names but are nevertheless not possible names for atablespace directory, either because their names have leading zeroesthat shouldn't be there, or the value is actually zero, or becausethe value is too large to represent as an OID.In those cases, the directory would previously have made it intothe list of tablespaceinfo objects and no longer will. Thus, basebackups will now ignore such directories, instead of treating themas legitimate tablespace directories. Similarly, if entries forsuch tablespaces occur in a tablespace_map file, they will nowbe rejected as erroneous, instead of being honored.This is infrastructure for future work that wants to be able toknow the tablespace of each relation that is part of a backup*as an OID*. By strengthening the up-front validation, we don'thave to worry about weird cases later, and can more easily avoidrepeated string->integer conversions.Patch by me, reviewed by David Steele.Discussion:http://postgr.es/m/CA+TgmoZNVeBzoqDL8xvr-nkaepq815jtDR4nJzPew7=3iEuM1g@mail.gmail.com
1 parent5c47c65 commit5b36e8f

File tree

7 files changed

+49
-29
lines changed

7 files changed

+49
-29
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8579,9 +8579,22 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
85798579
char*relpath=NULL;
85808580
char*s;
85818581
PGFileTypede_type;
8582+
char*badp;
8583+
Oidtsoid;
85828584

8583-
/* Skip anything that doesn't look like a tablespace */
8584-
if (strspn(de->d_name,"0123456789")!=strlen(de->d_name))
8585+
/*
8586+
* Try to parse the directory name as an unsigned integer.
8587+
*
8588+
* Tablespace directories should be positive integers that can be
8589+
* represented in 32 bits, with no leading zeroes or trailing
8590+
* garbage. If we come across a name that doesn't meet those
8591+
* criteria, skip it.
8592+
*/
8593+
if (de->d_name[0]<'1'||de->d_name[1]>'9')
8594+
continue;
8595+
errno=0;
8596+
tsoid=strtoul(de->d_name,&badp,10);
8597+
if (*badp!='\0'||errno==EINVAL||errno==ERANGE)
85858598
continue;
85868599

85878600
snprintf(fullpath,sizeof(fullpath),"pg_tblspc/%s",de->d_name);
@@ -8656,7 +8669,7 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
86568669
}
86578670

86588671
ti=palloc(sizeof(tablespaceinfo));
8659-
ti->oid=pstrdup(de->d_name);
8672+
ti->oid=tsoid;
86608673
ti->path=pstrdup(linkpath);
86618674
ti->rpath=relpath;
86628675
ti->size=-1;

‎src/backend/access/transam/xlogrecovery.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
678678
tablespaceinfo*ti=lfirst(lc);
679679
char*linkloc;
680680

681-
linkloc=psprintf("pg_tblspc/%s",ti->oid);
681+
linkloc=psprintf("pg_tblspc/%u",ti->oid);
682682

683683
/*
684684
* Remove the existing symlink if any and Create the symlink
@@ -692,7 +692,6 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
692692
errmsg("could not create symbolic link \"%s\": %m",
693693
linkloc)));
694694

695-
pfree(ti->oid);
696695
pfree(ti->path);
697696
pfree(ti);
698697
}
@@ -1341,6 +1340,8 @@ read_tablespace_map(List **tablespaces)
13411340
{
13421341
if (!was_backslash&& (ch=='\n'||ch=='\r'))
13431342
{
1343+
char*endp;
1344+
13441345
if (i==0)
13451346
continue;/* \r immediately followed by \n */
13461347

@@ -1360,7 +1361,12 @@ read_tablespace_map(List **tablespaces)
13601361
str[n++]='\0';
13611362

13621363
ti=palloc0(sizeof(tablespaceinfo));
1363-
ti->oid=pstrdup(str);
1364+
errno=0;
1365+
ti->oid=strtoul(str,&endp,10);
1366+
if (*endp!='\0'||errno==EINVAL||errno==ERANGE)
1367+
ereport(FATAL,
1368+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1369+
errmsg("invalid data in file \"%s\"",TABLESPACE_MAP)));
13641370
ti->path=pstrdup(str+n);
13651371
*tablespaces=lappend(*tablespaces,ti);
13661372

‎src/backend/backup/backup_manifest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ FreeBackupManifest(backup_manifest_info *manifest)
9797
* Add an entry to the backup manifest for a file.
9898
*/
9999
void
100-
AddFileToBackupManifest(backup_manifest_info*manifest,constchar*spcoid,
100+
AddFileToBackupManifest(backup_manifest_info*manifest,Oidspcoid,
101101
constchar*pathname,size_tsize,pg_time_tmtime,
102102
pg_checksum_context*checksum_ctx)
103103
{
@@ -114,9 +114,9 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
114114
* pathname relative to the data directory (ignoring the intermediate
115115
* symlink traversal).
116116
*/
117-
if (spcoid!=NULL)
117+
if (OidIsValid(spcoid))
118118
{
119-
snprintf(pathbuf,sizeof(pathbuf),"pg_tblspc/%s/%s",spcoid,
119+
snprintf(pathbuf,sizeof(pathbuf),"pg_tblspc/%u/%s",spcoid,
120120
pathname);
121121
pathname=pathbuf;
122122
}

‎src/backend/backup/basebackup.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ typedef struct
7575
pg_checksum_typemanifest_checksum_type;
7676
}basebackup_options;
7777

78-
staticint64sendTablespace(bbsink*sink,char*path,char*spcoid,boolsizeonly,
78+
staticint64sendTablespace(bbsink*sink,char*path,Oidspcoid,boolsizeonly,
7979
structbackup_manifest_info*manifest);
8080
staticint64sendDir(bbsink*sink,constchar*path,intbasepathlen,boolsizeonly,
8181
List*tablespaces,boolsendtblspclinks,
82-
backup_manifest_info*manifest,constchar*spcoid);
82+
backup_manifest_info*manifest,Oidspcoid);
8383
staticboolsendFile(bbsink*sink,constchar*readfilename,constchar*tarfilename,
84-
structstat*statbuf,boolmissing_ok,Oiddboid,
85-
backup_manifest_info*manifest,constchar*spcoid);
84+
structstat*statbuf,boolmissing_ok,
85+
Oiddboid,Oidspcoid,
86+
backup_manifest_info*manifest);
8687
staticoff_tread_file_data_into_buffer(bbsink*sink,
8788
constchar*readfilename,intfd,
8889
off_toffset,size_tlength,
@@ -305,7 +306,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
305306

306307
if (tmp->path==NULL)
307308
tmp->size=sendDir(sink,".",1, true,state.tablespaces,
308-
true,NULL,NULL);
309+
true,NULL,InvalidOid);
309310
else
310311
tmp->size=sendTablespace(sink,tmp->path,tmp->oid, true,
311312
NULL);
@@ -346,7 +347,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
346347

347348
/* Then the bulk of the files... */
348349
sendDir(sink,".",1, false,state.tablespaces,
349-
sendtblspclinks,&manifest,NULL);
350+
sendtblspclinks,&manifest,InvalidOid);
350351

351352
/* ... and pg_control after everything else. */
352353
if (lstat(XLOG_CONTROL_FILE,&statbuf)!=0)
@@ -355,11 +356,11 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
355356
errmsg("could not stat file \"%s\": %m",
356357
XLOG_CONTROL_FILE)));
357358
sendFile(sink,XLOG_CONTROL_FILE,XLOG_CONTROL_FILE,&statbuf,
358-
false,InvalidOid,&manifest,NULL);
359+
false,InvalidOid,InvalidOid,&manifest);
359360
}
360361
else
361362
{
362-
char*archive_name=psprintf("%s.tar",ti->oid);
363+
char*archive_name=psprintf("%u.tar",ti->oid);
363364

364365
bbsink_begin_archive(sink,archive_name);
365366

@@ -623,8 +624,8 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
623624
(errcode_for_file_access(),
624625
errmsg("could not stat file \"%s\": %m",pathbuf)));
625626

626-
sendFile(sink,pathbuf,pathbuf,&statbuf, false,InvalidOid,
627-
&manifest,NULL);
627+
sendFile(sink,pathbuf,pathbuf,&statbuf, false,
628+
InvalidOid,InvalidOid,&manifest);
628629

629630
/* unconditionally mark file as archived */
630631
StatusFilePath(pathbuf,fname,".done");
@@ -1087,7 +1088,7 @@ sendFileWithContent(bbsink *sink, const char *filename, const char *content,
10871088

10881089
_tarWritePadding(sink,len);
10891090

1090-
AddFileToBackupManifest(manifest,NULL,filename,len,
1091+
AddFileToBackupManifest(manifest,InvalidOid,filename,len,
10911092
(pg_time_t)statbuf.st_mtime,&checksum_ctx);
10921093
}
10931094

@@ -1099,7 +1100,7 @@ sendFileWithContent(bbsink *sink, const char *filename, const char *content,
10991100
* Only used to send auxiliary tablespaces, not PGDATA.
11001101
*/
11011102
staticint64
1102-
sendTablespace(bbsink*sink,char*path,char*spcoid,boolsizeonly,
1103+
sendTablespace(bbsink*sink,char*path,Oidspcoid,boolsizeonly,
11031104
backup_manifest_info*manifest)
11041105
{
11051106
int64size;
@@ -1154,7 +1155,7 @@ sendTablespace(bbsink *sink, char *path, char *spcoid, bool sizeonly,
11541155
staticint64
11551156
sendDir(bbsink*sink,constchar*path,intbasepathlen,boolsizeonly,
11561157
List*tablespaces,boolsendtblspclinks,backup_manifest_info*manifest,
1157-
constchar*spcoid)
1158+
Oidspcoid)
11581159
{
11591160
DIR*dir;
11601161
structdirent*de;
@@ -1416,8 +1417,8 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
14161417

14171418
if (!sizeonly)
14181419
sent=sendFile(sink,pathbuf,pathbuf+basepathlen+1,&statbuf,
1419-
true,isDbDir ?atooid(lastDir+1) :InvalidOid,
1420-
manifest,spcoid);
1420+
true,isDbDir ?atooid(lastDir+1) :InvalidOid,spcoid,
1421+
manifest);
14211422

14221423
if (sent||sizeonly)
14231424
{
@@ -1486,8 +1487,8 @@ is_checksummed_file(const char *fullpath, const char *filename)
14861487
*/
14871488
staticbool
14881489
sendFile(bbsink*sink,constchar*readfilename,constchar*tarfilename,
1489-
structstat*statbuf,boolmissing_ok,Oiddboid,
1490-
backup_manifest_info*manifest,constchar*spcoid)
1490+
structstat*statbuf,boolmissing_ok,Oiddboid,Oidspcoid,
1491+
backup_manifest_info*manifest)
14911492
{
14921493
intfd;
14931494
BlockNumberblkno=0;

‎src/backend/backup/basebackup_copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ SendTablespaceList(List *tablespaces)
407407
}
408408
else
409409
{
410-
values[0]=ObjectIdGetDatum(strtoul(ti->oid,NULL,10));
410+
values[0]=ObjectIdGetDatum(ti->oid);
411411
values[1]=CStringGetTextDatum(ti->path);
412412
}
413413
if (ti->size >=0)

‎src/include/backup/backup_manifest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern void InitializeBackupManifest(backup_manifest_info *manifest,
3939
backup_manifest_optionwant_manifest,
4040
pg_checksum_typemanifest_checksum_type);
4141
externvoidAddFileToBackupManifest(backup_manifest_info*manifest,
42-
constchar*spcoid,
42+
Oidspcoid,
4343
constchar*pathname,size_tsize,
4444
pg_time_tmtime,
4545
pg_checksum_context*checksum_ctx);

‎src/include/backup/basebackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
typedefstruct
2929
{
30-
char*oid;/* tablespace's OID, as a decimal string */
30+
Oidoid;/* tablespace's OID */
3131
char*path;/* full path to tablespace's directory */
3232
char*rpath;/* relative path if it's within PGDATA, else
3333
* NULL */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp