> > 0002 fixes the symmetry of error handling which is a change the callbacks > > that we could still do. This is also cleaner because when an extension > > signals > > failure, pgstat_write_statsfile() discards the temporary file immediately > > rather > > than writing bad data that would just be discarded on the next startup > > anyway. > > > > Note that I intentionally kept the core write path using deferred error > > checking with ferror(). Core only writes to a single FILE handle, so keeping > > it as one check at the end is sufficient and avoid adding if (!...) goto > > error > > in about 12 different places. > > Hmm. I also see a point in not having to_serialized_data() return an > error and keep processing all the entries: if we have multiple > auxiliary files across multiple stats kinds, we would be able to let > each stats kind notice that something is wrong and let their FILE > handles be cleaned up in the finish() callback with a ferror() check. > These errors run under the assumption that one error on a file handle > would lost likely lead to other similar errors for the rest of the > files written to. This means that we could miss opportunities to > clean up auxiliary files with 0002.
When an error is returned from a callback, the error block in 0002 only discards the core stats temp file and then moves on to call the finish callback for every extension that registered one ( and they better register one to perform cleanups ). So, the proposed will not cause any missed cleanups of auxiliary files. -- Sami
