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

Commita8ea8ab

Browse files
author
Arthur Zakirov
committed
Fix for3e8ac28, improve error messages.
We need call fflush() for buffered IO. Without fflush() fsync() could be useless.
1 parent9f91dfc commita8ea8ab

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

‎src/backup.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ pg_stop_backup(pgBackup *backup)
11021102
charbackup_label[MAXPGPATH];
11031103
FILE*fp;
11041104
pgFile*file;
1105+
size_tlen;
11051106

11061107
Assert(PQnfields(res) >=5);
11071108

@@ -1114,9 +1115,13 @@ pg_stop_backup(pgBackup *backup)
11141115
elog(ERROR,"can't open backup label file \"%s\": %s",
11151116
backup_label,strerror(errno));
11161117

1117-
fwrite(PQgetvalue(res,0,1),1,strlen(PQgetvalue(res,0,1)),fp);
1118-
fsync(fileno(fp));
1119-
fclose(fp);
1118+
len=strlen(PQgetvalue(res,0,1));
1119+
if (fwrite(PQgetvalue(res,0,1),1,len,fp)!=len||
1120+
fflush(fp)!=0||
1121+
fsync(fileno(fp))!=0||
1122+
fclose(fp))
1123+
elog(ERROR,"can't write backup label file \"%s\": %s",
1124+
backup_label,strerror(errno));
11201125

11211126
/*
11221127
* It's vital to check if backup_files_list is initialized,
@@ -1142,9 +1147,13 @@ pg_stop_backup(pgBackup *backup)
11421147
elog(ERROR,"can't open tablespace map file \"%s\": %s",
11431148
tablespace_map,strerror(errno));
11441149

1145-
fwrite(PQgetvalue(res,0,2),1,strlen(PQgetvalue(res,0,2)),fp);
1146-
fsync(fileno(fp));
1147-
fclose(fp);
1150+
len=strlen(PQgetvalue(res,0,2));
1151+
if (fwrite(PQgetvalue(res,0,2),1,len,fp)!=len||
1152+
fflush(fp)!=0||
1153+
fsync(fileno(fp))!=0||
1154+
fclose(fp))
1155+
elog(ERROR,"can't write tablespace map file \"%s\": %s",
1156+
tablespace_map,strerror(errno));
11481157

11491158
file=pgFileNew(tablespace_map, true);
11501159
calc_file_checksum(file);
@@ -1667,8 +1676,10 @@ write_backup_file_list(parray *files, const char *root)
16671676

16681677
print_file_list(fp,files,root);
16691678

1670-
fsync(fileno(fp));
1671-
fclose(fp);
1679+
if (fflush(fp)!=0||
1680+
fsync(fileno(fp))!=0||
1681+
fclose(fp))
1682+
elog(ERROR,"cannot write file list \"%s\": %s",path,strerror(errno));
16721683
}
16731684

16741685
/*

‎src/data.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,12 @@ backup_data_file(const char *from_root, const char *to_root,
357357
strerror(errno_tmp));
358358
}
359359

360-
fsync(fileno(out));
360+
if (fflush(out)!=0||
361+
fsync(fileno(out))!=0||
362+
fclose(out))
363+
elog(ERROR,"cannot write backup file \"%s\": %s",
364+
to_path,strerror(errno));
361365
fclose(in);
362-
fclose(out);
363366

364367
FIN_CRC32C(file->crc);
365368

@@ -471,9 +474,11 @@ restore_file_partly(const char *from_root,const char *to_root, pgFile *file)
471474
strerror(errno_tmp));
472475
}
473476

474-
fsync(fileno(out));
477+
if (fflush(out)!=0||
478+
fsync(fileno(out))!=0||
479+
fclose(out))
480+
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
475481
fclose(in);
476-
fclose(out);
477482
}
478483

479484
void
@@ -607,9 +612,11 @@ restore_data_file(const char *from_root,
607612
strerror(errno_tmp));
608613
}
609614

610-
fsync(fileno(out));
615+
if (fflush(out)!=0||
616+
fsync(fileno(out))!=0||
617+
fclose(out))
618+
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
611619
fclose(in);
612-
fclose(out);
613620
}
614621

615622
/*
@@ -735,9 +742,11 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
735742
strerror(errno_tmp));
736743
}
737744

738-
fsync(fileno(out));
745+
if (fflush(out)!=0||
746+
fsync(fileno(out))!=0||
747+
fclose(out))
748+
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
739749
fclose(in);
740-
fclose(out);
741750

742751
return true;
743752
}
@@ -836,9 +845,11 @@ copy_wal_file(const char *from_path, const char *to_path)
836845
strerror(errno_tmp));
837846
}
838847

839-
fsync(fileno(out));
848+
if (fflush(out)!=0||
849+
fsync(fileno(out))!=0||
850+
fclose(out))
851+
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
840852
fclose(in);
841-
fclose(out);
842853
}
843854

844855
/*
@@ -961,9 +972,11 @@ copy_file_partly(const char *from_root, const char *to_root,
961972
/* add meta information needed for recovery */
962973
file->is_partial_copy= true;
963974

964-
fsync(fileno(out));
975+
if (fflush(out)!=0||
976+
fsync(fileno(out))!=0||
977+
fclose(out))
978+
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
965979
fclose(in);
966-
fclose(out);
967980

968981
return true;
969982
}

‎src/restore.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,11 @@ create_recovery_conf(time_t backup_id,
750750
if (target_tli)
751751
fprintf(fp,"recovery_target_timeline = '%u'\n",target_tli);
752752

753-
fsync(fileno(fp));
754-
fclose(fp);
753+
if (fflush(fp)!=0||
754+
fsync(fileno(fp))!=0||
755+
fclose(fp))
756+
elog(ERROR,"cannot write recovery.conf \"%s\": %s",path,
757+
strerror(errno));
755758
}
756759

757760
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp