@@ -120,9 +120,10 @@ ptrackCleanFilesAndMap(void)
120120elog (LOG ,"could not unmap ptrack_map" );
121121
122122ptrack_map = NULL ;
123- if (ptrack_file_exists (ptrack_mmap_path ))
124- durable_unlink (ptrack_mmap_path ,LOG );
125123}
124+
125+ if (ptrack_file_exists (ptrack_mmap_path ))
126+ durable_unlink (ptrack_mmap_path ,LOG );
126127}
127128
128129/*
@@ -147,12 +148,8 @@ ptrackMapInit(void)
147148/* We do it at server start, so the map must be not allocated yet. */
148149Assert (ptrack_map == NULL );
149150
150- /* Delete ptrack_map and all related files, if ptrack was switched off. */
151151if (ptrack_map_size == 0 )
152- {
153- ptrackCleanFilesAndMap ();
154152return ;
155- }
156153
157154sprintf (ptrack_path ,"%s/%s" ,DataDir ,PTRACK_PATH );
158155sprintf (ptrack_mmap_path ,"%s/%s" ,DataDir ,PTRACK_MMAP_PATH );
@@ -443,7 +440,6 @@ ptrackCheckpoint(void)
443440}
444441
445442/* Write if anythig left */
446- /* TODO: check this i */
447443if ((i + 1 ) %PTRACK_BUF_SIZE != 0 )
448444{
449445int writesz = sizeof (pg_atomic_uint64 )* j ;
@@ -476,8 +472,7 @@ ptrackCheckpoint(void)
476472errmsg ("ptrack checkpoint: could not close file \"%s\": %m" ,ptrack_path_tmp )));
477473
478474/* And finally replace old file with the new one */
479- /* TODO: shall we use ERROR instead of LOG here? */
480- durable_rename (ptrack_path_tmp ,ptrack_path ,LOG );
475+ durable_rename (ptrack_path_tmp ,ptrack_path ,ERROR );
481476
482477/* Sanity check */
483478if (stat (ptrack_path ,& stat_buf )== 0 &&
@@ -496,13 +491,21 @@ assign_ptrack_map_size(int newval, void *extra)
496491MyProcPid ,newval ,ptrack_map_size );
497492
498493/*
499- * TODO: for some reason assign_ptrack_map_size is called twice during
500- * postmaster start: first with bootValue, second with actual config
501- * value. However, we use 0 as a signal to cleanup all ptrack files, so we
502- * would drop map on each restart. That way, we return here for now.
494+ * XXX: for some reason assign_ptrack_map_size is called twice during the
495+ * postmaster boot! First, it is always called with bootValue, so we use
496+ * -1 as default value and no-op here. Next, it is called with the actual
497+ * value from config. That way, we use 0 as an option for user to turn
498+ * off ptrack and clean up all files.
503499 */
500+ if (newval == -1 )
501+ return ;
502+
503+ /* Delete ptrack_map and all related files, if ptrack was switched off. */
504504if (newval == 0 )
505+ {
506+ ptrackCleanFilesAndMap ();
505507return ;
508+ }
506509
507510if (newval != 0 && !XLogIsNeeded ())
508511ereport (ERROR ,
@@ -516,8 +519,8 @@ assign_ptrack_map_size(int newval, void *extra)
516519/* Always assign ptrack_map_size */
517520ptrack_map_size = newval * 1024 * 1024 ;
518521
519- elog (DEBUG1 ,"assign_ptrack_map_size:MyProc %d newval %d ptrack_map_size " UINT64_FORMAT ,
520- MyProcPid , newval , ptrack_map_size );
522+ elog (DEBUG1 ,"assign_ptrack_map_size:ptrack_map_size set to " UINT64_FORMAT ,
523+ ptrack_map_size );
521524
522525/* Init map on postmaster start */
523526if (!IsUnderPostmaster )
@@ -577,8 +580,6 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
577580/*
578581 * Mark all files in the given directory in ptrack_map.
579582 * For use in functions that copy directories bypassing buffer manager.
580- *
581- * TODO: do we need to add process_symlinks?
582583 */
583584void
584585ptrack_walkdir (const char * path ,Oid tablespaceOid ,Oid dbOid )