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

Commitaa8377e

Browse files
committed
Fix fsync-at-startup code to not treat errors as fatal.
Commit2ce439f introduced a rather seriousregression, namely that if its scan of the data directory came across anyun-fsync-able files, it would fail and thereby prevent database startup.Worse yet, symlinks to such files also caused the problem, which meant thatcrash restart was guaranteed to fail on certain common installations suchas older Debian.After discussion, we agreed that (1) failure to start is worse than anyconsequence of not fsync'ing is likely to be, therefore treat all errorsin this code as nonfatal; (2) we should not chase symlinks other thanthose that are expected to exist, namely pg_xlog/ and tablespace linksunder pg_tblspc/. The latter restriction avoids possibly fsync'ing amuch larger part of the filesystem than intended, if the user has leftrandom symlinks hanging about in the data directory.This commit takes care of that and also does some code beautification,mainly moving the relevant code into fd.c, which seems a much better placefor it than xlog.c, and making sure that the conditional compilation forthe pre_sync_fname pass has something to do with whether pg_flush_dataworks.I also relocated the call site in xlog.c down a few lines; it seems abit silly to be doing this before ValidateXLOGDirectoryStructure().The similar logic in initdb.c ought to be made to match this, but thatchange is noncritical and will be dealt with separately.Back-patch to all active branches, like the prior commit.Abhijit Menon-Sen and Tom Lane
1 parentf3c67aa commitaa8377e

File tree

3 files changed

+259
-113
lines changed

3 files changed

+259
-113
lines changed

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

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,6 @@ static bool read_backup_label(XLogRecPtr *checkPointLoc,
701701
staticvoidrm_redo_error_callback(void*arg);
702702
staticintget_sync_bit(intmethod);
703703

704-
staticvoidfsync_pgdata(char*datadir);
705-
706704
/*
707705
* Insert an XLOG record having the specified RMID and info bytes,
708706
* with the body of the record being the data chunk(s) described by
@@ -6418,18 +6416,6 @@ StartupXLOG(void)
64186416
(errmsg("database system was interrupted; last known up at %s",
64196417
str_time(ControlFile->time))));
64206418

6421-
/*
6422-
* If we previously crashed, there might be data which we had written,
6423-
* intending to fsync it, but which we had not actually fsync'd yet.
6424-
* Therefore, a power failure in the near future might cause earlier
6425-
* unflushed writes to be lost, even though more recent data written to
6426-
* disk from here on would be persisted. To avoid that, fsync the entire
6427-
* data directory.
6428-
*/
6429-
if (ControlFile->state!=DB_SHUTDOWNED&&
6430-
ControlFile->state!=DB_SHUTDOWNED_IN_RECOVERY)
6431-
fsync_pgdata(data_directory);
6432-
64336419
/* This is just to allow attaching to startup process with a debugger */
64346420
#ifdefXLOG_REPLAY_DELAY
64356421
if (ControlFile->state!=DB_SHUTDOWNED)
@@ -6453,6 +6439,18 @@ StartupXLOG(void)
64536439
*/
64546440
RelationCacheInitFileRemove();
64556441

6442+
/*
6443+
* If we previously crashed, there might be data which we had written,
6444+
* intending to fsync it, but which we had not actually fsync'd yet.
6445+
* Therefore, a power failure in the near future might cause earlier
6446+
* unflushed writes to be lost, even though more recent data written to
6447+
* disk from here on would be persisted. To avoid that, fsync the entire
6448+
* data directory.
6449+
*/
6450+
if (ControlFile->state!=DB_SHUTDOWNED&&
6451+
ControlFile->state!=DB_SHUTDOWNED_IN_RECOVERY)
6452+
SyncDataDirectory();
6453+
64566454
/*
64576455
* Initialize on the assumption we want to recover to the same timeline
64586456
* that's active according to pg_control.
@@ -11027,31 +11025,3 @@ SetWalWriterSleeping(bool sleeping)
1102711025
xlogctl->WalWriterSleeping=sleeping;
1102811026
SpinLockRelease(&xlogctl->info_lck);
1102911027
}
11030-
11031-
/*
11032-
* Issue fsync recursively on PGDATA and all its contents.
11033-
*/
11034-
staticvoid
11035-
fsync_pgdata(char*datadir)
11036-
{
11037-
if (!enableFsync)
11038-
return;
11039-
11040-
/*
11041-
* If possible, hint to the kernel that we're soon going to fsync
11042-
* the data directory and its contents.
11043-
*/
11044-
#if defined(HAVE_SYNC_FILE_RANGE)|| \
11045-
(defined(USE_POSIX_FADVISE)&& defined(POSIX_FADV_DONTNEED))
11046-
walkdir(datadir,pre_sync_fname);
11047-
#endif
11048-
11049-
/*
11050-
* Now we do the fsync()s in the same order.
11051-
*
11052-
* It's important to fsync the destination directory itself as individual
11053-
* file fsyncs don't guarantee that the directory entry for the file is
11054-
* synced.
11055-
*/
11056-
walkdir(datadir,fsync_fname);
11057-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp