Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d9d8d70

Browse files
committed
Return back an option to turn off ptrack and delete all files with ptrack.map_size = 0
1 parent aa00949 commit d9d8d70

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

engine.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ ptrackCleanFilesAndMap(void)
120120
elog(LOG, "could not unmap ptrack_map");
121121

122122
ptrack_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. */
148149
Assert(ptrack_map == NULL);
149150

150-
/* Delete ptrack_map and all related files, if ptrack was switched off. */
151151
if (ptrack_map_size == 0)
152-
{
153-
ptrackCleanFilesAndMap();
154152
return;
155-
}
156153

157154
sprintf(ptrack_path, "%s/%s", DataDir, PTRACK_PATH);
158155
sprintf(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 */
447443
if ((i + 1) % PTRACK_BUF_SIZE != 0)
448444
{
449445
int writesz = sizeof(pg_atomic_uint64) * j;
@@ -476,8 +472,7 @@ ptrackCheckpoint(void)
476472
errmsg("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 */
483478
if (stat(ptrack_path, &stat_buf) == 0 &&
@@ -496,13 +491,21 @@ assign_ptrack_map_size(int newval, void *extra)
496491
MyProcPid, 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. */
504504
if (newval == 0)
505+
{
506+
ptrackCleanFilesAndMap();
505507
return;
508+
}
506509

507510
if (newval != 0 && !XLogIsNeeded())
508511
ereport(ERROR,
@@ -516,8 +519,8 @@ assign_ptrack_map_size(int newval, void *extra)
516519
/* Always assign ptrack_map_size */
517520
ptrack_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 */
523526
if (!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
*/
583584
void
584585
ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)

ptrack.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ _PG_init(void)
8383

8484
/*
8585
* Define (or redefine) custom GUC variables.
86+
*
87+
* XXX: for some reason assign_ptrack_map_size is called twice during the
88+
* postmaster boot! First, it is always called with bootValue, so we use
89+
* -1 as default value and no-op here. Next, it is called with the actual
90+
* value from config.
8691
*/
8792
DefineCustomIntVariable("ptrack.map_size",
8893
"Sets the size of ptrack map in MB used for incremental backup (0 disabled).",
8994
NULL,
9095
&ptrack_map_size_tmp,
91-
0,
92-
0, INT_MAX,
96+
-1,
97+
-1, INT_MAX,
9398
PGC_POSTMASTER,
9499
0,
95100
NULL,
@@ -376,10 +381,12 @@ PG_FUNCTION_INFO_V1(ptrack_init_lsn);
376381
Datum
377382
ptrack_init_lsn(PG_FUNCTION_ARGS)
378383
{
379-
XLogRecPtr init_lsn = pg_atomic_read_u64(&ptrack_map->init_lsn);
380-
381384
if (ptrack_map != NULL)
385+
{
386+
XLogRecPtr init_lsn = pg_atomic_read_u64(&ptrack_map->init_lsn);
387+
382388
PG_RETURN_LSN(init_lsn);
389+
}
383390
else
384391
{
385392
elog(WARNING, "ptrack is disabled");
@@ -418,7 +425,6 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
418425
ctx->lsn = PG_GETARG_LSN(0);
419426
ctx->filelist = NIL;
420427

421-
/* get_call_result_type(fcinfo, NULL, &funcctx->tuple_desc); */
422428
/* Make tuple descriptor */
423429
tupdesc = CreateTemplateTupleDesc(2);
424430
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "path", TEXTOID, -1, 0);

0 commit comments

Comments
 (0)