@@ -120,9 +120,10 @@ ptrackCleanFilesAndMap(void)
120
120
elog (LOG , "could not unmap ptrack_map" );
121
121
122
122
ptrack_map = NULL ;
123
- if (ptrack_file_exists (ptrack_mmap_path ))
124
- durable_unlink (ptrack_mmap_path , LOG );
125
123
}
124
+
125
+ if (ptrack_file_exists (ptrack_mmap_path ))
126
+ durable_unlink (ptrack_mmap_path , LOG );
126
127
}
127
128
128
129
/*
@@ -147,12 +148,8 @@ ptrackMapInit(void)
147
148
/* We do it at server start, so the map must be not allocated yet. */
148
149
Assert (ptrack_map == NULL );
149
150
150
- /* Delete ptrack_map and all related files, if ptrack was switched off. */
151
151
if (ptrack_map_size == 0 )
152
- {
153
- ptrackCleanFilesAndMap ();
154
152
return ;
155
- }
156
153
157
154
sprintf (ptrack_path , "%s/%s" , DataDir , PTRACK_PATH );
158
155
sprintf (ptrack_mmap_path , "%s/%s" , DataDir , PTRACK_MMAP_PATH );
@@ -443,7 +440,6 @@ ptrackCheckpoint(void)
443
440
}
444
441
445
442
/* Write if anythig left */
446
- /* TODO: check this i */
447
443
if ((i + 1 ) % PTRACK_BUF_SIZE != 0 )
448
444
{
449
445
int writesz = sizeof (pg_atomic_uint64 ) * j ;
@@ -476,8 +472,7 @@ ptrackCheckpoint(void)
476
472
errmsg ("ptrack checkpoint: could not close file \"%s\": %m" , ptrack_path_tmp )));
477
473
478
474
/* 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 );
481
476
482
477
/* Sanity check */
483
478
if (stat (ptrack_path , & stat_buf ) == 0 &&
@@ -496,13 +491,21 @@ assign_ptrack_map_size(int newval, void *extra)
496
491
MyProcPid , newval , ptrack_map_size );
497
492
498
493
/*
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.
503
499
*/
500
+ if (newval == -1 )
501
+ return ;
502
+
503
+ /* Delete ptrack_map and all related files, if ptrack was switched off. */
504
504
if (newval == 0 )
505
+ {
506
+ ptrackCleanFilesAndMap ();
505
507
return ;
508
+ }
506
509
507
510
if (newval != 0 && !XLogIsNeeded ())
508
511
ereport (ERROR ,
@@ -516,8 +519,8 @@ assign_ptrack_map_size(int newval, void *extra)
516
519
/* Always assign ptrack_map_size */
517
520
ptrack_map_size = newval * 1024 * 1024 ;
518
521
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 );
521
524
522
525
/* Init map on postmaster start */
523
526
if (!IsUnderPostmaster )
@@ -577,8 +580,6 @@ ptrack_mark_file(Oid dbOid, Oid tablespaceOid,
577
580
/*
578
581
* Mark all files in the given directory in ptrack_map.
579
582
* For use in functions that copy directories bypassing buffer manager.
580
- *
581
- * TODO: do we need to add process_symlinks?
582
583
*/
583
584
void
584
585
ptrack_walkdir (const char * path , Oid tablespaceOid , Oid dbOid )
0 commit comments