Re: Refactor backup related code (was: Is it correct to say, "invalid data in file \"%s\"", BACKUP_LABEL_FILE in do_pg_backup_stop?)
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: Michael Paquier <michael@paquier.xyz>, David Steele <david@pgmasters.net>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-09-23T00:32:24Z
Lists: pgsql-hackers
Attachments
- v12-0001-Refactor-backup-related-code.patch (application/x-patch) patch v12-0001
On Thu, Sep 22, 2022 at 3:17 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote: > > + MemSet(backup_state, 0, sizeof(BackupState)); > + MemSet(backup_state->name, '\0', sizeof(backup_state->name)); > > The latter MemSet() is not necessary because the former already > resets that with zero, is it? Yes, earlier, the name was a palloc'd string but now it is a fixed array. Removed. > + pfree(tablespace_map); > + tablespace_map = NULL; > + } > + > + tablespace_map = makeStringInfo(); > > tablespace_map doesn't need to be reset to NULL here. > > + pfree(tablespace_map); > + tablespace_map = NULL; > + pfree(backup_state); > + backup_state = NULL; > > It's harmless to set tablespace_map and backup_state to NULL after pfree(), > but it's also unnecessary at least here. Yes. But we can retain it for the sake of consistency with the other places and avoid dangling pointers, if at all any new code gets added in between it will be useful. > /* Free structures allocated in TopMemoryContext */ > - pfree(label_file->data); > - pfree(label_file); > <snip> > + pfree(backup_label->data); > + pfree(backup_label); > + backup_label = NULL; > > This source comment is a bit misleading, isn't it? Because the memory > for backup_label is allocated under the memory context other than > TopMemoryContext. Yes, we can just say /* Deallocate backup-related variables. */. The pg_backup_start() has the info about the variables being allocated in TopMemoryContext. > +#include "access/xlog.h" > +#include "access/xlog_internal.h" > +#include "access/xlogbackup.h" > +#include "utils/memutils.h" > > Seems "utils/memutils.h" doesn't need to be included. Yes, removed now. > + XLByteToSeg(state->startpoint, stopsegno, wal_segment_size); > + XLogFileName(stopxlogfile, state->starttli, stopsegno, wal_segment_size); > + appendStringInfo(result, "STOP WAL LOCATION: %X/%X (file %s)\n", > + LSN_FORMAT_ARGS(state->startpoint), stopxlogfile); > > state->stoppoint and state->stoptli should be used instead of > state->startpoint and state->starttli? Nice catch! Corrected. PSA v12 patch with the above review comments addressed. -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Commits
-
Fix some comments of do_pg_backup_start() and do_pg_backup_stop()
- 2e560b974ec7 16.0 landed
-
Remove dependency to StringInfo in xlogbackup.{c.h}
- e1e6f8f3dfe1 16.0 landed
-
Refactor creation of backup_label and backup history files
- 7d708093b740 16.0 landed
-
Move basebackup code to new directory src/backend/backup
- a8c012869763 16.0 cited
-
Remove exclusive backup mode
- 39969e2a1e4d 15.0 cited