@@ -1123,10 +1123,8 @@ mdsync(void)
1123
1123
* The bitmap manipulations are slightly tricky, because we can call
1124
1124
* AbsorbFsyncRequests() inside the loop and that could result in
1125
1125
* bms_add_member() modifying and even re-palloc'ing the bitmapsets.
1126
- * This is okay because we unlink each bitmapset from the hashtable
1127
- * entry before scanning it. That means that any incoming fsync
1128
- * requests will be processed now if they reach the table before we
1129
- * begin to scan their fork.
1126
+ * So we detach it, but if we fail we'll merge it with any new
1127
+ * requests that have arrived in the meantime.
1130
1128
*/
1131
1129
for (forknum = 0 ; forknum <= MAX_FORKNUM ; forknum ++ )
1132
1130
{
@@ -1136,7 +1134,8 @@ mdsync(void)
1136
1134
entry -> requests [forknum ] = NULL ;
1137
1135
entry -> canceled [forknum ] = false;
1138
1136
1139
- while ((segno = bms_first_member (requests )) >= 0 )
1137
+ segno = -1 ;
1138
+ while ((segno = bms_next_member (requests , segno )) >= 0 )
1140
1139
{
1141
1140
int failures ;
1142
1141
@@ -1217,6 +1216,7 @@ mdsync(void)
1217
1216
longest = elapsed ;
1218
1217
total_elapsed += elapsed ;
1219
1218
processed ++ ;
1219
+ requests = bms_del_member (requests , segno );
1220
1220
if (log_checkpoints )
1221
1221
elog (DEBUG1 , "checkpoint sync: number=%d file=%s time=%.3f msec" ,
1222
1222
processed ,
@@ -1245,10 +1245,23 @@ mdsync(void)
1245
1245
*/
1246
1246
if (!FILE_POSSIBLY_DELETED (errno ) ||
1247
1247
failures > 0 )
1248
+ {
1249
+ Bitmapset * new_requests ;
1250
+
1251
+ /*
1252
+ * We need to merge these unsatisfied requests with
1253
+ * any others that have arrived since we started.
1254
+ */
1255
+ new_requests = entry -> requests [forknum ];
1256
+ entry -> requests [forknum ] =
1257
+ bms_join (new_requests , requests );
1258
+
1259
+ errno = save_errno ;
1248
1260
ereport (ERROR ,
1249
1261
(errcode_for_file_access (),
1250
1262
errmsg ("could not fsync file \"%s\": %m" ,
1251
1263
path )));
1264
+ }
1252
1265
else
1253
1266
ereport (DEBUG1 ,
1254
1267
(errcode_for_file_access (),
0 commit comments