diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index bb96881cad..0fab0a25fd 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -1150,14 +1150,11 @@ mdsync(void) * The bitmap manipulations are slightly tricky, because we can call * AbsorbFsyncRequests() inside the loop and that could result in * bms_add_member() modifying and even re-palloc'ing the bitmapsets. - * This is okay because we unlink each bitmapset from the hashtable - * entry before scanning it. That means that any incoming fsync - * requests will be processed now if they reach the table before we - * begin to scan their fork. + * So we need to take a copy. */ for (forknum = 0; forknum <= MAX_FORKNUM; forknum++) { - Bitmapset *requests = entry->requests[forknum]; + Bitmapset *requests = bms_copy(entry->requests[forknum]); int segno; entry->requests[forknum] = NULL; @@ -1272,10 +1269,18 @@ mdsync(void) */ if (!FILE_POSSIBLY_DELETED(errno) || failures > 0) + { + /* + * We need to merge these unsatisfied requests with + * any others that have arrived since we started. + */ + entry->requests[forknum] = + bms_union(entry->requests[forknum], requests); ereport(ERROR, (errcode_for_file_access(), errmsg("could not fsync file \"%s\": %m", path))); + } else ereport(DEBUG1, (errcode_for_file_access(),