Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a4d6d6a

Browse files
committed
Don't forget about failed fsync() requests.
If fsync() fails, md.c must keep the request in its bitmap, so that future attempts will try again. Back-patch to all supported releases. Author: Thomas Munro Reviewed-by: Amit Kapila Reported-by: Andrew Gierth Discussion: https://postgr.es/m/87y3i1ia4w.fsf%40news-spur.riddles.org.uk
1 parent 71b2951 commit a4d6d6a

File tree

1 file changed

+18
-5
lines changed
  • src/backend/storage/smgr

1 file changed

+18
-5
lines changed

src/backend/storage/smgr/md.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,8 @@ mdsync(void)
11481148
* The bitmap manipulations are slightly tricky, because we can call
11491149
* AbsorbFsyncRequests() inside the loop and that could result in
11501150
* bms_add_member() modifying and even re-palloc'ing the bitmapsets.
1151-
* This is okay because we unlink each bitmapset from the hashtable
1152-
* entry before scanning it. That means that any incoming fsync
1153-
* requests will be processed now if they reach the table before we
1154-
* begin to scan their fork.
1151+
* So we detach it, but if we fail we'll merge it with any new
1152+
* requests that have arrived in the meantime.
11551153
*/
11561154
for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
11571155
{
@@ -1161,7 +1159,8 @@ mdsync(void)
11611159
entry->requests[forknum] = NULL;
11621160
entry->canceled[forknum] = false;
11631161

1164-
while ((segno = bms_first_member(requests)) >= 0)
1162+
segno = -1;
1163+
while ((segno = bms_next_member(requests, segno)) >= 0)
11651164
{
11661165
int failures;
11671166

@@ -1242,6 +1241,7 @@ mdsync(void)
12421241
longest = elapsed;
12431242
total_elapsed += elapsed;
12441243
processed++;
1244+
requests = bms_del_member(requests, segno);
12451245
if (log_checkpoints)
12461246
elog(DEBUG1, "checkpoint sync: number=%d file=%s time=%.3f msec",
12471247
processed,
@@ -1270,10 +1270,23 @@ mdsync(void)
12701270
*/
12711271
if (!FILE_POSSIBLY_DELETED(errno) ||
12721272
failures > 0)
1273+
{
1274+
Bitmapset *new_requests;
1275+
1276+
/*
1277+
* We need to merge these unsatisfied requests with
1278+
* any others that have arrived since we started.
1279+
*/
1280+
new_requests = entry->requests[forknum];
1281+
entry->requests[forknum] =
1282+
bms_join(new_requests, requests);
1283+
1284+
errno = save_errno;
12731285
ereport(ERROR,
12741286
(errcode_for_file_access(),
12751287
errmsg("could not fsync file \"%s\": %m",
12761288
path)));
1289+
}
12771290
else
12781291
ereport(DEBUG1,
12791292
(errcode_for_file_access(),

0 commit comments

Comments
 (0)