/* *Insomecontexts(currently,standalonebackendsandthecheckpointer) *wekeeptrackofpendingfsyncoperations:weneedtorememberallrelation *segmentsthathavebeenwrittensincethelastcheckpoint,sothatwecan *fsyncthemdowntodiskbeforecompletingthenextcheckpoint.Thishash *tableremembersthependingoperations.Weuseahashtablemostlyas *aconvenientwayofmergingduplicaterequests. * *Weuseasimilarmechanismtorememberno-longer-neededfilesthatcan *bedeletedafterthenextcheckpoint,butweusealinkedlistinsteadof *ahashtable,becausewedon'texpecttheretobeanyduplicaterequests. * *Thesemechanismsareonlyusedfornon-temprelations;weneverfsync *temprels,nordoweneedtopostponetheirdeletion(seecommentsin *mdunlink). * *(Regularbackendsdonottrackpendingoperationslocally,butforward *themtothecheckpointer.)
*/ typedef uint16 CycleCtr; /* can be any convenient integer size */
typedefstruct
{
FileTag tag; /* identifies handler and file */
CycleCtr cycle_ctr; /* sync_cycle_ctr of oldest request */ bool canceled; /* canceled is true if we canceled "recently" */
} PendingFsyncEntry;
typedefstruct
{
FileTag tag; /* identifies handler and file */
CycleCtr cycle_ctr; /* checkpoint_cycle_ctr when request was made */ bool canceled; /* true if request has been canceled */
} PendingUnlinkEntry;
static HTAB *pendingOps = NULL; static List *pendingUnlinks = NIL; static MemoryContext pendingOpsCxt; /* context for the above */
HASH_SEQ_STATUS hstat;
PendingFsyncEntry *entry; int absorb_counter;
/* Statistics on sync times */ int processed = 0;
instr_time sync_start,
sync_end,
sync_diff;
uint64 elapsed;
uint64 longest = 0;
uint64 total_elapsed = 0;
/* *Thisisonlycalledduringcheckpoints,andcheckpointsshouldonly *occurinprocessesthathavecreatedapendingOps.
*/ if (!pendingOps)
elog(ERROR, "cannot sync without a pendingOps table");
/* Advance counter so that new hashtable entries are distinguishable */
sync_cycle_ctr++;
/* Set flag to detect failure if we don't reach the end of the loop */
sync_in_progress = true;
/* Now scan the hashtable for fsync requests to process */
absorb_counter = FSYNCS_PER_ABSORB;
hash_seq_init(&hstat, pendingOps); while ((entry = (PendingFsyncEntry *) hash_seq_search(&hstat)) != NULL)
{ int failures;
/* *Iftheentryisnewthendon'tprocessitthistime;itisnew. *Note"continue"bypassesthehash-removecallatthebottomofthe *loop.
*/ if (entry->cycle_ctr == sync_cycle_ctr) continue;
/* Else assert we haven't missed it */
Assert((CycleCtr) (entry->cycle_ctr + 1) == sync_cycle_ctr);
/* *Itispossiblethattherelationhasbeendroppedor *truncatedsincethefsyncrequestwasentered.Therefore, *allowENOENT,butonlyifwedidn'tfailalreadyonthis *file.
*/ if (!FILE_POSSIBLY_DELETED(errno) || failures > 0)
ereport(data_sync_elevel(ERROR),
(errcode_for_file_access(),
errmsg("could not fsync file \"%s\": %m",
path))); else
ereport(DEBUG1,
(errcode_for_file_access(),
errmsg_internal("could not fsync file \"%s\" but retrying: %m",
path)));
/* *Absorbincomingrequestsandchecktoseeifacancel *arrivedforthisrelationfork.
*/
AbsorbSyncRequests();
absorb_counter = FSYNCS_PER_ABSORB; /* might as well... */
} /* end retry loop */
}
/* We are done with this entry, remove it */ if (hash_search(pendingOps, &entry->tag, HASH_REMOVE, NULL) == NULL)
elog(ERROR, "pendingOps corrupted");
} /* end loop over hashtable entries */
/* Return sync performance metrics for report at checkpoint end */
CheckpointStats.ckpt_sync_rels = processed;
CheckpointStats.ckpt_longest_sync = longest;
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
/* Flag successful completion of ProcessSyncRequests */
sync_in_progress = false;
}
MemoryContextSwitchTo(oldcxt);
} else
{ /* Normal case: enter a request to fsync this segment */
MemoryContext oldcxt = MemoryContextSwitchTo(pendingOpsCxt);
PendingFsyncEntry *entry; bool found;
Assert(type == SYNC_REQUEST);
entry = (PendingFsyncEntry *) hash_search(pendingOps,
ftag,
HASH_ENTER,
&found); /* if new entry, or was previously canceled, initialize it */ if (!found || entry->canceled)
{
entry->cycle_ctr = sync_cycle_ctr;
entry->canceled = false;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.