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

Commite4a04e5

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 parentb06649b commite4a04e5

File tree

3 files changed

+263
-117
lines changed

3 files changed

+263
-117
lines changed

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

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

631-
staticvoidfsync_pgdata(char*datadir);
632-
633631
/*
634632
* Insert an XLOG record having the specified RMID and info bytes,
635633
* with the body of the record being the data chunk(s) described by
@@ -5925,18 +5923,6 @@ StartupXLOG(void)
59255923
(errmsg("database system was interrupted; last known up at %s",
59265924
str_time(ControlFile->time))));
59275925

5928-
/*
5929-
* If we previously crashed, there might be data which we had written,
5930-
* intending to fsync it, but which we had not actually fsync'd yet.
5931-
* Therefore, a power failure in the near future might cause earlier
5932-
* unflushed writes to be lost, even though more recent data written to
5933-
* disk from here on would be persisted. To avoid that, fsync the entire
5934-
* data directory.
5935-
*/
5936-
if (ControlFile->state!=DB_SHUTDOWNED&&
5937-
ControlFile->state!=DB_SHUTDOWNED_IN_RECOVERY)
5938-
fsync_pgdata(data_directory);
5939-
59405926
/* This is just to allow attaching to startup process with a debugger */
59415927
#ifdefXLOG_REPLAY_DELAY
59425928
if (ControlFile->state!=DB_SHUTDOWNED)
@@ -5960,6 +5946,18 @@ StartupXLOG(void)
59605946
*/
59615947
RelationCacheInitFileRemove();
59625948

5949+
/*
5950+
* If we previously crashed, there might be data which we had written,
5951+
* intending to fsync it, but which we had not actually fsync'd yet.
5952+
* Therefore, a power failure in the near future might cause earlier
5953+
* unflushed writes to be lost, even though more recent data written to
5954+
* disk from here on would be persisted. To avoid that, fsync the entire
5955+
* data directory.
5956+
*/
5957+
if (ControlFile->state!=DB_SHUTDOWNED&&
5958+
ControlFile->state!=DB_SHUTDOWNED_IN_RECOVERY)
5959+
SyncDataDirectory();
5960+
59635961
/*
59645962
* Initialize on the assumption we want to recover to the same timeline
59655963
* that's active according to pg_control.
@@ -9980,31 +9978,3 @@ CheckForStandbyTrigger(void)
99809978
}
99819979
return false;
99829980
}
9983-
9984-
/*
9985-
* Issue fsync recursively on PGDATA and all its contents.
9986-
*/
9987-
staticvoid
9988-
fsync_pgdata(char*datadir)
9989-
{
9990-
if (!enableFsync)
9991-
return;
9992-
9993-
/*
9994-
* If possible, hint to the kernel that we're soon going to fsync
9995-
* the data directory and its contents.
9996-
*/
9997-
#if defined(HAVE_SYNC_FILE_RANGE)|| \
9998-
(defined(USE_POSIX_FADVISE)&& defined(POSIX_FADV_DONTNEED))
9999-
walkdir(datadir,pre_sync_fname);
10000-
#endif
10001-
10002-
/*
10003-
* Now we do the fsync()s in the same order.
10004-
*
10005-
* It's important to fsync the destination directory itself as individual
10006-
* file fsyncs don't guarantee that the directory entry for the file is
10007-
* synced.
10008-
*/
10009-
walkdir(datadir,fsync_fname);
10010-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp